tinybase 4.3.11 → 4.3.13
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-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/debug/persisters/persister-partykit-client.js +29 -19
- package/lib/debug/persisters/persister-partykit-server.js +160 -78
- 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/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 +19 -8
- package/lib/types/persisters/persister-partykit-server.d.ts +350 -12
- package/lib/types/tools.d.ts +4 -6
- 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 +19 -8
- package/lib/types/with-schemas/persisters/persister-partykit-server.d.ts +383 -12
- package/lib/types/with-schemas/tools.d.ts +4 -6
- package/lib/types/with-schemas/ui-react.d.ts +4 -4
- 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-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/package.json +15 -15
- package/readme.md +2 -2
|
@@ -18,7 +18,16 @@
|
|
|
18
18
|
* @since 4.3.0
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import {
|
|
22
|
+
Cell,
|
|
23
|
+
CellOrUndefined,
|
|
24
|
+
NoTablesSchema,
|
|
25
|
+
NoValuesSchema,
|
|
26
|
+
Value,
|
|
27
|
+
ValueOrUndefined,
|
|
28
|
+
} from '../store';
|
|
21
29
|
import {Connection, Party, Request, Server} from 'partykit/server';
|
|
30
|
+
import {Id} from '../common';
|
|
22
31
|
|
|
23
32
|
/**
|
|
24
33
|
* The TinyBasePartyKitServerConfig type describes the configuration of a
|
|
@@ -38,13 +47,13 @@ import {Connection, Party, Request, Server} from 'partykit/server';
|
|
|
38
47
|
* 'tinybase_' in case you are worried about colliding with other data stored
|
|
39
48
|
* in the room.
|
|
40
49
|
*
|
|
41
|
-
* ```js
|
|
42
|
-
*
|
|
43
|
-
* readonly config
|
|
50
|
+
* ```js
|
|
51
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
52
|
+
* readonly config = {
|
|
44
53
|
* storePath: '/my_tinybase',
|
|
45
54
|
* storagePrefix: 'tinybase_',
|
|
46
55
|
* };
|
|
47
|
-
* }
|
|
56
|
+
* }
|
|
48
57
|
* ```
|
|
49
58
|
* @category Configuration
|
|
50
59
|
* @since v4.3.9
|
|
@@ -56,6 +65,14 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
56
65
|
* on the client. Both default to '/store'.
|
|
57
66
|
*/
|
|
58
67
|
storePath?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The prefix at the beginning of the web socket messages between the client
|
|
70
|
+
* and the server when synchronizing the Store. Use this to make sure they do
|
|
71
|
+
* not collide with any other message syntax that your room is using. This
|
|
72
|
+
* must match the messagePrefix property of the PartyKitPersisterConfig object
|
|
73
|
+
* used on the client. Both default to an empty string.
|
|
74
|
+
*/
|
|
75
|
+
messagePrefix?: string;
|
|
59
76
|
/**
|
|
60
77
|
* The prefix used before all the keys in the server's durable storage. Use
|
|
61
78
|
* this in case you are worried about the Store data colliding with other data
|
|
@@ -98,7 +115,7 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
98
115
|
* ```js
|
|
99
116
|
* // This is your PartyKit server entry point.
|
|
100
117
|
*
|
|
101
|
-
*
|
|
118
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
102
119
|
* constructor(party) {
|
|
103
120
|
* super(party);
|
|
104
121
|
* // custom constructor code
|
|
@@ -109,8 +126,8 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
109
126
|
* console.log('Server started');
|
|
110
127
|
* }
|
|
111
128
|
*
|
|
112
|
-
* async onMessage(message,
|
|
113
|
-
* await super.onMessage(message,
|
|
129
|
+
* async onMessage(message, connection) {
|
|
130
|
+
* await super.onMessage(message, connection);
|
|
114
131
|
* // custom onMessage code
|
|
115
132
|
* }
|
|
116
133
|
*
|
|
@@ -124,6 +141,8 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
124
141
|
* See the [PartyKit server API
|
|
125
142
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
126
143
|
* more details.
|
|
144
|
+
* @category Creation
|
|
145
|
+
* @since v4.3.0
|
|
127
146
|
*/
|
|
128
147
|
export class TinyBasePartyKitServer implements Server {
|
|
129
148
|
constructor(party: Party);
|
|
@@ -132,6 +151,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
132
151
|
* object of the TinyBasePartyKitServerConfig type.
|
|
133
152
|
*
|
|
134
153
|
* See the documentation for that type for more details.
|
|
154
|
+
* @category Configuration
|
|
155
|
+
* @since v4.3.9
|
|
135
156
|
*/
|
|
136
157
|
readonly config: TinyBasePartyKitServerConfig;
|
|
137
158
|
/**
|
|
@@ -143,7 +164,7 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
143
164
|
* synchronization stays supported:
|
|
144
165
|
*
|
|
145
166
|
* ```js
|
|
146
|
-
*
|
|
167
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
147
168
|
* async onRequest(request) {
|
|
148
169
|
* // custom onRequest code, else:
|
|
149
170
|
* return await super.onRequest(request);
|
|
@@ -154,6 +175,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
154
175
|
* See the [PartyKit server API
|
|
155
176
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
156
177
|
* more details.
|
|
178
|
+
* @category Connection
|
|
179
|
+
* @since v4.3.0
|
|
157
180
|
*/
|
|
158
181
|
onRequest(request: Request): Promise<Response>;
|
|
159
182
|
/**
|
|
@@ -165,9 +188,9 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
165
188
|
* synchronization stays supported:
|
|
166
189
|
*
|
|
167
190
|
* ```js
|
|
168
|
-
*
|
|
169
|
-
* async onMessage(message,
|
|
170
|
-
* await super.onMessage(message,
|
|
191
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
192
|
+
* async onMessage(message, connection) {
|
|
193
|
+
* await super.onMessage(message, connection);
|
|
171
194
|
* // custom onMessage code
|
|
172
195
|
* }
|
|
173
196
|
* }
|
|
@@ -176,6 +199,354 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
176
199
|
* See the [PartyKit server API
|
|
177
200
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
178
201
|
* more details.
|
|
202
|
+
* @category Connection
|
|
203
|
+
* @since v4.3.0
|
|
204
|
+
*/
|
|
205
|
+
onMessage(message: string, connection: Connection): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* The canSetTable method lets you allow or disallow any changes to a Table
|
|
208
|
+
* stored on the server, as sent from a client.
|
|
209
|
+
*
|
|
210
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
211
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
212
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
213
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
214
|
+
* the server considers valid or safe.
|
|
215
|
+
*
|
|
216
|
+
* This method is passed the Table Id that the client is trying to change. The
|
|
217
|
+
* `initialSave` parameter distinguishes between the first bulk save of the
|
|
218
|
+
* Store to the PartyKit room over HTTP (`true`), and subsequent incremental
|
|
219
|
+
* updates over a web sockets (`false`).
|
|
220
|
+
*
|
|
221
|
+
* The `requestOrConnection` parameter will either be the HTTP(S) request or
|
|
222
|
+
* the web socket connection, in those two cases respectively. You can, for
|
|
223
|
+
* instance, use this to distinguish between different users.
|
|
224
|
+
*
|
|
225
|
+
* Since v4.3.13, the final parameter is the Cell previously stored on the
|
|
226
|
+
* server, if any. Use this to distinguish between the addition of a new Cell
|
|
227
|
+
* (in which case it will be undefined) and the updating of an existing one.
|
|
228
|
+
*
|
|
229
|
+
* Return `false` from this method to disallow changes to this Table on the
|
|
230
|
+
* server, or `true` to allow them (subject to subsequent canSetRow method,
|
|
231
|
+
* canDelRow method, canSetCell method, and canSetCell method checks). The
|
|
232
|
+
* default implementation returns `true` to allow all changes.
|
|
233
|
+
* @example
|
|
234
|
+
* The following implementation will strip out any attempts by the client to
|
|
235
|
+
* update any 'user' tabular data after the initial save:
|
|
236
|
+
*
|
|
237
|
+
* ```js
|
|
238
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
239
|
+
* canSetTable(tableId, initialSave) {
|
|
240
|
+
* return initialSave || tableId != 'user';
|
|
241
|
+
* }
|
|
242
|
+
* }
|
|
243
|
+
* ```
|
|
244
|
+
* @category Sanitization
|
|
245
|
+
* @since v4.3.12
|
|
246
|
+
*/
|
|
247
|
+
canSetTable(
|
|
248
|
+
tableId: Id,
|
|
249
|
+
initialSave: boolean,
|
|
250
|
+
requestOrConnection: Request | Connection,
|
|
251
|
+
): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* The canDelTable method lets you allow or disallow deletions of a Table
|
|
254
|
+
* stored on the server, as sent from a client.
|
|
255
|
+
*
|
|
256
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
257
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
258
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
259
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
260
|
+
* the server considers valid or safe.
|
|
261
|
+
*
|
|
262
|
+
* This method is passed the Table Id that the client is trying to delete. The
|
|
263
|
+
* `connection` parameter will be the web socket connection of that client.
|
|
264
|
+
* You can, for instance, use this to distinguish between different users.
|
|
265
|
+
*
|
|
266
|
+
* Return `false` from this method to disallow this Table from being deleted
|
|
267
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
268
|
+
* `true` to allow deletion.
|
|
269
|
+
* @example
|
|
270
|
+
* The following implementation will strip out any attempts by the client to
|
|
271
|
+
* delete the 'user' Table:
|
|
272
|
+
*
|
|
273
|
+
* ```js
|
|
274
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
275
|
+
* canDelTable(tableId) {
|
|
276
|
+
* return tableId != 'user';
|
|
277
|
+
* }
|
|
278
|
+
* }
|
|
279
|
+
* ```
|
|
280
|
+
* @category Sanitization
|
|
281
|
+
* @since v4.3.12
|
|
282
|
+
*/
|
|
283
|
+
canDelTable(tableId: Id, connection: Connection): boolean;
|
|
284
|
+
/**
|
|
285
|
+
* The canSetRow method lets you allow or disallow any changes to a Row stored
|
|
286
|
+
* 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 and Row Id that the client is trying to
|
|
295
|
+
* change. The `initialSave` parameter distinguishes between the first bulk
|
|
296
|
+
* save of the Store to the PartyKit room over HTTP (`true`), and subsequent
|
|
297
|
+
* incremental updates over a web sockets (`false`).
|
|
298
|
+
*
|
|
299
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
300
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
301
|
+
* can, for instance, use this to distinguish between different users.
|
|
302
|
+
*
|
|
303
|
+
* Return `false` from this method to disallow changes to this Row on the
|
|
304
|
+
* server, or `true` to allow them (subject to subsequent canSetCell method
|
|
305
|
+
* and canSetCell method checks). The default implementation returns `true` to
|
|
306
|
+
* allow all changes.
|
|
307
|
+
* @example
|
|
308
|
+
* The following implementation will strip out any attempts by the client to
|
|
309
|
+
* update the 'me' Row of the 'user' Table after the initial save:
|
|
310
|
+
*
|
|
311
|
+
* ```js
|
|
312
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
313
|
+
* canSetRow(tableId, rowId, initialSave) {
|
|
314
|
+
* return initialSave || tableId != 'user' || rowId != 'me';
|
|
315
|
+
* }
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
* @category Sanitization
|
|
319
|
+
* @since v4.3.12
|
|
320
|
+
*/
|
|
321
|
+
canSetRow(
|
|
322
|
+
tableId: Id,
|
|
323
|
+
rowId: Id,
|
|
324
|
+
initialSave: boolean,
|
|
325
|
+
requestOrConnection: Request | Connection,
|
|
326
|
+
): boolean;
|
|
327
|
+
/**
|
|
328
|
+
* The canDelRow method lets you allow or disallow deletions of a Row stored
|
|
329
|
+
* on the server, as sent from a client.
|
|
330
|
+
*
|
|
331
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
332
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
333
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
334
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
335
|
+
* the server considers valid or safe.
|
|
336
|
+
*
|
|
337
|
+
* This method is passed the Table Id and Row Id that the client is trying to
|
|
338
|
+
* delete. The `connection` parameter will be the web socket connection of
|
|
339
|
+
* that client. You can, for instance, use this to distinguish between
|
|
340
|
+
* different users.
|
|
341
|
+
*
|
|
342
|
+
* Return `false` from this method to disallow this Row from being deleted
|
|
343
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
344
|
+
* `true` to allow deletion.
|
|
345
|
+
* @example
|
|
346
|
+
* The following implementation will strip out any attempts by the client to
|
|
347
|
+
* delete the 'me' Row of the 'user' Table:
|
|
348
|
+
*
|
|
349
|
+
* ```js
|
|
350
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
351
|
+
* canDelRow(tableId, rowId) {
|
|
352
|
+
* return tableId != 'user' || rowId != 'me';
|
|
353
|
+
* }
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
356
|
+
* @category Sanitization
|
|
357
|
+
* @since v4.3.12
|
|
358
|
+
*/
|
|
359
|
+
canDelRow(tableId: Id, rowId: Id, connection: Connection): boolean;
|
|
360
|
+
/**
|
|
361
|
+
* The canSetCell method lets you allow or disallow any changes to a Cell
|
|
362
|
+
* stored on the server, as sent from a client.
|
|
363
|
+
*
|
|
364
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
365
|
+
*
|
|
366
|
+
* ```ts override
|
|
367
|
+
* canSetCell(
|
|
368
|
+
* tableId: Id,
|
|
369
|
+
* rowId: Id,
|
|
370
|
+
* cellId: Id,
|
|
371
|
+
* cell: Cell,
|
|
372
|
+
* initialSave: boolean,
|
|
373
|
+
* requestOrConnection: Request | Connection,
|
|
374
|
+
* oldCell: CellOrUndefined,
|
|
375
|
+
* ): boolean;
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
379
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
380
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
381
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
382
|
+
* the server considers valid or safe.
|
|
383
|
+
*
|
|
384
|
+
* This method is passed the Table Id, Row Id, and Cell Id that the client is
|
|
385
|
+
* trying to change - as well as the Cell value itself. The `initialSave`
|
|
386
|
+
* parameter distinguishes between the first bulk save of the Store to the
|
|
387
|
+
* PartyKit room over HTTP (`true`), and subsequent incremental updates over a
|
|
388
|
+
* web sockets (`false`).
|
|
389
|
+
*
|
|
390
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
391
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
392
|
+
* can, for instance, use this to distinguish between different users.
|
|
393
|
+
*
|
|
394
|
+
* Return `false` from this method to disallow changes to this Cell on the
|
|
395
|
+
* server, or `true` to allow them. The default implementation returns `true`
|
|
396
|
+
* to allow all changes.
|
|
397
|
+
* @example
|
|
398
|
+
* The following implementation will strip out any attempts by the client to
|
|
399
|
+
* update the 'name' Cell of the 'me' Row of the 'user' Table after the
|
|
400
|
+
* initial save:
|
|
401
|
+
*
|
|
402
|
+
* ```js
|
|
403
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
404
|
+
* canSetCell(tableId, rowId, cellId, cell, initialSave) {
|
|
405
|
+
* return (
|
|
406
|
+
* initialSave || tableId != 'user' || rowId != 'me' || cellId != 'name'
|
|
407
|
+
* );
|
|
408
|
+
* }
|
|
409
|
+
* }
|
|
410
|
+
* ```
|
|
411
|
+
* @category Sanitization
|
|
412
|
+
* @since v4.3.12
|
|
413
|
+
*/
|
|
414
|
+
canSetCell(
|
|
415
|
+
tableId: Id,
|
|
416
|
+
rowId: Id,
|
|
417
|
+
cellId: Id,
|
|
418
|
+
cell: Cell<NoTablesSchema, Id, Id>,
|
|
419
|
+
initialSave: boolean,
|
|
420
|
+
requestOrConnection: Request | Connection,
|
|
421
|
+
oldCell: CellOrUndefined<NoTablesSchema, Id, Id>,
|
|
422
|
+
): boolean;
|
|
423
|
+
/**
|
|
424
|
+
* The canDelCell method lets you allow or disallow deletions of a Cell stored
|
|
425
|
+
* on the server, as sent from a client.
|
|
426
|
+
*
|
|
427
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
428
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
429
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
430
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
431
|
+
* the server considers valid or safe.
|
|
432
|
+
*
|
|
433
|
+
* This method is passed the Table Id, Row Id, and Cell Id that the client is
|
|
434
|
+
* trying to delete. The `connection` parameter will be the web socket
|
|
435
|
+
* connection of that client. You can, for instance, use this to distinguish
|
|
436
|
+
* between different users.
|
|
437
|
+
*
|
|
438
|
+
* Return `false` from this method to disallow this Cell from being deleted on
|
|
439
|
+
* the server, or `true` to allow it. The default implementation returns
|
|
440
|
+
* `true` to allow deletion.
|
|
441
|
+
* @example
|
|
442
|
+
* The following implementation will strip out any attempts by the client to
|
|
443
|
+
* delete the 'name' Cell of the 'me' Row of the 'user' Table:
|
|
444
|
+
*
|
|
445
|
+
* ```js
|
|
446
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
447
|
+
* canDelCell(tableId, rowId, cellId) {
|
|
448
|
+
* return tableId != 'user' || rowId != 'me' || cellId != 'name';
|
|
449
|
+
* }
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
* @category Sanitization
|
|
453
|
+
* @since v4.3.12
|
|
454
|
+
*/
|
|
455
|
+
canDelCell(
|
|
456
|
+
tableId: Id,
|
|
457
|
+
rowId: Id,
|
|
458
|
+
cellId: Id,
|
|
459
|
+
connection: Connection,
|
|
460
|
+
): boolean;
|
|
461
|
+
/**
|
|
462
|
+
* The canSetValue method lets you allow or disallow any changes to a Value
|
|
463
|
+
* stored on the server, as sent from a client.
|
|
464
|
+
*
|
|
465
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
466
|
+
*
|
|
467
|
+
* ```ts override
|
|
468
|
+
* canSetValue(
|
|
469
|
+
* valueId: Id,
|
|
470
|
+
* value: Value,
|
|
471
|
+
* initialSave: boolean,
|
|
472
|
+
* requestOrConnection: Request | Connection,
|
|
473
|
+
* oldValue: ValueOrUndefined,
|
|
474
|
+
* ): boolean;
|
|
475
|
+
* ```
|
|
476
|
+
*
|
|
477
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
478
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
479
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
480
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
481
|
+
* the server considers valid or safe.
|
|
482
|
+
*
|
|
483
|
+
* This method is passed the Value Id that the client is trying to change - as
|
|
484
|
+
* well as the Value itself. The `initialSave` parameter distinguishes between
|
|
485
|
+
* the first bulk save of the Store to the PartyKit room over HTTP (`true`),
|
|
486
|
+
* and subsequent incremental updates over a web sockets (`false`).
|
|
487
|
+
*
|
|
488
|
+
* The `requestOrConnection` parameter will either be the HTTP(S) request or
|
|
489
|
+
* the web socket connection, in those two cases respectively. You can, for
|
|
490
|
+
* instance, use this to distinguish between different users.
|
|
491
|
+
*
|
|
492
|
+
* Since v4.3.13, the final parameter is the Value previously stored on the
|
|
493
|
+
* server, if any. Use this to distinguish between the addition of a new Value
|
|
494
|
+
* (in which case it will be undefined) and the updating of an existing one.
|
|
495
|
+
*
|
|
496
|
+
* Return `false` from this method to disallow changes to this Value on the
|
|
497
|
+
* server, or `true` to allow them. The default implementation returns `true`
|
|
498
|
+
* to allow all changes.
|
|
499
|
+
* @example
|
|
500
|
+
* The following implementation will strip out any attempts by the client to
|
|
501
|
+
* update the 'userId' Value after the initial save:
|
|
502
|
+
*
|
|
503
|
+
* ```js
|
|
504
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
505
|
+
* canSetValue(valueId, value, initialSave) {
|
|
506
|
+
* return initialSave || userId != 'userId';
|
|
507
|
+
* }
|
|
508
|
+
* }
|
|
509
|
+
* ```
|
|
510
|
+
* @category Sanitization
|
|
511
|
+
* @since v4.3.12
|
|
512
|
+
*/
|
|
513
|
+
canSetValue(
|
|
514
|
+
valueId: Id,
|
|
515
|
+
value: Value<NoValuesSchema, Id>,
|
|
516
|
+
initialSave: boolean,
|
|
517
|
+
requestOrConnection: Request | Connection,
|
|
518
|
+
oldValue: ValueOrUndefined<NoValuesSchema, Id>,
|
|
519
|
+
): boolean;
|
|
520
|
+
/**
|
|
521
|
+
* The canDelValue method lets you allow or disallow deletions of a Value
|
|
522
|
+
* stored on the server, as sent from a client.
|
|
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 delete. The
|
|
531
|
+
* `connection` parameter will be the web socket connection of that client.
|
|
532
|
+
* You can, for instance, use this to distinguish between different users.
|
|
533
|
+
*
|
|
534
|
+
* Return `false` from this method to disallow this Value from being deleted
|
|
535
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
536
|
+
* `true` to allow deletion.
|
|
537
|
+
* @example
|
|
538
|
+
* The following implementation will strip out any attempts by the client to
|
|
539
|
+
* delete the 'userId' Value:
|
|
540
|
+
*
|
|
541
|
+
* ```js
|
|
542
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
543
|
+
* canDelValue(valueId) {
|
|
544
|
+
* return valueId != 'userId';
|
|
545
|
+
* }
|
|
546
|
+
* }
|
|
547
|
+
* ```
|
|
548
|
+
* @category Sanitization
|
|
549
|
+
* @since v4.3.12
|
|
179
550
|
*/
|
|
180
|
-
|
|
551
|
+
canDelValue(valueId: Id, connection: Connection): boolean;
|
|
181
552
|
}
|
|
@@ -412,9 +412,8 @@ export interface Tools<in out Schemas extends OptionalSchemas> {
|
|
|
412
412
|
* },
|
|
413
413
|
* });
|
|
414
414
|
* const tools = createTools(store);
|
|
415
|
-
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
416
|
-
* store
|
|
417
|
-
* ).getPrettyStoreApi('shop');
|
|
415
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
416
|
+
* await createTools(store).getPrettyStoreApi('shop');
|
|
418
417
|
*
|
|
419
418
|
* const dTsLines = dTs.split('\n');
|
|
420
419
|
* console.log(dTsLines[17]);
|
|
@@ -433,9 +432,8 @@ export interface Tools<in out Schemas extends OptionalSchemas> {
|
|
|
433
432
|
* felix: {price: 4},
|
|
434
433
|
* });
|
|
435
434
|
* const tools = createTools(store);
|
|
436
|
-
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
437
|
-
* store
|
|
438
|
-
* ).getPrettyStoreApi('shop');
|
|
435
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
436
|
+
* await createTools(store).getPrettyStoreApi('shop');
|
|
439
437
|
*
|
|
440
438
|
* const dTsLines = dTs.split('\n');
|
|
441
439
|
* console.log(dTsLines[17]);
|
|
@@ -4393,8 +4393,8 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
4393
4393
|
* </Provider>
|
|
4394
4394
|
* );
|
|
4395
4395
|
* const Pane = () => {
|
|
4396
|
-
* useWillFinishTransactionListener(
|
|
4397
|
-
*
|
|
4396
|
+
* useWillFinishTransactionListener(() =>
|
|
4397
|
+
* console.log('Will finish transaction'),
|
|
4398
4398
|
* );
|
|
4399
4399
|
* return <span>App</span>;
|
|
4400
4400
|
* };
|
|
@@ -4462,8 +4462,8 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
4462
4462
|
* </Provider>
|
|
4463
4463
|
* );
|
|
4464
4464
|
* const Pane = () => {
|
|
4465
|
-
* useDidFinishTransactionListener(
|
|
4466
|
-
*
|
|
4465
|
+
* useDidFinishTransactionListener(() =>
|
|
4466
|
+
* console.log('Did finish transaction'),
|
|
4467
4467
|
* );
|
|
4468
4468
|
* return <span>App</span>;
|
|
4469
4469
|
* };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t,e;t=this,e=function(t){"use strict";const e=t=>typeof t,a=
|
|
1
|
+
var t,e;t=this,e=function(t){"use strict";const e=t=>typeof t,a="",s=e(a),o=(t,e)=>t instanceof e,n=t=>null==t,r=(t,e,a)=>n(t)?a?.():e(t),i=t=>e(t)==s,c=t=>t.length,d=Object,y=d.keys,u=d.freeze,f=t=>(t=>o(t,d)&&t.constructor==d)(t)&&0==(t=>c(y(t)))(t),h=t=>JSON.stringify(t,((t,e)=>o(e,Map)?d.fromEntries([...e]):e)),l=JSON.parse,p="/store",v=t=>new Map(t),w=(t,e)=>t?.get(e),g=(t,e,a)=>{return n(a)?(s=t,o=e,s?.delete(o),t):t?.set(e,a);var s,o},m=(t,e,a)=>{var s,o;return s=t,o=e,s?.has(o)||g(t,e,a()),w(t,e)},P=v(),S=v(),A="message";t.createPartyKitPersister=(t,e,s,o)=>{const{host:d,room:y}=e.partySocketOptions,{storeProtocol:v="https",storePath:L=p,messagePrefix:C=a}={...i(s)?{storeProtocol:s}:s},T=v+"://"+d+"/parties/"+(e.name??"main")+"/"+y+L,b=async t=>await(await fetch(T,{...t?{method:"PUT",body:h(t)}:{},mode:"cors",cache:"no-store"})).json();return((t,e,a,s,o,i,c=[])=>{let d,y,h,l=0,p=0;m(P,c,(()=>0)),m(S,c,(()=>[]));const v=async t=>(2!=l&&(l=1,await A.schedule((async()=>{await t(),l=0}))),A),A={load:async(a,s)=>await v((async()=>{try{t.setContent(await e())}catch{t.setContent([a,s])}})),startAutoLoad:async(a={},o={})=>(A.stopAutoLoad(),await A.load(a,o),p=1,h=s((async(a,s)=>{if(s){const e=s();await v((async()=>t.setTransactionChanges(e)))}else await v((async()=>{try{t.setContent(a?.()??await e())}catch(t){i?.(t)}}))})),A),stopAutoLoad:()=>(p&&(o(h),h=void 0,p=0),A),save:async e=>(1!=l&&(l=2,await A.schedule((async()=>{try{await a(t.getContent,e)}catch(t){i?.(t)}l=0}))),A),startAutoSave:async()=>(await A.stopAutoSave().save(),d=t.addDidFinishTransactionListener(((t,e)=>{const[a,s]=e();f(a)&&f(s)||A.save((()=>[a,s]))})),A),stopAutoSave:()=>(r(d,t.delListener),A),schedule:async(...t)=>(((t,...e)=>{t.push(...e)})(w(S,c),...t),await(async()=>{if(!w(P,c)){for(g(P,c,1);!n((t=w(S,c),y=t.shift()));)try{await y()}catch(t){i?.(t)}g(P,c,0)}var t})(),A),getStore:()=>t,destroy:()=>A.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return u(A)})(t,(async()=>await b()),(async(t,a)=>{var s,o;a?e.send((s=C,o=a(),s+"s"+(i(o)?o:h(o)))):await b(t())}),(t=>{const a=e=>r(((t,e,a)=>{const s=c(t);return((t,e)=>t.startsWith(e))(e,t)?[e[s],l((o=e,n=s+1,o.slice(n,void 0)))]:void 0;var o,n})(C,e.data),(([e,a])=>{"s"==e&&t(void 0,(()=>a))}));return e.addEventListener(A,a),a}),(t=>{e.removeEventListener(A,t)}),o)}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterPartyKitClient={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t,e;t=this,e=function(t){"use strict";const e=t=>typeof t,s=e(
|
|
1
|
+
var t,e;t=this,e=function(t){"use strict";const e=t=>typeof t,a="",s=e(a),n="t",i=(t,e)=>t.startsWith(e),r=Promise,o=t=>null==t,c=(t,e,a)=>o(t)?a?.():e(t),l=(t,e,a)=>t.slice(e,a),f=t=>t.length,u=async t=>r.all(t),h=(t,e)=>t.map(e),y=(t,...e)=>t.push(...e),w=Object,g=(t=[])=>w.fromEntries(t),p=(t,e)=>h(w.entries(t),(([t,a])=>e(a,t))),d=(t,e,a)=>(((t,e)=>!o(((t,e)=>c(t,(t=>t[e])))(t,e)))(t,e)||(t[e]=a()),t[e]),S=t=>JSON.stringify(t,((t,e)=>e instanceof Map?w.fromEntries([...e]):e)),P=JSON.parse,b=(t,a,n)=>t+a+(e(n)==s?n:S(n)),m=(t,e,a)=>{const s=f(t);return i(e,t)?[e[s],(a?P:String)(l(e,s+1))]:void 0},T=(t,e)=>((t,e)=>t?.forEach(e))(t,((t,a)=>e(a,t))),x="hasStore",D=g(h(["Origin","Methods","Headers"],(t=>["Access-Control-Allow-"+t,"*"]))),v=async t=>await t.party.storage.get((t.config.storagePrefix??a)+x),R=async(t,e,s,r)=>{const c=t.party.storage,l=t.config.storagePrefix??a,h={[l+x]:1},w=[],g=[];await u(p(e[0],(async(e,a)=>o(e)?!s&&t.canDelTable(a,r)&&((t,...e)=>t.unshift(...e))(g,C(l,n,a)):t.canSetTable(a,s,r)&&await u(p(e,(async(e,i)=>o(e)?!s&&t.canDelRow(a,i,r)&&y(g,C(l,n,a,i)):t.canSetRow(a,i,s,r)&&await u(p(e,(async(e,f)=>{const u=[a,i,f],g=C(l,n,...u);o(e)?!s&&t.canDelCell(...u,r)&&y(w,g):t.canSetCell(...u,e,s,r,await c.get(g))&&(h[g]=e)}))))))))),await u(p(e[1],(async(e,a)=>{const n=l+"v"+a;o(e)?!s&&t.canDelValue(a,r)&&y(w,n):t.canSetValue(a,e,s,r,await c.get(n))&&(h[n]=e)}))),0!=f(g)&&T(await c.list(),(t=>g.every((e=>!i(t,e)||y(w,t)&&0)))),await c.delete(w),await c.put(h)},C=(t,e,...a)=>b(t,e,l(S(a),1,-1)),O=async(t,e,a=null)=>new Response(a,{status:e,headers:t.config.responseHeaders??D});t.TinyBasePartyKitServer=class{constructor(t){this.party=t,this.config={}}async onRequest(t){const e=this.config.storePath??"/store";if(new URL(t.url).pathname.endsWith(e)){const e=await v(this),s=await t.text();return"PUT"==t.method?e?O(this,205):(await R(this,P(s),!0,t),O(this,201)):O(this,200,e?S(await(async t=>{const e={},s={},i=t.config.storagePrefix??a;return T(await t.party.storage.list(),((t,a)=>c(m(i,t),(([t,i])=>{if(t==n){const[t,s,n]=P("["+i+"]");d(d(e,t,g),s,g)[n]=a}else"v"==t&&(s[i]=a)})))),[e,s]})(this)):a)}return O(this,404)}async onMessage(t,e){const s=this.config.messagePrefix??a;await c(m(s,t,1),(async([t,a])=>{"s"==t&&await v(this)&&(await R(this,a,!1,e),this.party.broadcast(b(s,"s",a)))}))}canSetTable(t,e,a){return!0}canDelTable(t,e){return!0}canSetRow(t,e,a,s){return!0}canDelRow(t,e,a){return!0}canSetCell(t,e,a,s,n,i,r){return!0}canDelCell(t,e,a,s){return!0}canSetValue(t,e,a,s,n){return!0}canDelValue(t,e){return!0}}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterPartyKitServer={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n=
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",o=t(n),r=(e,t)=>e instanceof t,l=e=>null==e,i=(e,t,n)=>l(e)?null==n?void 0:n():t(e),s=e=>t(e)==o,u=e=>e.length,a=Object,d=a.keys,c=a.freeze,v=e=>(e=>r(e,a)&&e.constructor==a)(e)&&0==(e=>u(d(e)))(e),y=e=>JSON.stringify(e,((e,t)=>r(t,Map)?a.fromEntries([...t]):t)),f=JSON.parse,p="/store",h=e=>new Map(e),m=(e,t)=>null==e?void 0:e.get(t),P=(e,t,n)=>{return l(n)?(r=t,null==(o=e)||o.delete(r),e):null==e?void 0:e.set(t,n);var o,r},b=(e,t,n)=>{var o,r,l;return r=t,null!=(l=null==(o=e)?void 0:o.has(r))&&l||P(e,t,n()),m(e,t)};var g=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{s(n.next(e))}catch(e){r(e)}},i=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);s((n=n.apply(e,t)).next())}));const O=h(),S=h();var j=Object.defineProperty,w=Object.defineProperties,x=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,T=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t)=>{for(var n in t||(t={}))L.call(t,n)&&T(e,n,t[n]);if(A)for(var n of A(t))C.call(t,n)&&T(e,n,t[n]);return e},k=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{s(n.next(e))}catch(e){r(e)}},i=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);s((n=n.apply(e,t)).next())}));const D="message";e.createPartyKitPersister=(e,t,o,r)=>{var a;const{host:d,room:h}=t.partySocketOptions,{storeProtocol:j="https",storePath:A=p,messagePrefix:L=n}=E({},s(o)?{storeProtocol:o}:o),C=j+"://"+d+"/parties/"+(null!=(a=t.name)?a:"main")+"/"+h+A,T=e=>k(void 0,null,(function*(){return yield(yield fetch(C,(t=E({},e?{method:"PUT",body:y(e)}:{}),n={mode:"cors",cache:"no-store"},w(t,x(n))))).json();var t,n}));return((e,t,n,o,r,s,u=[])=>{let a,d,y,f=0,p=0;b(O,u,(()=>0)),b(S,u,(()=>[]));const h=e=>g(void 0,null,(function*(){return 2!=f&&(f=1,yield j.schedule((()=>g(void 0,null,(function*(){yield e(),f=0}))))),j})),j={load:(n,o)=>g(void 0,null,(function*(){return yield h((()=>g(void 0,null,(function*(){try{e.setContent(yield t())}catch(t){e.setContent([n,o])}}))))})),startAutoLoad:(...n)=>g(void 0,[...n],(function*(n={},r={}){return j.stopAutoLoad(),yield j.load(n,r),p=1,y=o(((n,o)=>g(void 0,null,(function*(){if(o){const t=o();yield h((()=>g(void 0,null,(function*(){return e.setTransactionChanges(t)}))))}else yield h((()=>g(void 0,null,(function*(){var o;try{e.setContent(null!=(o=null==n?void 0:n())?o:yield t())}catch(e){null==s||s(e)}}))))})))),j})),stopAutoLoad:()=>(p&&(r(y),y=void 0,p=0),j),save:t=>g(void 0,null,(function*(){return 1!=f&&(f=2,yield j.schedule((()=>g(void 0,null,(function*(){try{yield n(e.getContent,t)}catch(e){null==s||s(e)}f=0}))))),j})),startAutoSave:()=>g(void 0,null,(function*(){return yield j.stopAutoSave().save(),a=e.addDidFinishTransactionListener(((e,t)=>{const[n,o]=t();v(n)&&v(o)||j.save((()=>[n,o]))})),j})),stopAutoSave:()=>(i(a,e.delListener),j),schedule:(...e)=>g(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(m(S,u),...e),yield g(void 0,null,(function*(){if(!m(O,u)){for(P(O,u,1);!l((e=m(S,u),d=e.shift()));)try{yield d()}catch(e){null==s||s(e)}P(O,u,0)}var e})),j})),getStore:()=>e,destroy:()=>j.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return c(j)})(e,(()=>k(void 0,null,(function*(){return yield T()}))),((e,n)=>k(void 0,null,(function*(){var o,r;n?t.send((o=L,r=n(),o+"s"+(s(r)?r:y(r)))):yield T(e())}))),(e=>{const n=t=>i(((e,t,n)=>{const o=u(e);return((e,t)=>e.startsWith(t))(t,e)?[t[o],f((r=t,l=o+1,r.slice(l,void 0)))]:void 0;var r,l})(L,t.data),(([t,n])=>{"s"==t&&e(void 0,(()=>n))}));return t.addEventListener(D,n),n}),(e=>{t.removeEventListener(D,e)}),r)}},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterPartyKitClient={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",r=t(n),l="t",i=(e,t)=>e.startsWith(t),o=Promise,s=e=>null==e,a=(e,t,n)=>s(e)?null==n?void 0:n():t(e),u=(e,t,n)=>e.slice(t,n),c=e=>e.length,d=e=>{return t=function*(){return o.all(e)},new Promise(((e,n)=>{var r=e=>{try{i(t.next(e))}catch(e){n(e)}},l=e=>{try{i(t.throw(e))}catch(e){n(e)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,l);i((t=t.apply(void 0,null)).next())}));var t},f=(e,t)=>e.map(t),h=(e,...t)=>e.push(...t),y=Object,v=(e=[])=>y.fromEntries(e),p=(e,t)=>f(y.entries(e),(([e,n])=>t(n,e))),g=(e,t,n)=>(((e,t)=>!s(((e,t)=>a(e,(e=>e[t])))(e,t)))(e,t)||(e[t]=n()),e[t]),P=e=>JSON.stringify(e,((e,t)=>t instanceof Map?y.fromEntries([...t]):t)),S=JSON.parse,m=(e,n,l)=>e+n+(t(l)==r?l:P(l)),x=(e,t,n)=>{const r=c(e);return i(t,e)?[t[r],(n?S:String)(u(t,r+1))]:void 0},w=(e,t)=>((e,t)=>null==e?void 0:e.forEach(t))(e,((e,n)=>t(n,e)));var b=(e,t,n)=>new Promise(((r,l)=>{var i=e=>{try{s(n.next(e))}catch(e){l(e)}},o=e=>{try{s(n.throw(e))}catch(e){l(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,o);s((n=n.apply(e,t)).next())}));const T="hasStore",D=v(f(["Origin","Methods","Headers"],(e=>["Access-Control-Allow-"+e,"*"]))),R=e=>b(void 0,null,(function*(){var t;return yield e.party.storage.get((null!=(t=e.config.storagePrefix)?t:n)+T)})),C=(e,t,r,o)=>b(void 0,null,(function*(){var a;const u=e.party.storage,f=null!=(a=e.config.storagePrefix)?a:n,y={[f+T]:1},v=[],g=[];yield d(p(t[0],((t,n)=>b(void 0,null,(function*(){return s(t)?!r&&e.canDelTable(n,o)&&((e,...t)=>e.unshift(...t))(g,O(f,l,n)):e.canSetTable(n,r,o)&&(yield d(p(t,((t,i)=>b(void 0,null,(function*(){return s(t)?!r&&e.canDelRow(n,i,o)&&h(g,O(f,l,n,i)):e.canSetRow(n,i,r,o)&&(yield d(p(t,((t,a)=>b(void 0,null,(function*(){const c=[n,i,a],d=O(f,l,...c);s(t)?!r&&e.canDelCell(...c,o)&&h(v,d):e.canSetCell(...c,t,r,o,yield u.get(d))&&(y[d]=t)}))))))}))))))}))))),yield d(p(t[1],((t,n)=>b(void 0,null,(function*(){const l=f+"v"+n;s(t)?!r&&e.canDelValue(n,o)&&h(v,l):e.canSetValue(n,t,r,o,yield u.get(l))&&(y[l]=t)}))))),0!=c(g)&&w(yield u.list(),(e=>g.every((t=>!i(e,t)||h(v,e)&&0)))),yield u.delete(v),yield u.put(y)})),O=(e,t,...n)=>m(e,t,u(P(n),1,-1)),V=(e,t,n=null)=>b(void 0,null,(function*(){var r;return new Response(n,{status:t,headers:null!=(r=e.config.responseHeaders)?r:D})}));e.TinyBasePartyKitServer=class{constructor(e){this.party=e,this.config={}}onRequest(e){return b(this,null,(function*(){var t;const r=null!=(t=this.config.storePath)?t:"/store";if(new URL(e.url).pathname.endsWith(r)){const t=yield R(this),r=yield e.text();return"PUT"==e.method?t?V(this,205):(yield C(this,S(r),!0,e),V(this,201)):V(this,200,t?P(yield(i=this,b(void 0,null,(function*(){var e;const t={},r={},o=null!=(e=i.config.storagePrefix)?e:n;return w(yield i.party.storage.list(),((e,n)=>a(x(o,e),(([e,i])=>{if(e==l){const[e,r,l]=S("["+i+"]");g(g(t,e,v),r,v)[l]=n}else"v"==e&&(r[i]=n)})))),[t,r]})))):n)}var i;return V(this,404)}))}onMessage(e,t){return b(this,null,(function*(){var r;const l=null!=(r=this.config.messagePrefix)?r:n;yield a(x(l,e,1),(e=>b(this,[e],(function*([e,n]){"s"==e&&(yield R(this))&&(yield C(this,n,!1,t),this.party.broadcast(m(l,"s",n)))}))))}))}canSetTable(e,t,n){return!0}canDelTable(e,t){return!0}canSetRow(e,t,n,r){return!0}canDelRow(e,t,n){return!0}canSetCell(e,t,n,r,l,i,o){return!0}canDelCell(e,t,n,r){return!0}canSetValue(e,t,n,r,l){return!0}canDelValue(e,t){return!0}}},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterPartyKitServer={});
|
|
Binary file
|