@pluv/io 2.2.1 → 2.2.2

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