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.
Files changed (38) hide show
  1. package/lib/cjs/persisters/persister-partykit-client.cjs +1 -1
  2. package/lib/cjs/persisters/persister-partykit-client.cjs.gz +0 -0
  3. package/lib/cjs/persisters/persister-partykit-server.cjs +1 -1
  4. package/lib/cjs/persisters/persister-partykit-server.cjs.gz +0 -0
  5. package/lib/cjs-es6/persisters/persister-partykit-client.cjs +1 -1
  6. package/lib/cjs-es6/persisters/persister-partykit-client.cjs.gz +0 -0
  7. package/lib/cjs-es6/persisters/persister-partykit-server.cjs +1 -1
  8. package/lib/cjs-es6/persisters/persister-partykit-server.cjs.gz +0 -0
  9. package/lib/debug/persisters/persister-partykit-client.js +29 -19
  10. package/lib/debug/persisters/persister-partykit-server.js +160 -78
  11. package/lib/es6/persisters/persister-partykit-client.js +1 -1
  12. package/lib/es6/persisters/persister-partykit-client.js.gz +0 -0
  13. package/lib/es6/persisters/persister-partykit-server.js +1 -1
  14. package/lib/es6/persisters/persister-partykit-server.js.gz +0 -0
  15. package/lib/persisters/persister-partykit-client.js +1 -1
  16. package/lib/persisters/persister-partykit-client.js.gz +0 -0
  17. package/lib/persisters/persister-partykit-server.js +1 -1
  18. package/lib/persisters/persister-partykit-server.js.gz +0 -0
  19. package/lib/types/persisters/persister-indexed-db.d.ts +4 -5
  20. package/lib/types/persisters/persister-partykit-client.d.ts +19 -8
  21. package/lib/types/persisters/persister-partykit-server.d.ts +350 -12
  22. package/lib/types/tools.d.ts +4 -6
  23. package/lib/types/ui-react.d.ts +4 -4
  24. package/lib/types/with-schemas/persisters/persister-indexed-db.d.ts +4 -5
  25. package/lib/types/with-schemas/persisters/persister-partykit-client.d.ts +19 -8
  26. package/lib/types/with-schemas/persisters/persister-partykit-server.d.ts +383 -12
  27. package/lib/types/with-schemas/tools.d.ts +4 -6
  28. package/lib/types/with-schemas/ui-react.d.ts +4 -4
  29. package/lib/umd/persisters/persister-partykit-client.js +1 -1
  30. package/lib/umd/persisters/persister-partykit-client.js.gz +0 -0
  31. package/lib/umd/persisters/persister-partykit-server.js +1 -1
  32. package/lib/umd/persisters/persister-partykit-server.js.gz +0 -0
  33. package/lib/umd-es6/persisters/persister-partykit-client.js +1 -1
  34. package/lib/umd-es6/persisters/persister-partykit-client.js.gz +0 -0
  35. package/lib/umd-es6/persisters/persister-partykit-server.js +1 -1
  36. package/lib/umd-es6/persisters/persister-partykit-server.js.gz +0 -0
  37. package/package.json +15 -15
  38. 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 yolo
42
- * export default class extends TinyBasePartyServer {
43
- * readonly config: TinyBasePartyKitServerConfig = {
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
- * export default class extends TinyBasePartyServer {
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, client) {
113
- * await super.onMessage(message, client);
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
- * export default class extends TinyBasePartyServer {
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
- * export default class extends TinyBasePartyServer {
169
- * async onMessage(message, client) {
170
- * await super.onMessage(message, client);
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
- onMessage(message: string, client: Connection): void;
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] = await createTools(
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] = await createTools(
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
- * () => console.log('Will finish transaction'),
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
- * () => console.log('Did finish transaction'),
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=e(""),s=(t,e)=>t instanceof e,o=t=>null==t,n=t=>e(t)==a,r=Object,i=r.keys,c=r.freeze,d=t=>(t=>s(t,r)&&t.constructor==r)(t)&&0==(t=>i(t).length)(t),y=t=>JSON.stringify(t,((t,e)=>s(e,Map)?r.fromEntries([...e]):e)),u=JSON.parse,h=t=>new Map(t),l=(t,e)=>t?.get(e),f=(t,e,a)=>{return o(a)?(s=t,n=e,s?.delete(n),t):t?.set(e,a);var s,n},p=(t,e,a)=>{var s,o;return s=t,o=e,s?.has(o)||f(t,e,a()),l(t,e)},v=h(),w=h(),g="message",m={storeProtocol:"https",storePath:"/store"};t.createPartyKitPersister=(t,e,a,s)=>{const{host:r,room:i}=e.partySocketOptions,{storeProtocol:h,storePath:P}={...m,...n(a)?{storeProtocol:a}:a},S=h+"://"+r+"/parties/"+(e.name??"main")+"/"+i+P,A=async t=>await(await fetch(S,{...t?{method:"PUT",body:y(t)}:{},mode:"cors",cache:"no-store"})).json();return((t,e,a,s,n,r,i=[])=>{let y,u,h,g=0,m=0;p(v,i,(()=>0)),p(w,i,(()=>[]));const P=async t=>(2!=g&&(g=1,await S.schedule((async()=>{await t(),g=0}))),S),S={load:async(a,s)=>await P((async()=>{try{t.setContent(await e())}catch{t.setContent([a,s])}})),startAutoLoad:async(a={},o={})=>(S.stopAutoLoad(),await S.load(a,o),m=1,h=s((async(a,s)=>{if(s){const e=s();await P((async()=>t.setTransactionChanges(e)))}else await P((async()=>{try{t.setContent(a?.()??await e())}catch(t){r?.(t)}}))})),S),stopAutoLoad:()=>(m&&(n(h),h=void 0,m=0),S),save:async e=>(1!=g&&(g=2,await S.schedule((async()=>{try{await a(t.getContent,e)}catch(t){r?.(t)}g=0}))),S),startAutoSave:async()=>(await S.stopAutoSave().save(),y=t.addDidFinishTransactionListener(((t,e)=>{const[a,s]=e();d(a)&&d(s)||S.save((()=>[a,s]))})),S),stopAutoSave:()=>{var e,a;return e=y,a=t.delListener,o(e)||a(e),S},schedule:async(...t)=>(((t,...e)=>{t.push(...e)})(l(w,i),...t),await(async()=>{if(!l(v,i)){for(f(v,i,1);!o((t=l(w,i),u=t.shift()));)try{await u()}catch(t){r?.(t)}f(v,i,0)}var t})(),S),getStore:()=>t,destroy:()=>S.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return c(S)})(t,(async()=>await A()),(async(t,a)=>{var s;a?e.send((s=a(),"s"+(n(s)?s:y(s)))):await A(t())}),(t=>{const a=e=>{const[a,s]=[(i=e.data)[0],u((o=i,n=1,o.slice(n,r)))];var o,n,r,i;"s"==a&&t(void 0,(()=>s))};return e.addEventListener(g,a),a}),(t=>{e.removeEventListener(g,t)}),s)}},"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={});
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={});
@@ -1 +1 @@
1
- var t,e;t=this,e=function(t){"use strict";const e=t=>typeof t,s=e(""),a="t",i=Promise,n=t=>null==t,r=(t,e,s)=>t.slice(e,s),o=t=>t.length,c=(t,e)=>t.map(e),h=(t,...e)=>t.push(...e),f=Object,p=(t=[])=>f.fromEntries(t),l=(t,e)=>c(f.entries(t),(([t,s])=>e(s,t))),y=(t,e,s)=>(((t,e)=>!n(((t,e)=>{return a=t=>t[e],n(s=t)?void 0:a(s);var s,a})(t,e)))(t,e)||(t[e]=s()),t[e]),u=t=>JSON.stringify(t,((t,e)=>e instanceof Map?f.fromEntries([...e]):e)),d=JSON.parse,g=(t,e)=>[t[0],e?d(r(t,1)):r(t,1)],w=(t,e)=>((t,e)=>t?.forEach(e))(t,((t,s)=>e(s,t))),m="hasStore",v=p(c(["Origin","Methods","Headers"],(t=>["Access-Control-Allow-"+t,"*"]))),P=async(t,e)=>await t.get(e+m),R=async(t,e,s)=>{const r=[t.put(e+m,1)],c=[];l(s[0],((s,i)=>n(s)?((t,...e)=>t.unshift(...e))(c,e+x(a,i)):l(s,((s,o)=>n(s)?h(c,e+x(a,i,o)):l(s,((s,n)=>b(r,t,e+x(a,i,o,n),s))))))),l(s[1],((s,a)=>b(r,t,e+"v"+a,s))),0!=o(c)&&w(await t.list(),(e=>c.every((s=>!e.startsWith(s)||b(r,t,e)&&!1)))),await(async t=>i.all(t))(r)},x=(t,...e)=>t+r(u(e),1,-1),b=(t,e,s,a)=>h(t,n(a)?e.delete(s):e.put(s,a));t.TinyBasePartyKitServer=class{constructor(t){this.party=t,this.config={},this.createResponse=(t,e=null)=>new Response(e,{status:t,headers:this.config.responseHeaders??v})}async onRequest(t){const e=this.party.storage,s=this.config.storagePrefix??"",i=this.config.storePath??"/store";if(new URL(t.url).pathname.endsWith(i)){const i=await P(e,s),n=await t.text();return"PUT"==t.method?i?this.createResponse(205):(await R(e,s,d(n)),this.createResponse(201)):this.createResponse(200,i?u(await(async(t,e)=>{const s={},i={};return w(await t.list(),((t,n)=>{if(t.startsWith(e)){t=r(t,o(e));const[c,h]=g(t);if(c==a){const[t,e,a]=d("["+h+"]");y(y(s,t,p),e,p)[a]=n}else"v"==c&&(i[h]=n)}})),[s,i]})(e,s)):"")}return this.createResponse(404)}async onMessage(t,a){const i=this.party.storage,n=this.config.storagePrefix??"",[r,o]=g(t,1);"s"==r&&await P(i,n)&&(await R(i,n,o),this.party.broadcast(((t,a)=>"s"+(e(a)==s?a:u(a)))(0,o),[a.id]))}}},"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={});
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={});
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n=t(""),o=(e,t)=>e instanceof t,r=e=>null==e,l=e=>t(e)==n,i=Object,s=i.keys,u=i.freeze,a=e=>(e=>o(e,i)&&e.constructor==i)(e)&&0==(e=>s(e).length)(e),c=e=>JSON.stringify(e,((e,t)=>o(t,Map)?i.fromEntries([...t]):t)),d=JSON.parse,v=e=>new Map(e),y=(e,t)=>null==e?void 0:e.get(t),f=(e,t,n)=>{return r(n)?(l=t,null==(o=e)||o.delete(l),e):null==e?void 0:e.set(t,n);var o,l},p=(e,t,n)=>{var o,r,l;return r=t,null!=(l=null==(o=e)?void 0:o.has(r))&&l||f(e,t,n()),y(e,t)};var h=(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 P=v(),m=v();var b=Object.defineProperty,g=Object.defineProperties,O=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,A=(e,t,n)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,L=(e,t)=>{for(var n in t||(t={}))j.call(t,n)&&A(e,n,t[n]);if(S)for(var n of S(t))w.call(t,n)&&A(e,n,t[n]);return e},x=(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 C="message",T={storeProtocol:"https",storePath:"/store"};e.createPartyKitPersister=(e,t,n,o)=>{var i;const{host:s,room:v}=t.partySocketOptions,{storeProtocol:b,storePath:S}=L(L({},T),l(n)?{storeProtocol:n}:n),j=b+"://"+s+"/parties/"+(null!=(i=t.name)?i:"main")+"/"+v+S,w=e=>x(void 0,null,(function*(){return yield(yield fetch(j,(t=L({},e?{method:"PUT",body:c(e)}:{}),n={mode:"cors",cache:"no-store"},g(t,O(n))))).json();var t,n}));return((e,t,n,o,l,i,s=[])=>{let c,d,v,b=0,g=0;p(P,s,(()=>0)),p(m,s,(()=>[]));const O=e=>h(void 0,null,(function*(){return 2!=b&&(b=1,yield S.schedule((()=>h(void 0,null,(function*(){yield e(),b=0}))))),S})),S={load:(n,o)=>h(void 0,null,(function*(){return yield O((()=>h(void 0,null,(function*(){try{e.setContent(yield t())}catch(t){e.setContent([n,o])}}))))})),startAutoLoad:(...n)=>h(void 0,[...n],(function*(n={},r={}){return S.stopAutoLoad(),yield S.load(n,r),g=1,v=o(((n,o)=>h(void 0,null,(function*(){if(o){const t=o();yield O((()=>h(void 0,null,(function*(){return e.setTransactionChanges(t)}))))}else yield O((()=>h(void 0,null,(function*(){var o;try{e.setContent(null!=(o=null==n?void 0:n())?o:yield t())}catch(e){null==i||i(e)}}))))})))),S})),stopAutoLoad:()=>(g&&(l(v),v=void 0,g=0),S),save:t=>h(void 0,null,(function*(){return 1!=b&&(b=2,yield S.schedule((()=>h(void 0,null,(function*(){try{yield n(e.getContent,t)}catch(e){null==i||i(e)}b=0}))))),S})),startAutoSave:()=>h(void 0,null,(function*(){return yield S.stopAutoSave().save(),c=e.addDidFinishTransactionListener(((e,t)=>{const[n,o]=t();a(n)&&a(o)||S.save((()=>[n,o]))})),S})),stopAutoSave:()=>{var t,n;return t=c,n=e.delListener,!!r(t)||n(t),S},schedule:(...e)=>h(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(y(m,s),...e),yield h(void 0,null,(function*(){if(!y(P,s)){for(f(P,s,1);!r((e=y(m,s),d=e.shift()));)try{yield d()}catch(e){null==i||i(e)}f(P,s,0)}var e})),S})),getStore:()=>e,destroy:()=>S.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return u(S)})(e,(()=>x(void 0,null,(function*(){return yield w()}))),((e,n)=>x(void 0,null,(function*(){var o;n?t.send((o=n(),"s"+(l(o)?o:c(o)))):yield w(e())}))),(e=>{const n=t=>{const[n,o]=[(s=t.data)[0],d((r=s,l=1,r.slice(l,i)))];var r,l,i,s;"s"==n&&e(void 0,(()=>o))};return t.addEventListener(C,n),n}),(e=>{t.removeEventListener(C,e)}),o)}},"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={});
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={});
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,s=t(""),n="t",r=Promise,i=e=>null==e,o=(e,t,s)=>e.slice(t,s),l=e=>e.length,a=(e,t)=>e.map(t),c=(e,...t)=>e.push(...t),u=Object,h=(e=[])=>u.fromEntries(e),d=(e,t)=>a(u.entries(e),(([e,s])=>t(s,e))),f=(e,t,s)=>(((e,t)=>!i(((e,t)=>{return n=e=>e[t],i(s=e)?void 0:n(s);var s,n})(e,t)))(e,t)||(e[t]=s()),e[t]),y=e=>JSON.stringify(e,((e,t)=>t instanceof Map?u.fromEntries([...t]):t)),p=JSON.parse,v=(e,t)=>[e[0],t?p(o(e,1)):o(e,1)],g=(e,t)=>((e,t)=>null==e?void 0:e.forEach(t))(e,((e,s)=>t(s,e)));var m=(e,t,s)=>new Promise(((n,r)=>{var i=e=>{try{l(s.next(e))}catch(e){r(e)}},o=e=>{try{l(s.throw(e))}catch(e){r(e)}},l=e=>e.done?n(e.value):Promise.resolve(e.value).then(i,o);l((s=s.apply(e,t)).next())}));const P="hasStore",x=h(a(["Origin","Methods","Headers"],(e=>["Access-Control-Allow-"+e,"*"]))),R=(e,t)=>m(void 0,null,(function*(){return yield e.get(t+P)})),w=(e,t,s)=>m(void 0,null,(function*(){const o=[e.put(t+P,1)],a=[];d(s[0],((s,r)=>i(s)?((e,...t)=>e.unshift(...t))(a,t+b(n,r)):d(s,((s,l)=>i(s)?c(a,t+b(n,r,l)):d(s,((s,i)=>S(o,e,t+b(n,r,l,i),s))))))),d(s[1],((s,n)=>S(o,e,t+"v"+n,s))),0!=l(a)&&g(yield e.list(),(t=>a.every((s=>!t.startsWith(s)||S(o,e,t)&&!1)))),yield(e=>{return t=function*(){return r.all(e)},new Promise(((e,s)=>{var n=e=>{try{i(t.next(e))}catch(e){s(e)}},r=e=>{try{i(t.throw(e))}catch(e){s(e)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(n,r);i((t=t.apply(void 0,null)).next())}));var t})(o)})),b=(e,...t)=>e+o(y(t),1,-1),S=(e,t,s,n)=>c(e,i(n)?t.delete(s):t.put(s,n));e.TinyBasePartyKitServer=class{constructor(e){this.party=e,this.config={},this.createResponse=(e,t=null)=>{var s;return new Response(t,{status:e,headers:null!=(s=this.config.responseHeaders)?s:x})}}onRequest(e){return m(this,null,(function*(){var t,s;const r=this.party.storage,i=null!=(t=this.config.storagePrefix)?t:"",a=null!=(s=this.config.storePath)?s:"/store";if(new URL(e.url).pathname.endsWith(a)){const t=yield R(r,i),s=yield e.text();return"PUT"==e.method?t?this.createResponse(205):(yield w(r,i,p(s)),this.createResponse(201)):this.createResponse(200,t?y(yield((e,t)=>m(void 0,null,(function*(){const s={},r={};return g(yield e.list(),((e,i)=>{if(e.startsWith(t)){e=o(e,l(t));const[a,c]=v(e);if(a==n){const[e,t,n]=p("["+c+"]");f(f(s,e,h),t,h)[n]=i}else"v"==a&&(r[c]=i)}})),[s,r]})))(r,i)):"")}return this.createResponse(404)}))}onMessage(e,n){return m(this,null,(function*(){var r;const i=this.party.storage,o=null!=(r=this.config.storagePrefix)?r:"",[l,a]=v(e,1);"s"==l&&(yield R(i,o))&&(yield w(i,o,a),this.party.broadcast(((e,n)=>"s"+(t(n)==s?n:y(n)))(0,a),[n.id]))}))}}},"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={});
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={});