@pluv/io 2.2.1 → 2.2.3

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