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