@pluv/io 0.0.0-experimental-20250527040415

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/CHANGELOG.md ADDED
@@ -0,0 +1,2138 @@
1
+ # @pluv/io
2
+
3
+ ## 0.0.0-experimental-20250527040415
4
+
5
+ ### Patch Changes
6
+
7
+ - 724b228: Fixed validating the platform config when using the `PluvServer` in fetch mode.
8
+ - @pluv/crdt@0.0.0-experimental-20250527040415
9
+ - @pluv/types@0.0.0-experimental-20250527040415
10
+
11
+ ## 2.2.7
12
+
13
+ ### Patch Changes
14
+
15
+ - ec2717b: Fixed `ioServer.fetch` not receiving the `PluvServer` config.
16
+ - @pluv/crdt@2.2.7
17
+ - @pluv/types@2.2.7
18
+
19
+ ## 2.2.6
20
+
21
+ ### Patch Changes
22
+
23
+ - @pluv/crdt@2.2.6
24
+ - @pluv/types@2.2.6
25
+
26
+ ## 2.2.5
27
+
28
+ ### Patch Changes
29
+
30
+ - @pluv/crdt@2.2.5
31
+ - @pluv/types@2.2.5
32
+
33
+ ## 2.2.4
34
+
35
+ ### Patch Changes
36
+
37
+ - @pluv/crdt@2.2.4
38
+ - @pluv/types@2.2.4
39
+
40
+ ## 2.2.3
41
+
42
+ ### Patch Changes
43
+
44
+ - @pluv/crdt@2.2.3
45
+ - @pluv/types@2.2.3
46
+
47
+ ## 2.2.2
48
+
49
+ ### Patch Changes
50
+
51
+ - @pluv/crdt@2.2.2
52
+ - @pluv/types@2.2.2
53
+
54
+ ## 2.2.1
55
+
56
+ ### Patch Changes
57
+
58
+ - @pluv/crdt@2.2.1
59
+ - @pluv/types@2.2.1
60
+
61
+ ## 2.2.0
62
+
63
+ ### Patch Changes
64
+
65
+ - cb660cd: Fixed multiple Cloudflare Worker Durable Objects sharing references to the same I/O methods.
66
+ - @pluv/crdt@2.2.0
67
+ - @pluv/types@2.2.0
68
+
69
+ ## 2.1.0
70
+
71
+ ### Patch Changes
72
+
73
+ - @pluv/crdt@2.1.0
74
+ - @pluv/types@2.1.0
75
+
76
+ ## 2.0.2
77
+
78
+ ### Patch Changes
79
+
80
+ - @pluv/crdt@2.0.2
81
+ - @pluv/types@2.0.2
82
+
83
+ ## 2.0.1
84
+
85
+ ### Patch Changes
86
+
87
+ - @pluv/crdt@2.0.1
88
+ - @pluv/types@2.0.1
89
+
90
+ ## 2.0.0
91
+
92
+ ### Patch Changes
93
+
94
+ - 047a1d8: Moved several internal types to `@pluv/types`.
95
+ - Updated dependencies [047a1d8]
96
+ - @pluv/types@2.0.0
97
+ - @pluv/crdt@2.0.0
98
+
99
+ ## 1.0.2
100
+
101
+ ### Patch Changes
102
+
103
+ - @pluv/crdt@1.0.2
104
+ - @pluv/types@1.0.2
105
+
106
+ ## 1.0.1
107
+
108
+ ### Patch Changes
109
+
110
+ - c583be9: Fixed storage race condition that occurred when 2 users joined a room near simultaneously that would cause users to have mismatched storage states from the server (and thereby preventing updates from properly registering) until the user reconnected.
111
+ - @pluv/crdt@1.0.1
112
+ - @pluv/types@1.0.1
113
+
114
+ ## 1.0.0
115
+
116
+ ### Major Changes
117
+
118
+ - af94706: pluv.io is now stable and production ready!
119
+
120
+ With this v1 release, pluv.io will now follow [semantic versioning](https://semver.org/) with more comprehensive release notes for future changes to the library.
121
+
122
+ Checkout the [full documentation here](https://pluv.io/docs/introduction) to get started today!
123
+
124
+ ### Patch Changes
125
+
126
+ - Updated dependencies [af94706]
127
+ - @pluv/crdt@1.0.0
128
+ - @pluv/types@1.0.0
129
+
130
+ ## 0.44.2
131
+
132
+ ### Patch Changes
133
+
134
+ - @pluv/crdt@0.44.2
135
+ - @pluv/types@0.44.2
136
+
137
+ ## 0.44.1
138
+
139
+ ### Patch Changes
140
+
141
+ - @pluv/crdt@0.44.1
142
+ - @pluv/types@0.44.1
143
+
144
+ ## 0.44.0
145
+
146
+ ### Patch Changes
147
+
148
+ - @pluv/crdt@0.44.0
149
+ - @pluv/types@0.44.0
150
+
151
+ ## 0.43.0
152
+
153
+ ### Minor Changes
154
+
155
+ - 0063e80: **BREAKING** Added a configurable limit for the max-size (in bytes) for storage (defaulting to 30MB). To unset this limit, you can set this limit to `0` or `null`.
156
+
157
+ ```ts
158
+ createIO({
159
+ limits: {
160
+ storageMaxSize: null,
161
+ },
162
+ });
163
+ ```
164
+
165
+ - 4b0fbb3: **BREAKING** Added the ability to configure the limits for user object size, presence size, and user id length. User id is now defaulted to be limited to 128 characters. To unset this limit, you can set this limit to `0` or `null`.
166
+
167
+ ```ts
168
+ // defaults
169
+ createIO(
170
+ platformCloudflare({
171
+ limits: {
172
+ presenceMaxSize: 512,
173
+ storageMaxSize: 31_457_280,
174
+ userIdMaxLength: 128,
175
+ userMaxSize: 512,
176
+ },
177
+ }),
178
+ );
179
+ ```
180
+
181
+ ### Patch Changes
182
+
183
+ - e60a677: Fix 1 and 2 character long room names not being supported.
184
+ - 244a973: Fixed not applying user size limits when calling `PluvIO.authorize` and not allowing it to be overwritten for `platformPluv`.
185
+ - @pluv/crdt@0.43.0
186
+ - @pluv/types@0.43.0
187
+
188
+ ## 0.42.0
189
+
190
+ ### Patch Changes
191
+
192
+ - cf1529a: Each time garbage collection is run, a sync-state event will be emitted to connected sessions with info of currently connected users.
193
+ - @pluv/crdt@0.42.0
194
+ - @pluv/types@0.42.0
195
+
196
+ ## 0.41.7
197
+
198
+ ### Patch Changes
199
+
200
+ - @pluv/crdt@0.41.7
201
+ - @pluv/types@0.41.7
202
+
203
+ ## 0.41.6
204
+
205
+ ### Patch Changes
206
+
207
+ - @pluv/crdt@0.41.6
208
+ - @pluv/types@0.41.6
209
+
210
+ ## 0.41.5
211
+
212
+ ### Patch Changes
213
+
214
+ - @pluv/crdt@0.41.5
215
+ - @pluv/types@0.41.5
216
+
217
+ ## 0.41.4
218
+
219
+ ### Patch Changes
220
+
221
+ - @pluv/crdt@0.41.4
222
+ - @pluv/types@0.41.4
223
+
224
+ ## 0.41.3
225
+
226
+ ### Patch Changes
227
+
228
+ - 49051c0: Fix presence keys becoming lost, causing presence objects to be partial and failing schema validation.
229
+ - @pluv/crdt@0.41.3
230
+ - @pluv/types@0.41.3
231
+
232
+ ## 0.41.2
233
+
234
+ ### Patch Changes
235
+
236
+ - @pluv/crdt@0.41.2
237
+ - @pluv/types@0.41.2
238
+
239
+ ## 0.41.1
240
+
241
+ ### Patch Changes
242
+
243
+ - @pluv/crdt@0.41.1
244
+ - @pluv/types@0.41.1
245
+
246
+ ## 0.41.0
247
+
248
+ ### Minor Changes
249
+
250
+ - 73adf21: **BREAKING** The `user` that is provided to `PluvServer.createToken` is now limited to be at most 512 bytes. If the `user` is any larger, `PluvServer.createToken` will now throw an error.
251
+ - f02a430: **BREAKING** Updated the way `user` is stored and read from the websocket, so now `user` is persisted in-memory rather than from persistent storage (improves performance and lowers cost in some cases). This change primarily affects pluv platforms, which are intended for internal use only, and therefore should be mostly non-breaking.
252
+ - 0b908b3: **BREAKING** User's presence is now limited to be at most 512 bytes. If the presence is any larger, the `PluvServer` will now throw an error.
253
+ - 555b88d: Users can now have multiple simultaneous connections. Previously, if a user tried to open a connection to a room while already being connected to the room, the new connection would be blocked. Now, when the user opens another connection, the new connection will be opened and initialized with their latest presence.
254
+
255
+ Users can only have 1 identity and 1 presence, which means that all presence updates will sync across all of that user's connections. This means that even when a user opens multiple connections, they will only appear once in `others`.
256
+
257
+ ### Patch Changes
258
+
259
+ - 6422f3b: In certain edge-cases, WebSocket connections can silently die in all runtimes, causing connected clients to see the presence of other connections that aren't connected anymore.
260
+
261
+ The `IORoom` now automatically garbage collects dead websockets that haven't been pinged in a long time. Garbage collection happens on WebSocket ping/pong messages every 60 seconds.
262
+
263
+ However, garbage collection does not automatically happen for Cloudflare Worker Durable Objects using websocket hiberation because ping/pong messages happen outside of the Durable Object's compute. Therefore `IORoom` now provides a method `garbageCollect` that can be called manually to clear any dead websockets whenever the user chooses.
264
+
265
+ For example, within a Cloudflare Worker Durable Object, an [alarm](https://developers.cloudflare.com/durable-objects/api/alarms/) can be set to periodically run garbage collection for you:
266
+
267
+ ```ts
268
+ import { InferIORoom } from "@pluv/io";
269
+
270
+ class RoomDurableObject extends DurableObject {
271
+ private _room: InferIORoom<typeof ioServer>;
272
+
273
+ constructor(state: DurableObjectState, env: Env) {
274
+ super(state, env);
275
+
276
+ this._room = io.createRoom(state.id.toString(), { env, state });
277
+ }
278
+
279
+ // ... WebSocket handlers here
280
+
281
+ async fetch(request: Request): Promise<Response> {
282
+ // ... WebSocket validation and pair creation here
283
+
284
+ const alarm = await this.ctx.storage.getAlarm();
285
+
286
+ // Start running the garbage collection interval
287
+ if (alarm !== null) await this.ctx.storage.setAlarm(Date.now() + 60_000);
288
+
289
+ await this._room.register(server, { env: this.env, request });
290
+
291
+ // ... Return response
292
+ }
293
+
294
+ async alarm(): Promise<void> {
295
+ await this._room.garbageCollect();
296
+
297
+ // Garbage collect every 1 minute
298
+ await this.ctx.storage.setAlarm(Date.now() + 60_000);
299
+ }
300
+ }
301
+ ```
302
+
303
+ - a663c65: Update websocket session connection ids to be deterministic based on the user's id if authorization is configured (i.e. connection id will now just be the user's id with a prefix).
304
+ - 555b88d: Added a new field `presence` to the server's event resolver context to view the message sender's currently known presence.
305
+ - @pluv/crdt@0.41.0
306
+ - @pluv/types@0.41.0
307
+
308
+ ## 0.40.2
309
+
310
+ ### Patch Changes
311
+
312
+ - @pluv/crdt@0.40.2
313
+ - @pluv/types@0.40.2
314
+
315
+ ## 0.40.1
316
+
317
+ ### Patch Changes
318
+
319
+ - @pluv/crdt@0.40.1
320
+ - @pluv/types@0.40.1
321
+
322
+ ## 0.40.0
323
+
324
+ ### Patch Changes
325
+
326
+ - @pluv/crdt@0.40.0
327
+ - @pluv/types@0.40.0
328
+
329
+ ## 0.39.1
330
+
331
+ ### Patch Changes
332
+
333
+ - @pluv/crdt@0.39.1
334
+ - @pluv/types@0.39.1
335
+
336
+ ## 0.39.0
337
+
338
+ ### Patch Changes
339
+
340
+ - fe6e239: Broadcast the quitting user when the server receives an abnormal message event from a session that was marked as having quit.
341
+ - 737d508: Fix not always fully running clean-up effects on the `IORoom` after websocket sessions are closed.
342
+ - @pluv/crdt@0.39.0
343
+ - @pluv/types@0.39.0
344
+
345
+ ## 0.38.14
346
+
347
+ ### Patch Changes
348
+
349
+ - @pluv/crdt@0.38.14
350
+ - @pluv/types@0.38.14
351
+
352
+ ## 0.38.13
353
+
354
+ ### Patch Changes
355
+
356
+ - 809afd3: Fix generic type default for router events.
357
+ - @pluv/crdt@0.38.13
358
+ - @pluv/types@0.38.13
359
+
360
+ ## 0.38.12
361
+
362
+ ### Patch Changes
363
+
364
+ - @pluv/crdt@0.38.12
365
+ - @pluv/types@0.38.12
366
+
367
+ ## 0.38.11
368
+
369
+ ### Patch Changes
370
+
371
+ - @pluv/crdt@0.38.11
372
+ - @pluv/types@0.38.11
373
+
374
+ ## 0.38.10
375
+
376
+ ### Patch Changes
377
+
378
+ - @pluv/crdt@0.38.10
379
+ - @pluv/types@0.38.10
380
+
381
+ ## 0.38.9
382
+
383
+ ### Patch Changes
384
+
385
+ - @pluv/crdt@0.38.9
386
+ - @pluv/types@0.38.9
387
+
388
+ ## 0.38.8
389
+
390
+ ### Patch Changes
391
+
392
+ - @pluv/crdt@0.38.8
393
+ - @pluv/types@0.38.8
394
+
395
+ ## 0.38.7
396
+
397
+ ### Patch Changes
398
+
399
+ - @pluv/crdt@0.38.7
400
+ - @pluv/types@0.38.7
401
+
402
+ ## 0.38.6
403
+
404
+ ### Patch Changes
405
+
406
+ - @pluv/crdt@0.38.6
407
+ - @pluv/types@0.38.6
408
+
409
+ ## 0.38.5
410
+
411
+ ### Patch Changes
412
+
413
+ - @pluv/crdt@0.38.5
414
+ - @pluv/types@0.38.5
415
+
416
+ ## 0.38.4
417
+
418
+ ### Patch Changes
419
+
420
+ - @pluv/crdt@0.38.4
421
+ - @pluv/types@0.38.4
422
+
423
+ ## 0.38.3
424
+
425
+ ### Patch Changes
426
+
427
+ - 8346273: Disallow the `# @pluv/io character in router event names.
428
+ - @pluv/crdt@0.38.3
429
+ - @pluv/types@0.38.3
430
+
431
+ ## 0.38.2
432
+
433
+ ### Patch Changes
434
+
435
+ - 039cd64: Require `PluvRouter` event names to be formatted as valid JavaScript variable names.
436
+ - @pluv/crdt@0.38.2
437
+ - @pluv/types@0.38.2
438
+
439
+ ## 0.38.1
440
+
441
+ ### Patch Changes
442
+
443
+ - @pluv/crdt@0.38.1
444
+ - @pluv/types@0.38.1
445
+
446
+ ## 0.38.0
447
+
448
+ ### Minor Changes
449
+
450
+ - f4ceca3: Updated internal event names to follow a new naming convention.
451
+
452
+ ### Patch Changes
453
+
454
+ - Updated dependencies [f4ceca3]
455
+ - @pluv/types@0.38.0
456
+ - @pluv/crdt@0.38.0
457
+
458
+ ## 0.37.7
459
+
460
+ ### Patch Changes
461
+
462
+ - @pluv/crdt@0.37.7
463
+ - @pluv/types@0.37.7
464
+
465
+ ## 0.37.6
466
+
467
+ ### Patch Changes
468
+
469
+ - 3a874f1: Now logs errors to the console when errors on encountered on the `onUserConnected` and `onUserDisconnected` events.
470
+ - @pluv/crdt@0.37.6
471
+ - @pluv/types@0.37.6
472
+
473
+ ## 0.37.5
474
+
475
+ ### Patch Changes
476
+
477
+ - 9a9ecee: Fixed an issue where hibernated Cloudflare Worker websockets were not updating their last ping timer and causing them to be disconnected after some time.
478
+ - @pluv/crdt@0.37.5
479
+ - @pluv/types@0.37.5
480
+
481
+ ## 0.37.4
482
+
483
+ ### Patch Changes
484
+
485
+ - @pluv/crdt@0.37.4
486
+ - @pluv/types@0.37.4
487
+
488
+ ## 0.37.3
489
+
490
+ ### Patch Changes
491
+
492
+ - @pluv/crdt@0.37.3
493
+ - @pluv/types@0.37.3
494
+
495
+ ## 0.37.2
496
+
497
+ ### Patch Changes
498
+
499
+ - @pluv/crdt@0.37.2
500
+ - @pluv/types@0.37.2
501
+
502
+ ## 0.37.1
503
+
504
+ ### Patch Changes
505
+
506
+ - @pluv/crdt@0.37.1
507
+ - @pluv/types@0.37.1
508
+
509
+ ## 0.37.0
510
+
511
+ ### Patch Changes
512
+
513
+ - 9b74abb: Improved type inference when calling `PluvIO.server` to not include options that are always undefined (i.e. are not allowed by the specified platform).
514
+ - @pluv/crdt@0.37.0
515
+ - @pluv/types@0.37.0
516
+
517
+ ## 0.36.0
518
+
519
+ ### Patch Changes
520
+
521
+ - @pluv/crdt@0.36.0
522
+ - @pluv/types@0.36.0
523
+
524
+ ## 0.35.4
525
+
526
+ ### Patch Changes
527
+
528
+ - 5d3a56f: Fix error emitted about `platformCloudflare` not supporting `fetch` when deployed to Cloudflare Workers.
529
+ - @pluv/crdt@0.35.4
530
+ - @pluv/types@0.35.4
531
+
532
+ ## 0.35.3
533
+
534
+ ### Patch Changes
535
+
536
+ - @pluv/crdt@0.35.3
537
+ - @pluv/types@0.35.3
538
+
539
+ ## 0.35.2
540
+
541
+ ### Patch Changes
542
+
543
+ - 81cb692: Fixed type inference of the `authorize` option in `createIO` when used as a function.
544
+ - Updated dependencies [81cb692]
545
+ - @pluv/types@0.35.2
546
+ - @pluv/crdt@0.35.2
547
+
548
+ ## 0.35.1
549
+
550
+ ### Patch Changes
551
+
552
+ - @pluv/crdt@0.35.1
553
+ - @pluv/types@0.35.1
554
+
555
+ ## 0.35.0
556
+
557
+ ### Minor Changes
558
+
559
+ - c9073ad: **BREAKING**
560
+
561
+ Removed the `required` property on the `authorize` config when creating a `PluvIO` instance. When `authorize` is provided, the session will be required to be authorized.
562
+
563
+ ```ts
564
+ // Before
565
+ import { z } from "zod";
566
+
567
+ const io = createIO({
568
+ // ...
569
+ authorize: {
570
+ // Previously required: true to force all users to authorize
571
+ required: true,
572
+ user: z.object({
573
+ id: z.string(),
574
+ name: z.string(),
575
+ }),
576
+ secret: "sk_...",
577
+ },
578
+ // ...
579
+ });
580
+
581
+ // After
582
+
583
+ const io = createIO({
584
+ // ...
585
+ authorize: {
586
+ // No more `required` property. Now automatically applied always if
587
+ // `authorize` prop is provided to `createIO`
588
+ user: z.object({
589
+ id: z.string(),
590
+ name: z.string(),
591
+ }),
592
+ secret: "sk_...",
593
+ },
594
+ // ...
595
+ });
596
+ ```
597
+
598
+ ### Patch Changes
599
+
600
+ - @pluv/crdt@0.35.0
601
+ - @pluv/types@0.35.0
602
+
603
+ ## 0.34.1
604
+
605
+ ### Patch Changes
606
+
607
+ - d639427: Narrow type `EventResolverContext` so that `session` is only null on `sync` event types.
608
+ - @pluv/crdt@0.34.1
609
+ - @pluv/types@0.34.1
610
+
611
+ ## 0.34.0
612
+
613
+ ### Minor Changes
614
+
615
+ - 70af3b2: Updated `@pluv/io` to have a `handleMode` internally that determines if connections are handled by the `PluvServer` or by the platform itself (i.e. outside of the `PluvServer`). The internals of `@pluv/platform-node` and `@pluv/platform-cloudflare` have been updated with the required changes for this.
616
+
617
+ ### Patch Changes
618
+
619
+ - 0c920ea: Fix the `onUserDisconnected` event not triggering.
620
+ - @pluv/crdt@0.34.0
621
+ - @pluv/types@0.34.0
622
+
623
+ ## 0.33.0
624
+
625
+ ### Patch Changes
626
+
627
+ - @pluv/crdt@0.33.0
628
+ - @pluv/types@0.33.0
629
+
630
+ ## 0.32.9
631
+
632
+ ### Patch Changes
633
+
634
+ - @pluv/crdt@0.32.9
635
+ - @pluv/types@0.32.9
636
+
637
+ ## 0.32.8
638
+
639
+ ### Patch Changes
640
+
641
+ - e659f8a: Update `getInitialStorage` so that the context is made available on the `context` event property.
642
+
643
+ ```ts
644
+ import { createIO } from "@pluv/io";
645
+
646
+ // Before
647
+ const io = createIO({
648
+ getInitialStorage: ({ room, ...context }) => {
649
+ // ...
650
+ },
651
+ });
652
+
653
+ // After
654
+ const io = createIO({
655
+ // Context is now an explicit property on the event
656
+ getInitialStorage: ({ room, context }) => {
657
+ // ...
658
+ },
659
+ });
660
+ ```
661
+
662
+ - @pluv/crdt@0.32.8
663
+ - @pluv/types@0.32.8
664
+
665
+ ## 0.32.7
666
+
667
+ ### Patch Changes
668
+
669
+ - @pluv/crdt@0.32.7
670
+ - @pluv/types@0.32.7
671
+
672
+ ## 0.32.6
673
+
674
+ ### Patch Changes
675
+
676
+ - c0956e7: Add `onUserConnected` and `onUserDisconnected` events on `PluvServer`.
677
+
678
+ ```ts
679
+ import { createIO } from "@pluv/io";
680
+
681
+ const io = createIO({
682
+ /* ... */
683
+ });
684
+
685
+ const ioServer = io.server({
686
+ // ...
687
+ onUserConnected: (event) => {
688
+ // ...
689
+ },
690
+ onUserDisconnected: (event) => {
691
+ // ...
692
+ },
693
+ });
694
+ ```
695
+
696
+ - @pluv/crdt@0.32.6
697
+ - @pluv/types@0.32.6
698
+
699
+ ## 0.32.5
700
+
701
+ ### Patch Changes
702
+
703
+ - @pluv/crdt@0.32.5
704
+ - @pluv/types@0.32.5
705
+
706
+ ## 0.32.4
707
+
708
+ ### Patch Changes
709
+
710
+ - @pluv/crdt@0.32.4
711
+ - @pluv/types@0.32.4
712
+
713
+ ## 0.32.3
714
+
715
+ ### Patch Changes
716
+
717
+ - bb21274: Added the ability to evict (i.e. close) a connection to a room via `IORoom.evict` and `IORoom.evictAll`.
718
+ - @pluv/crdt@0.32.3
719
+ - @pluv/types@0.32.3
720
+
721
+ ## 0.32.2
722
+
723
+ ### Patch Changes
724
+
725
+ - 890d45b: Update `onRoomMessage` and `onStorageUpdated` events to include the WebSocket as part of the `event` parameter of those listeners.
726
+ - @pluv/crdt@0.32.2
727
+ - @pluv/types@0.32.2
728
+
729
+ ## 0.32.1
730
+
731
+ ### Patch Changes
732
+
733
+ - @pluv/crdt@0.32.1
734
+ - @pluv/types@0.32.1
735
+
736
+ ## 0.32.0
737
+
738
+ ### Minor Changes
739
+
740
+ - cde5305: **BREAKING**
741
+
742
+ Update `createIO`'s `context` property to allow lazy initialization as a function. The `context` also no-longer contains platform-specific values by default. See example below:
743
+
744
+ ```ts
745
+ import { createIO } from "@pluv/io";
746
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
747
+ import { Database } from "./database";
748
+
749
+ // Before
750
+ const io = createIO({
751
+ platform: platformCloudflare(),
752
+ context: {
753
+ // Maybe you need to access `env` for Cloudflare, but it's not accessible
754
+ // here
755
+ db: new Database(env.DATABASE_URL),
756
+ // ^ Does not exist
757
+
758
+ // Even though it's not specified in this `context`, Cloudflare's
759
+ // env and state values were previously available where context
760
+ // was referenced
761
+ },
762
+ });
763
+
764
+ // After
765
+ const io = createIO({
766
+ platform: platformCloudfare(),
767
+ context: ({ env, state }) => ({
768
+ db: new Database(env.DATABASE_URL),
769
+ // ^ Now accessible
770
+
771
+ // Now these must be forwarded to use them
772
+ env,
773
+ state,
774
+ }),
775
+ });
776
+ ```
777
+
778
+ ### Patch Changes
779
+
780
+ - @pluv/crdt@0.32.0
781
+ - @pluv/types@0.32.0
782
+
783
+ ## 0.31.0
784
+
785
+ ### Minor Changes
786
+
787
+ - b3c31d7: **BREAKING**
788
+
789
+ Fixed platform context types. This will require additional properties when registering a websocket and creating authorization tokens. See example below:
790
+
791
+ ```ts
792
+ // @pluv/platform-node example
793
+
794
+ import { platformNode } from "@pluv/platform-node";
795
+ import { createIO } from "@pluv/io";
796
+ import type { IncomingMessage } from "node:http";
797
+ import { z } from "zod";
798
+
799
+ const io = createIO({
800
+ // If using a function authorize parameter, `req` is now available as a param
801
+ authorize: ({ req }) => ({
802
+ required: true,
803
+ secret: "MY-CUSTOM-SECRET",
804
+ user: z.object({
805
+ id: z.string(),
806
+ }),
807
+ }),
808
+ platformNode(),
809
+ });
810
+
811
+ // Before
812
+ io.createToken({
813
+ room: "my-custom-room",
814
+ user: { id: "abc123" },
815
+ });
816
+
817
+ // After
818
+ io.createToken({
819
+ room: "my-custom-room",
820
+ user: { id: "abc123" },
821
+
822
+ // Previously not required, but now required
823
+ req: req as IncomingMessage,
824
+ });
825
+ ```
826
+
827
+ ```ts
828
+ // @pluv/platform-cloudflare example
829
+
830
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
831
+ import { createIO } from "@pluv/io";
832
+ import { z } from "zod";
833
+
834
+ const io = createIO({
835
+ // If using a function authorize parameter, `env` and `request` are now available as params
836
+ authorize: ({ env, request }) => ({
837
+ required: true,
838
+ secret: "MY-CUSTOM-SECRET",
839
+ user: z.object({
840
+ id: z.string(),
841
+ }),
842
+ }),
843
+ platformCloudflare(),
844
+ });
845
+
846
+ // Before
847
+ io.createToken({
848
+ room: "my-custom-room",
849
+ user: { id: "abc123" },
850
+ });
851
+
852
+ // After
853
+ io.createToken({
854
+ room: "my-custom-room",
855
+ user: { id: "abc123" },
856
+
857
+ // Previously not required, but now required
858
+ env: env as Env,
859
+ request: request as Request,
860
+ });
861
+ ```
862
+
863
+ ### Patch Changes
864
+
865
+ - @pluv/crdt@0.31.0
866
+ - @pluv/types@0.31.0
867
+
868
+ ## 0.30.2
869
+
870
+ ### Patch Changes
871
+
872
+ - @pluv/crdt@0.30.2
873
+ - @pluv/types@0.30.2
874
+
875
+ ## 0.30.1
876
+
877
+ ### Patch Changes
878
+
879
+ - b9c3633: Export the `authorize` utility from `@pluv/io`.
880
+ - @pluv/crdt@0.30.1
881
+ - @pluv/types@0.30.1
882
+
883
+ ## 0.30.0
884
+
885
+ ### Patch Changes
886
+
887
+ - 7246a9e: Added `CrdtLibraryType` so that `@pluv/crdt-yjs` and `@pluv/crdt-loro` export a new property `kind` containing an identifier for the crdt.
888
+ - @pluv/crdt@0.30.0
889
+ - @pluv/types@0.30.0
890
+
891
+ ## 0.29.0
892
+
893
+ ### Patch Changes
894
+
895
+ - @pluv/crdt@0.29.0
896
+ - @pluv/types@0.29.0
897
+
898
+ ## 0.28.0
899
+
900
+ ### Patch Changes
901
+
902
+ - @pluv/crdt@0.28.0
903
+ - @pluv/types@0.28.0
904
+
905
+ ## 0.27.0
906
+
907
+ ### Patch Changes
908
+
909
+ - 19ed36c: Fixed custom events not properly registering on IORoom.
910
+ - e309b0b: Events without a procedure will now automatically be passed-through to connected peers as-if they were broadcast.
911
+
912
+ ```tsx
913
+ // backend
914
+
915
+ const io = createIO({
916
+ /* ... */
917
+ });
918
+
919
+ const ioServer = io.server({
920
+ router: io.router({
921
+ sendGreeting: io.procedure
922
+ .input(z.object({ name: z.string() }))
923
+ .broadcast(({ name }) => ({
924
+ receiveGreeting: { greeting: `Hi, I'm ${name}!` },
925
+ })),
926
+ }),
927
+ });
928
+
929
+ // frontend
930
+
931
+ const broadcast = useBroadcast();
932
+
933
+ // This will be captured in the server procedure and emit receiveGreeting
934
+ broadcast.sendGreeting({ name: "leedavidcs" });
935
+
936
+ event.receiveGreeting.useEvent(({ data }) => {
937
+ console.log(data.greeting);
938
+ });
939
+
940
+ // This is not captured by any server procedure and will be broadcast to peers as-is
941
+
942
+ broadcast.myCustomUncaughtEvent({ randomData: "Hello world!" });
943
+
944
+ // This will be be received by all connections, passed as-is from the server
945
+ event.myCustomUncaughtEvent.useEvent(({ data }) => {
946
+ console.log(data.randomData);
947
+ });
948
+ ```
949
+
950
+ - @pluv/crdt@0.27.0
951
+ - @pluv/types@0.27.0
952
+
953
+ ## 0.26.0
954
+
955
+ ### Patch Changes
956
+
957
+ - @pluv/crdt@0.26.0
958
+ - @pluv/types@0.26.0
959
+
960
+ ## 0.25.4
961
+
962
+ ### Patch Changes
963
+
964
+ - 7a9080c: Fix not passing all properties to the platform initialization.
965
+ - @pluv/crdt@0.25.4
966
+ - @pluv/types@0.25.4
967
+
968
+ ## 0.25.3
969
+
970
+ ### Patch Changes
971
+
972
+ - 50d9b96: Export listener and event types.
973
+ - @pluv/crdt@0.25.3
974
+ - @pluv/types@0.25.3
975
+
976
+ ## 0.25.2
977
+
978
+ ### Patch Changes
979
+
980
+ - 60a0bf1: Update internal accessor.
981
+ - @pluv/crdt@0.25.2
982
+ - @pluv/types@0.25.2
983
+
984
+ ## 0.25.1
985
+
986
+ ### Patch Changes
987
+
988
+ - 3925f7c: Update internal accessor.
989
+ - @pluv/crdt@0.25.1
990
+ - @pluv/types@0.25.1
991
+
992
+ ## 0.25.0
993
+
994
+ ### Minor Changes
995
+
996
+ - 9db06ba: **BREAKING **
997
+
998
+ Fixed typos `persistance` to `persistence`.
999
+
1000
+ This does mean that all properties referencing `persistance` will need to be fixed. Examples below:
1001
+
1002
+ ```bash
1003
+ # Re-install @pluv/persistence-redis
1004
+ pnpm uninstall @pluv/persistance-redis
1005
+ pnpm install @pluv/persistence-redis
1006
+ ```
1007
+
1008
+ ```ts
1009
+ // Before
1010
+ createIO({
1011
+ platform: platformNode({
1012
+ persistance: new PersistanceRedis(/* ... */),
1013
+ }),
1014
+ });
1015
+
1016
+ // After
1017
+ createIO({
1018
+ platform: platformNode({
1019
+ persistence: new PersistenceRedis(/* ... */),
1020
+ }),
1021
+ });
1022
+ ```
1023
+
1024
+ `@pluv/persistance-redis` has been deprecated for `@pluv/persistence-redis`.
1025
+
1026
+ ### Patch Changes
1027
+
1028
+ - 4e078ca: Fix IORoom onRoomMessage event triggering on message sent instead of on message received.
1029
+ - f556d30: Refactored PluvServer and IORoom properties to consolidate internal properties.
1030
+ - @pluv/crdt@0.25.0
1031
+ - @pluv/types@0.25.0
1032
+
1033
+ ## 0.24.1
1034
+
1035
+ ### Patch Changes
1036
+
1037
+ - @pluv/crdt@0.24.1
1038
+ - @pluv/types@0.24.1
1039
+
1040
+ ## 0.24.0
1041
+
1042
+ ### Minor Changes
1043
+
1044
+ - 6ac8a46: \* Fixed errors thrown when using Cloudflare's websocket hibernation API caused by rooms being re-used between different instances of DurableObjects.
1045
+
1046
+ - Add configurable `onDelete` and `onMessage` event listeners that can be set when rooms are created.
1047
+
1048
+ **BREAKING**
1049
+
1050
+ - Changed `PluvServer.getRoom` to `PluvServer.createRoom`. This means `PluvServer` only handles room creation. Room management must now be handled manually. This mainly affects manually creating rooms with `@pluv/platform-node`, and will likely not affect you if you are either using `createPluvHandler` on any platform, or if you are using `@pluv/platform-cloudflare`.
1051
+
1052
+ ```ts
1053
+ // For @pluv/platform-node
1054
+
1055
+ // Before
1056
+
1057
+ import { createIO } from "@pluv/io";
1058
+
1059
+ const io = createIO(/* ... */);
1060
+ const ioServer = io.server(/* ... */);
1061
+
1062
+ const roomId = "my-room-id";
1063
+ const room = ioServer.getRoom(roomId);
1064
+
1065
+ // After
1066
+
1067
+ import { createIO, type InferIORoom } from "@pluv/io";
1068
+
1069
+ const io = createIO(/* ... */);
1070
+ const ioServer = io.server(/* ... */);
1071
+
1072
+ const rooms = new Map<string, InferIORoom<typeof ioServer>>();
1073
+
1074
+ const roomId = "my-room-id";
1075
+ const room = ioServer.createRoom(roomId, {
1076
+ // Use new onDelete event listener
1077
+ onDelete: (event) => {
1078
+ rooms.delete(event.room);
1079
+ },
1080
+ });
1081
+
1082
+ rooms.set(roomId, room);
1083
+ ```
1084
+
1085
+ - c26986d: Fixed websocket messages getting lost after the Cloudflare Worker Durable Object wakes up from hibernation.
1086
+
1087
+ **BREAKING**
1088
+
1089
+ Updated `onMessage`, `onClose` and `onError` to all return `Promise.void` instead of `void`.
1090
+
1091
+ ```ts
1092
+ // Before
1093
+
1094
+ const io = createIO(/* ... */);
1095
+ const ioServer = io.server(/* ... */);
1096
+
1097
+ class RoomDurableObject implements DurableObject {
1098
+ public webSocketClose(ws: WebSocket, code: number, reason: string): void {
1099
+ const handler = this._room.onClose(ws);
1100
+
1101
+ // Previously returned `void`
1102
+ handler({ code, reason });
1103
+ }
1104
+
1105
+ public webSocketError(ws: WebSocket, error: unknown): void {
1106
+ const handler = this._room.onError(ws);
1107
+ const eventError = error instanceof Error ? error : new Error("Internal Error");
1108
+
1109
+ // Previously returned `void`
1110
+ handler({ error: eventError, message: eventError.message });
1111
+ }
1112
+
1113
+ public webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): void {
1114
+ const handler = this._room.onMessage(ws);
1115
+
1116
+ // Previously returned `void`
1117
+ handler({ data: message });
1118
+ }
1119
+ }
1120
+
1121
+ // After
1122
+
1123
+ const io = createIO(/* ... */);
1124
+ const ioServer = io.server(/* ... */);
1125
+
1126
+ class RoomDurableObject implements DurableObject {
1127
+ public async webSocketClose(ws: WebSocket, code: number, reason: string): Promise<void> {
1128
+ const handler = this._room.onClose(ws);
1129
+
1130
+ // Handler must now be awaited
1131
+ await handler({ code, reason });
1132
+ }
1133
+
1134
+ public async webSocketError(ws: WebSocket, error: unknown): Promise<void> {
1135
+ const handler = this._room.onError(ws);
1136
+ const eventError = error instanceof Error ? error : new Error("Internal Error");
1137
+
1138
+ // Handler must now be awaited
1139
+ await handler({ error: eventError, message: eventError.message });
1140
+ }
1141
+
1142
+ public async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void> {
1143
+ const handler = this._room.onMessage(ws);
1144
+
1145
+ // Handler must now be awaited
1146
+ await handler({ data: message });
1147
+ }
1148
+ }
1149
+ ```
1150
+
1151
+ ### Patch Changes
1152
+
1153
+ - @pluv/crdt@0.24.0
1154
+ - @pluv/types@0.24.0
1155
+
1156
+ ## 0.23.0
1157
+
1158
+ ### Minor Changes
1159
+
1160
+ - c01b16f: **BREAKING**
1161
+
1162
+ Moved `getInitialStorage`, `onRoomDeleted` and `onStorageUpdated` from `createIO` to `PluvIO.server`.
1163
+
1164
+ ```ts
1165
+ import { createIO } from "@pluv/io";
1166
+
1167
+ // Before
1168
+ const io = createIO({
1169
+ // ...
1170
+ getInitialStorage: (event) => {
1171
+ // ...
1172
+ },
1173
+ onRoomDeleted: (event) => {
1174
+ // ...
1175
+ },
1176
+ onStorageUpdated: (event) => {
1177
+ // ...
1178
+ },
1179
+ // ...
1180
+ });
1181
+
1182
+ const ioServer = io.server({
1183
+ // ...
1184
+ });
1185
+
1186
+ // After
1187
+ const io = createIO({
1188
+ // ...
1189
+ });
1190
+
1191
+ const ioServer = io.server({
1192
+ // ...
1193
+ getInitialStorage: (event) => {
1194
+ // ...
1195
+ },
1196
+ onRoomDeleted: (event) => {
1197
+ // ...
1198
+ },
1199
+ onStorageUpdated: (event) => {
1200
+ // ...
1201
+ },
1202
+ // ...
1203
+ });
1204
+ ```
1205
+
1206
+ Added a new listener `onRoomMessage` to `PluvIO.server` to listen to events that are sent within a room.
1207
+
1208
+ ```ts
1209
+ const ioServer = io.server({
1210
+ // ...
1211
+ onRoomMessage: (event) => {
1212
+ console.log(event.message);
1213
+ console.log(event.user);
1214
+ },
1215
+ // ...
1216
+ });
1217
+ ```
1218
+
1219
+ ### Patch Changes
1220
+
1221
+ - @pluv/crdt@0.23.0
1222
+ - @pluv/types@0.23.0
1223
+
1224
+ ## 0.22.0
1225
+
1226
+ ### Minor Changes
1227
+
1228
+ - 650e577: \* Fix `@pluv/platform-cloudflare` causing frequent disconnects due to incorrect heartbeat handling.
1229
+ - Updated default `mode` of `@pluv/platform-cloudflare` back to `"detached"` (i.e. use Cloudflare Worker Hibernation API by default).
1230
+
1231
+ ### Patch Changes
1232
+
1233
+ - @pluv/crdt@0.22.0
1234
+ - @pluv/types@0.22.0
1235
+
1236
+ ## 0.21.1
1237
+
1238
+ ### Patch Changes
1239
+
1240
+ - @pluv/crdt@0.21.1
1241
+ - @pluv/types@0.21.1
1242
+
1243
+ ## 0.21.0
1244
+
1245
+ ### Minor Changes
1246
+
1247
+ - 307bd44: `@pluv/platform-cloudflare` now supports Cloudflare Worker's WebSocket Hibernation API, and usees it by default.
1248
+
1249
+ To switch back to not using the WebSocket Hibernation API, specify a `mode` of `attached`.
1250
+
1251
+ ```ts
1252
+ // With event-listeners directly attached to the websocket on registration (i.e. non-hibernation)
1253
+ createIO({
1254
+ platform: platformCloudflare({
1255
+ mode: "attached",
1256
+ }),
1257
+ });
1258
+
1259
+ // With event listeners unattached to the websocket during registration (i.e. hibernation)
1260
+ createIO({
1261
+ platform: platformCloudflare({
1262
+ mode: "detached",
1263
+ }),
1264
+ });
1265
+ ```
1266
+
1267
+ - 41b15e4: **BREAKING** - Updated `sessions` type in the procedure context from `Map<string, WebSocketSession>` to `readonly WebSocketSession[]`.
1268
+ - f570c8a: **BREAKING**: The original request object is no longer available in the context of any event resolvers.
1269
+
1270
+ Previously, the request object that was passed into `PluvServer.getRoom` would be made available on the context object of each of the resolvers. This is no-longer a part of the event context, and therefore needs to be omitted from calls to `PluvServer.getRoom`.
1271
+
1272
+ ```ts
1273
+ // Before
1274
+
1275
+ // With platform-node
1276
+ ioServer.getRoom(websocket, { req, token });
1277
+
1278
+ // With platform-cloudflare
1279
+ ioServer.getRoom(websocket, { env, req, token });
1280
+ ```
1281
+
1282
+ ```ts
1283
+ // Now
1284
+
1285
+ // With platform-node
1286
+ ioServer.getRoom(websocket, { req });
1287
+
1288
+ // With platform-cloudflare
1289
+ ioServer.getRoom(websocket, { env, req });
1290
+ ```
1291
+
1292
+ - b98ab6b: Internal updates to platforms (i.e. `@pluv/platform-cloudflare` and `@pluv/platform-node`) to be able to support Cloudflare Worker Websocket Hibernation APIs.
1293
+ - 4c2228d: **BREAKING**: Require `DurableObjectState` in `ioServer.getRoom`.
1294
+
1295
+ ```ts
1296
+ // Before
1297
+
1298
+ // With platform-cloudflare
1299
+ ioServer.getRoom(websocket, { env, req });
1300
+ ```
1301
+
1302
+ ```ts
1303
+ // Now
1304
+
1305
+ // With platform-cloudflare
1306
+ ioServer.getRoom(websocket, { env, req, state });
1307
+ ```
1308
+
1309
+ ### Patch Changes
1310
+
1311
+ - cc2613e: Moved `sessionId` from being derived in `IORoom` to being derived as a getter in `AbstractWebsocket`.
1312
+ - @pluv/crdt@0.21.0
1313
+ - @pluv/types@0.21.0
1314
+
1315
+ ## 0.20.0
1316
+
1317
+ ### Patch Changes
1318
+
1319
+ - Updated dependencies [9492085]
1320
+ - @pluv/crdt@0.20.0
1321
+ - @pluv/types@0.20.0
1322
+
1323
+ ## 0.19.0
1324
+
1325
+ ### Patch Changes
1326
+
1327
+ - @pluv/crdt@0.19.0
1328
+ - @pluv/types@0.19.0
1329
+
1330
+ ## 0.18.0
1331
+
1332
+ ### Minor Changes
1333
+
1334
+ - 428c21c: Added broadcast proxy as a new way to broadcast events to a room.
1335
+
1336
+ ```tsx
1337
+ // backend
1338
+
1339
+ const io = createIO({
1340
+ /* ... */
1341
+ });
1342
+
1343
+ const router = io.router({
1344
+ SEND_MESSAGE: io.procedure
1345
+ .input(z.object({ message: z.string() }))
1346
+ .broadcast(({ message }) => ({ RECEIVE_MESSAGE: { message } })),
1347
+ });
1348
+
1349
+ const ioServer = io.server({ router });
1350
+
1351
+ const room = ioServer.getRoom("MY_EXAMPLE_ROOM");
1352
+
1353
+ // Both of the examples below are equivalent.
1354
+
1355
+ room.broadcast("SEND_MESSAGE", { message: "Hello world~!" });
1356
+
1357
+ room.broadcast.SEND_MESSAGE({ message: "Hello world~!" });
1358
+ ```
1359
+
1360
+ - 329dbcd: Narrowed types for `user` within the session object of an event resolver.
1361
+ - 99b5ca9: ## Breaking Changes
1362
+
1363
+ - `@pluv/io` has been updated to introduce `PluvProcedure`, `PluvRouter` and `PluvServer`. This change is intended to improve the ergonomics of declaring events and simplifying inferences of event types.
1364
+
1365
+ ### Before:
1366
+
1367
+ ```ts
1368
+ // backend/io.ts
1369
+
1370
+ import { createIO } from "@pluv/io";
1371
+ import { createPluvHandler, platformNode } from "@pluv/platform-node";
1372
+ import { z } from "zod";
1373
+
1374
+ export const io = createIO({
1375
+ platform: platformNode(),
1376
+ })
1377
+ .event("SEND_MESSAGE", {
1378
+ input: z.object({ message: z.string() }),
1379
+ resolver: ({ message }) => ({ RECEIVE_MESSAGE: { message } }),
1380
+ })
1381
+ .event("DOUBLE_VALUE", {
1382
+ input: z.object({ value: z.number() }),
1383
+ resolver: ({ value }) => ({ VALUE_DOUBLED: { value: value * 2 } }),
1384
+ });
1385
+
1386
+ const Pluv = createPluvHandler({
1387
+ io,
1388
+ /* ... */
1389
+ });
1390
+ ```
1391
+
1392
+ ```ts
1393
+ // frontend/pluv.ts
1394
+
1395
+ import { createClient } from "@pluv/react";
1396
+ import type { io } from "../backend/io";
1397
+
1398
+ const client = createClient<typeof io>({
1399
+ /* ... */
1400
+ });
1401
+ ```
1402
+
1403
+ ### Now:
1404
+
1405
+ ```ts
1406
+ import { createIO } from "@pluv/io";
1407
+ import { createPluvHandler, platformNode } from "@pluv/platform-node";
1408
+ import { z } from "zod";
1409
+
1410
+ const io = createIO({
1411
+ platform: platformNode(),
1412
+ });
1413
+
1414
+ const router = io.router({
1415
+ SEND_MESSAGE: io.procedure
1416
+ .input(z.object({ message: z.string() }))
1417
+ .broadcast(({ message }) => ({
1418
+ RECEIVE_MESSAGE: { message },
1419
+ })),
1420
+ DOUBLE_VALUE: io.procedure
1421
+ .input(z.object({ value: z.number() }))
1422
+ .broadcast(({ value }) => ({
1423
+ VALUE_DOUBLED: { value: value * 2 },
1424
+ })),
1425
+ });
1426
+
1427
+ export const ioServer = io.server({ router });
1428
+
1429
+ const Pluv = createPluvHandler({
1430
+ io: ioServer, // <- This uses the PluvServer now
1431
+ /* ... */
1432
+ });
1433
+ ```
1434
+
1435
+ ```ts
1436
+ // frontend/pluv.ts
1437
+
1438
+ import { createClient } from "@pluv/react";
1439
+ import type { ioServer } from "../backend/io";
1440
+
1441
+ // This users the PluvServer type now
1442
+ const client = createClient<typeof ioServer>({
1443
+ /* ... */
1444
+ });
1445
+ ```
1446
+
1447
+ - `PluvRouter` instances can also be merged via the `mergeRouters` method, which effectively performs an `Object.assign` of the events object and returns a new `PluvRouter` with the correct types:
1448
+
1449
+ ```ts
1450
+ const router = io.mergeRouters(router1, router2);
1451
+ ```
1452
+
1453
+ ### Patch Changes
1454
+
1455
+ - Updated dependencies [99b5ca9]
1456
+ - @pluv/types@0.18.0
1457
+ - @pluv/crdt@0.18.0
1458
+
1459
+ ## 0.17.3
1460
+
1461
+ ### Patch Changes
1462
+
1463
+ - @pluv/crdt@0.17.3
1464
+ - @pluv/types@0.17.3
1465
+
1466
+ ## 0.17.2
1467
+
1468
+ ### Patch Changes
1469
+
1470
+ - @pluv/crdt@0.17.2
1471
+ - @pluv/types@0.17.2
1472
+
1473
+ ## 0.17.1
1474
+
1475
+ ### Patch Changes
1476
+
1477
+ - @pluv/crdt@0.17.1
1478
+ - @pluv/types@0.17.1
1479
+
1480
+ ## 0.17.0
1481
+
1482
+ ### Minor Changes
1483
+
1484
+ - 507bc00: _BREAKING_: The `authorize` config when calling `createIO` can now also be a function that exposes the platform context.
1485
+ This allows accessing the `env` in Cloudflare workers.
1486
+
1487
+ ```ts
1488
+ import { createIO } from "@pluv/io";
1489
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
1490
+ import { z } from "zod";
1491
+
1492
+ const io = createIO({
1493
+ authorize: ({ env }) => ({
1494
+ required: true,
1495
+ secret: env.PLUV_AUTHORIZE_SECRET,
1496
+ user: z.object({
1497
+ id: z.string(),
1498
+ name: z.string(),
1499
+ }),
1500
+ }),
1501
+ platform: platformCloudflare<{ PLUV_AUTHORIZE_SECRET: string }>(),
1502
+ // ...
1503
+ });
1504
+ ```
1505
+
1506
+ This also requires that the platform contexts are passed to `io.createToken`.
1507
+
1508
+ ```ts
1509
+ // If using `platformNode`
1510
+ await io.createToken({
1511
+ req, // This `IncomingMessage` is now required
1512
+ room,
1513
+ user: {
1514
+ id: "user_123",
1515
+ name: "john doe",
1516
+ },
1517
+ });
1518
+
1519
+ // If using `platformCloudflare`
1520
+ await io.createToken({
1521
+ env, // This env is now required from the handler's fetch function
1522
+ room,
1523
+ user: {
1524
+ id: "user_123",
1525
+ name: "john doe",
1526
+ },
1527
+ });
1528
+ ```
1529
+
1530
+ ### Patch Changes
1531
+
1532
+ - Updated dependencies [507bc00]
1533
+ - @pluv/types@0.17.0
1534
+ - @pluv/crdt@0.17.0
1535
+
1536
+ ## 0.16.3
1537
+
1538
+ ### Patch Changes
1539
+
1540
+ - 0bf0934: Moved exposed `@pluv/io` version on the `PluvIO` instance as a property.
1541
+ - @pluv/crdt@0.16.3
1542
+ - @pluv/types@0.16.3
1543
+
1544
+ ## 0.16.2
1545
+
1546
+ ### Patch Changes
1547
+
1548
+ - 06f572d: Export the downloaded version of `@pluv/io`.
1549
+ - @pluv/crdt@0.16.2
1550
+ - @pluv/types@0.16.2
1551
+
1552
+ ## 0.16.1
1553
+
1554
+ ### Patch Changes
1555
+
1556
+ - cd05d96: Updated outdated README
1557
+ - @pluv/crdt@0.16.1
1558
+ - @pluv/types@0.16.1
1559
+
1560
+ ## 0.16.0
1561
+
1562
+ ### Minor Changes
1563
+
1564
+ - 4280220: ## Breaking Changes
1565
+
1566
+ - Storage types are now kept on the root of the document.
1567
+ - Previously, `@pluv/crdt-yjs` kept all shared-types on a hidden Yjs Map called `storage` on the root of the Yjs Doc. Now all shared-types are kept on the root of the Yjs Doc instead. This behavior should be more in-line with how shared-types are documented to be used from Yjs.
1568
+ - `@pluv/client` and `@pluv/react` no-longer re-export `@pluv/crdt-yjs`. This package will now need to be installed separately.
1569
+
1570
+ ```bash
1571
+ # if installing @pluv/client
1572
+ npm install @pluv/client @pluv/crdt-yjs
1573
+ # if installing @pluv/react
1574
+ npm install @pluv/react @pluv/crdt-yjs
1575
+ ```
1576
+
1577
+ ```ts
1578
+ // Before:
1579
+ import { createClient, y } from "@pluv/client";
1580
+ // After:
1581
+ import { createClient } from "@pluv/client";
1582
+ import { yjs } from "@pluv/crdt-yjs"; // y renamed to yjs
1583
+ ```
1584
+
1585
+ - The `y` import has been renamed to `yjs`.
1586
+ ```ts
1587
+ // Before:
1588
+ import { y } from "@pluv/crdt-yjs";
1589
+ // After:
1590
+ import { yjs } from "@pluv/crdt-yjs";
1591
+ ```
1592
+ - `@pluv/crdt-yjs` functions no-longer return Yjs shared-types directly, but instead return an `AbstractCrdtType` from `@pluv/crdt` (new package). This also affects methods that return storage shared types in both `@pluv/client` and `@pluv/react` from functions like `PluvRoom.getStorage` and `PluvRoom.useStorage`.
1593
+
1594
+ ```ts
1595
+ // Before:
1596
+ import { y } from "@pluv/crdt-yjs";
1597
+ import type { Array as YArray, Map as YMap } from "yjs";
1598
+
1599
+ const array: YArray<YMap<{ message: string }>> = y.array([y.object({ message: "Hello" })]);
1600
+
1601
+ array.push([y.object({ message: "World!" })]);
1602
+
1603
+ // After:
1604
+ import type { CrdtYjsArray, CrdtYjsObject } from "@pluv/crdt-yjs";
1605
+ import { yjs } from "@pluv/crdt-yjs";
1606
+ import type { Array as YArray } from "yjs";
1607
+
1608
+ const array: CrdtYjsArray<CrdtYjsObject<{ message: string }>> = yjs.array([
1609
+ yjs.object({ message: "Hello" }),
1610
+ ]);
1611
+
1612
+ array.push(yjs.object({ message: "World!" }));
1613
+
1614
+ // use .value to get the underlying yjs type
1615
+ const yarray: YArray<YMap<{ message: string }>> = array.value;
1616
+ ```
1617
+
1618
+ - `initialStorage` must now use the `doc` function from `@pluv/crdt-yjs` to be defined. This also affects `@pluv/react`.
1619
+
1620
+ ```ts
1621
+ // Before:
1622
+ import { createClient, y } from "@pluv/client";
1623
+
1624
+ const client = createClient({
1625
+ /* ... */
1626
+ });
1627
+
1628
+ client.createRoom({
1629
+ // ...
1630
+ initialStorage: () => ({
1631
+ messages: y.array([y.object({ message: "Hello world!" })]),
1632
+ }),
1633
+ });
1634
+
1635
+ // After:
1636
+ import { createClient } from "@pluv/client";
1637
+ // This is now imported separately
1638
+ import { yjs } from "@pluv/crdt-yjs";
1639
+
1640
+ const client = createClient({
1641
+ /* ... */
1642
+ });
1643
+
1644
+ client.createRoom({
1645
+ // ...
1646
+ initialStorage: yjs.doc(() => ({
1647
+ messages: yjs.array([yjs.object({ message: "Hello world!" })]),
1648
+ })),
1649
+ });
1650
+ ```
1651
+
1652
+ - `@pluv/client` can now instead use [loro](https://github.com/loro-dev/loro) instead of [yjs](https://github.com/yjs/yjs).
1653
+ ```bash
1654
+ npm install @pluv/client @pluv/crdt-loro loro-crdt
1655
+ ```
1656
+ - If you are using storage features with pluv, `@pluv/io` must now specify which crdt library (i.e. `@pluv/crdt-yjs` or `@pluv/crdt-loro`) it is meant to use.
1657
+
1658
+ ```ts
1659
+ import { loro } from "@pluv/crdt-loro";
1660
+ import { yjs } from "@pluv/crdt-yjs";
1661
+ import { createIO } from "@pluv/io";
1662
+
1663
+ const io = createIO({
1664
+ // ...
1665
+ // If using loro
1666
+ crdt: loro,
1667
+ // If using yjs
1668
+ crdt: yjs,
1669
+ });
1670
+ ```
1671
+
1672
+ - `PluvRoom.getDoc()` from `@pluv/client` no-longer returns the Yjs Doc instance, but rather a `AbstractCrdtDoc` instance from `@pluv/crdt`. This also affects the hook from `@pluv/react`.
1673
+
1674
+ ```ts
1675
+ // Before:
1676
+ import { Doc as YDoc } from "yjs";
1677
+
1678
+ const room: PluvRoom = client.createRoom({
1679
+ /* ... */
1680
+ });
1681
+
1682
+ const doc: YDoc = room.getDoc();
1683
+
1684
+ // After:
1685
+ import { CrdtYjsDoc } from "@pluv/crdt-yjs";
1686
+ import { Doc as YDoc } from "yjs";
1687
+
1688
+ const room: PluvRoom = client.createRoom({
1689
+ /* ... */
1690
+ });
1691
+
1692
+ const doc: CrdtYjsDoc<any> = room.getDoc();
1693
+ const ydoc: YDoc = doc.value;
1694
+ ```
1695
+
1696
+ - `@pluv/client` and `@pluv/react` now may return `null` when retrieving storage while storage is being initialized.
1697
+
1698
+ ```ts
1699
+ const sharedType = room.getStorage("messages"); // This may be null
1700
+
1701
+ const [data, sharedType] = useStorage("messages"); // data and sharedType may both be null
1702
+ ```
1703
+
1704
+ ### Patch Changes
1705
+
1706
+ - @pluv/crdt@0.16.0
1707
+ - @pluv/types@0.16.0
1708
+
1709
+ ## 0.15.0
1710
+
1711
+ ### Patch Changes
1712
+
1713
+ - @pluv/crdt-yjs@0.15.0
1714
+ - @pluv/types@0.15.0
1715
+
1716
+ ## 0.14.1
1717
+
1718
+ ### Patch Changes
1719
+
1720
+ - @pluv/crdt-yjs@0.14.1
1721
+ - @pluv/types@0.14.1
1722
+
1723
+ ## 0.14.0
1724
+
1725
+ ### Patch Changes
1726
+
1727
+ - @pluv/crdt-yjs@0.14.0
1728
+ - @pluv/types@0.14.0
1729
+
1730
+ ## 0.13.0
1731
+
1732
+ ### Patch Changes
1733
+
1734
+ - @pluv/crdt-yjs@0.13.0
1735
+ - @pluv/types@0.13.0
1736
+
1737
+ ## 0.12.3
1738
+
1739
+ ### Patch Changes
1740
+
1741
+ - da9f600: Upgraded dependencies
1742
+ - Updated dependencies [da9f600]
1743
+ - @pluv/crdt-yjs@0.12.3
1744
+ - @pluv/types@0.12.3
1745
+
1746
+ ## 0.12.2
1747
+
1748
+ ### Patch Changes
1749
+
1750
+ - 259a7da: Bumped dependencies
1751
+
1752
+ ## 0.12.1
1753
+
1754
+ ### Patch Changes
1755
+
1756
+ - @pluv/crdt-yjs@0.12.1
1757
+ - @pluv/types@0.12.1
1758
+
1759
+ ## 0.12.0
1760
+
1761
+ ### Patch Changes
1762
+
1763
+ - Updated dependencies [436040b]
1764
+ - @pluv/crdt-yjs@0.12.0
1765
+ - @pluv/types@0.12.0
1766
+
1767
+ ## 0.11.1
1768
+
1769
+ ### Patch Changes
1770
+
1771
+ - 74b3061: Bumped minor and patch dependencies.
1772
+ - Updated dependencies [74b3061]
1773
+ - @pluv/crdt-yjs@0.11.1
1774
+ - @pluv/types@0.11.1
1775
+
1776
+ ## 0.11.0
1777
+
1778
+ ### Minor Changes
1779
+
1780
+ - b538f5c: Exported class PluvIO from @pluv/io.
1781
+
1782
+ ### Patch Changes
1783
+
1784
+ - @pluv/crdt-yjs@0.11.0
1785
+ - @pluv/types@0.11.0
1786
+
1787
+ ## 0.10.3
1788
+
1789
+ ### Patch Changes
1790
+
1791
+ - a7d3ad1: Exposed context and getInitialProps from @pluv/io.
1792
+ - @pluv/crdt-yjs@0.10.3
1793
+ - @pluv/types@0.10.3
1794
+
1795
+ ## 0.10.2
1796
+
1797
+ ### Patch Changes
1798
+
1799
+ - 3deee13: Expose type AbstractPlatformConfig from @pluv/io.
1800
+ - @pluv/crdt-yjs@0.10.2
1801
+ - @pluv/types@0.10.2
1802
+
1803
+ ## 0.10.1
1804
+
1805
+ ### Patch Changes
1806
+
1807
+ - 0eeb67c: Passed through sessionId and userId into platform websockets.
1808
+ - 885835d: remove unnecessary dependency
1809
+ - Updated dependencies [885835d]
1810
+ - @pluv/crdt-yjs@0.10.1
1811
+ - @pluv/types@0.10.1
1812
+
1813
+ ## 0.10.0
1814
+
1815
+ ### Minor Changes
1816
+
1817
+ - f43f1cc: Change packages to all be versioned together for consistency.
1818
+
1819
+ ### Patch Changes
1820
+
1821
+ - Updated dependencies [f43f1cc]
1822
+ - @pluv/crdt-yjs@0.10.0
1823
+ - @pluv/types@0.10.0
1824
+
1825
+ ## 0.7.2
1826
+
1827
+ ### Patch Changes
1828
+
1829
+ - Updated dependencies [f4317ba]
1830
+ - @pluv/crdt-yjs@0.4.2
1831
+
1832
+ ## 0.7.1
1833
+
1834
+ ### Patch Changes
1835
+
1836
+ - 8fba48b: fix including incorrect dependency
1837
+ - 8997c65: bumped dependencies
1838
+ - Updated dependencies [8fba48b]
1839
+ - Updated dependencies [8997c65]
1840
+ - @pluv/crdt-yjs@0.4.1
1841
+ - @pluv/types@0.2.2
1842
+
1843
+ ## 0.7.0
1844
+
1845
+ ### Minor Changes
1846
+
1847
+ - 829d31b: Added support for defining persistant frontend storage for rooms via a new `addons` option on rooms.
1848
+
1849
+ This also introduces the first new addon `@pluv/addon-indexeddb`, which is more-or-less the equivalent to `y-indexeddb` which you can install like so:
1850
+
1851
+ ```
1852
+ npm install @pluv/addon-indexeddb
1853
+ ```
1854
+
1855
+ To use this new addon, simply pass it to options when creating a room:
1856
+
1857
+ ```ts
1858
+ import { addonIndexedDB } from "@pluv/addon-indexeddb";
1859
+ import { createClient } from "@pluv/client";
1860
+
1861
+ const client = createClient({
1862
+ // ...
1863
+ });
1864
+
1865
+ const room = client.createRoom("my-new-room", {
1866
+ addons: [
1867
+ // Define your addons in an array like so
1868
+ addonIndexedDB(),
1869
+ ],
1870
+ });
1871
+ ```
1872
+
1873
+ Or when using `@pluv/react`:
1874
+
1875
+ ```ts
1876
+ const PluvRoom = createRoomBundle({
1877
+ // ...
1878
+ addons: [
1879
+ // Define your addons in an array like so
1880
+ addonIndexedDB(),
1881
+ ],
1882
+ });
1883
+ ```
1884
+
1885
+ ### Patch Changes
1886
+
1887
+ - 8d11672: bumped dependencies to latest
1888
+ - Updated dependencies [8d11672]
1889
+ - Updated dependencies [829d31b]
1890
+ - @pluv/crdt-yjs@0.4.0
1891
+ - @pluv/types@0.2.1
1892
+
1893
+ ## 0.6.0
1894
+
1895
+ ### Minor Changes
1896
+
1897
+ - 2e7cbfa: Updated createIO config option `initialStorage` to be renamed to `getInitialStorage` and updated the params to use an object that includes platform parameters.
1898
+
1899
+ Previously:
1900
+
1901
+ ```ts
1902
+ createIO({
1903
+ initialStorage(room: string): Promise<string> => {
1904
+ // ...
1905
+ },
1906
+ });
1907
+ ```
1908
+
1909
+ Now:
1910
+
1911
+ ```ts
1912
+ createIO({
1913
+ platform: platformCloudflare<Env>(),
1914
+ getInitialStorage({
1915
+ // If you're using Cloudflare, this is the Cloudflare env parameter
1916
+ env,
1917
+ // The name of the room
1918
+ room,
1919
+ }): Promise<string> => {
1920
+ // ...
1921
+ },
1922
+ });
1923
+ ```
1924
+
1925
+ ## 0.5.0
1926
+
1927
+ ### Minor Changes
1928
+
1929
+ - ae4e1f1: added platform-specific contexts to expose env in cloudflare and req in node.js
1930
+
1931
+ ## 0.4.2
1932
+
1933
+ ### Patch Changes
1934
+
1935
+ - 8917309: fixed PluvIO listeners onRoomDeleted and onStorageUpdated not working when additional events were added
1936
+
1937
+ ## 0.4.1
1938
+
1939
+ ### Patch Changes
1940
+
1941
+ - b85a232: bumped dependencies
1942
+ - Updated dependencies [b85a232]
1943
+ - @pluv/crdt-yjs@0.3.8
1944
+ - @pluv/types@0.2.0
1945
+
1946
+ ## 0.4.0
1947
+
1948
+ ### Minor Changes
1949
+
1950
+ - bb2886b: allow sending multiple output types (broadcast, self, sync) per event
1951
+ - ae679a8: updated offline presence to be set when reconnecting to a room
1952
+
1953
+ ### Patch Changes
1954
+
1955
+ - 41943cf: bumped dependencies
1956
+ - 0dd847e: updated storage to be synced when reconnected to the room
1957
+ - 3518a83: bumped dependencies
1958
+ - Updated dependencies [0dd847e]
1959
+ - Updated dependencies [bb2886b]
1960
+ - Updated dependencies [ae679a8]
1961
+ - Updated dependencies [3518a83]
1962
+ - @pluv/crdt-yjs@0.3.7
1963
+ - @pluv/types@0.2.0
1964
+
1965
+ ## 0.3.9
1966
+
1967
+ ### Patch Changes
1968
+
1969
+ - abb3622: fixed @pluv/io yjs doc becoming unresponsive when the last user leaves on a cloudflare worker
1970
+
1971
+ ## 0.3.8
1972
+
1973
+ ### Patch Changes
1974
+
1975
+ - bcf1c3e: purge empty rooms before joining a new room
1976
+
1977
+ ## 0.3.7
1978
+
1979
+ ### Patch Changes
1980
+
1981
+ - ecc4040: added ability to set debug when room is created
1982
+
1983
+ ## 0.3.6
1984
+
1985
+ ### Patch Changes
1986
+
1987
+ - a7e2980: deleted links to docs that were removed
1988
+
1989
+ ## 0.3.5
1990
+
1991
+ ### Patch Changes
1992
+
1993
+ - 78fd644: updated readmes with links to the documentation website
1994
+ - Updated dependencies [78fd644]
1995
+ - @pluv/crdt-yjs@0.3.6
1996
+
1997
+ ## 0.3.4
1998
+
1999
+ ### Patch Changes
2000
+
2001
+ - 850626e: bumped dependencies
2002
+ - Updated dependencies [850626e]
2003
+ - @pluv/crdt-yjs@0.3.5
2004
+ - @pluv/types@0.1.6
2005
+
2006
+ ## 0.3.3
2007
+
2008
+ ### Patch Changes
2009
+
2010
+ - 77069a1: replaced chalk for kleur
2011
+ - @pluv/crdt-yjs@0.3.4
2012
+ - @pluv/types@0.1.5
2013
+
2014
+ ## 0.3.2
2015
+
2016
+ ### Patch Changes
2017
+
2018
+ - 9ae251d: bumped dependencies
2019
+ - Updated dependencies [9ae251d]
2020
+ - @pluv/crdt-yjs@0.3.4
2021
+
2022
+ ## 0.3.1
2023
+
2024
+ ### Patch Changes
2025
+
2026
+ - 74870ee: bumped dependencies
2027
+ - Updated dependencies [74870ee]
2028
+ - @pluv/crdt-yjs@0.3.3
2029
+ - @pluv/types@0.1.5
2030
+
2031
+ ## 0.3.0
2032
+
2033
+ ### Minor Changes
2034
+
2035
+ - c5567f1: renamed IORoom.room to IORoom.id
2036
+ - c5567f1: updated IORoom.broadcast to have the same function signature as PluvRoom.broadcast
2037
+
2038
+ ### Patch Changes
2039
+
2040
+ - @pluv/crdt-yjs@0.3.2
2041
+ - @pluv/types@0.1.4
2042
+
2043
+ ## 0.2.6
2044
+
2045
+ ### Patch Changes
2046
+
2047
+ - 9516a4e: updated typescript to 5.0
2048
+ - 7b6da1c: bumped dependencies
2049
+ - e9c1514: bumped dependencies
2050
+ - 9d1829c: chore: bumped dependencies
2051
+ - Updated dependencies [9516a4e]
2052
+ - Updated dependencies [7b6da1c]
2053
+ - Updated dependencies [e9c1514]
2054
+ - Updated dependencies [9d1829c]
2055
+ - @pluv/crdt-yjs@0.3.2
2056
+ - @pluv/types@0.1.4
2057
+
2058
+ ## 0.2.5
2059
+
2060
+ ### Patch Changes
2061
+
2062
+ - 161e00e: fixed links to other pluv packages in readmes
2063
+ - f6c0e65: bumped dependencies
2064
+ - Updated dependencies [161e00e]
2065
+ - Updated dependencies [f6c0e65]
2066
+ - @pluv/crdt-yjs@0.3.1
2067
+ - @pluv/types@0.1.3
2068
+
2069
+ ## 0.2.4
2070
+
2071
+ ### Patch Changes
2072
+
2073
+ - 8bf62cb: bumped dependencies
2074
+ - 7e52685: Bumped dependencies
2075
+ - 3b7b17a: docs: corrected readme typos
2076
+ - b1cb325: Updated dependencies
2077
+ - 8e97fb2: Updated dependencies
2078
+ - Updated dependencies [8bf62cb]
2079
+ - Updated dependencies [7e52685]
2080
+ - Updated dependencies [b1cb325]
2081
+ - Updated dependencies [327a6ef]
2082
+ - Updated dependencies [8e97fb2]
2083
+ - @pluv/crdt-yjs@0.3.0
2084
+ - @pluv/types@0.1.3
2085
+
2086
+ ## 0.2.3
2087
+
2088
+ ### Patch Changes
2089
+
2090
+ - 95b5ef8: breaking: update PluvRoom.broadcast api
2091
+ - e23fbbe: update demo gif in README
2092
+ - Updated dependencies [6858682]
2093
+ - @pluv/crdt-yjs@0.2.0
2094
+ - @pluv/types@0.1.2
2095
+
2096
+ ## 0.2.2
2097
+
2098
+ ### Patch Changes
2099
+
2100
+ - fe80d7b: added preview disclaimer about breaking changes in the readme
2101
+ - Updated dependencies [fe80d7b]
2102
+ - @pluv/crdt-yjs@0.1.3
2103
+ - @pluv/types@0.1.2
2104
+
2105
+ ## 0.2.1
2106
+
2107
+ ### Patch Changes
2108
+
2109
+ - b45d642: Fixed links on README
2110
+ - 203dfee: Updated README
2111
+ - Updated dependencies [b45d642]
2112
+ - @pluv/crdt-yjs@0.1.2
2113
+
2114
+ ## 0.2.0
2115
+
2116
+ ### Minor Changes
2117
+
2118
+ - 23a7382: Added `initialStorage` param to `createIO` to set initialStorage state of room.
2119
+ - 39271d4: Added support for IORoom listeners to get current storage state.
2120
+
2121
+ ### Patch Changes
2122
+
2123
+ - 24016e6: Updated dependencies
2124
+ - Updated dependencies [24016e6]
2125
+ - @pluv/crdt-yjs@0.1.1
2126
+ - @pluv/types@0.1.1
2127
+
2128
+ ## 0.1.0
2129
+
2130
+ ### Minor Changes
2131
+
2132
+ - a22f525: Added documentation
2133
+
2134
+ ### Patch Changes
2135
+
2136
+ - Updated dependencies [a22f525]
2137
+ - @pluv/crdt-yjs@0.1.0
2138
+ - @pluv/types@0.1.0