@liveblocks/core 1.1.3 → 1.1.4-internal1

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/dist/index.d.mts CHANGED
@@ -669,6 +669,212 @@ declare type Delegates<T extends BaseAuthResult> = {
669
669
  createSocket: (token: T) => IWebSocketInstance;
670
670
  };
671
671
 
672
+ declare type IdTuple<T> = [id: string, value: T];
673
+ declare enum CrdtType {
674
+ OBJECT = 0,
675
+ LIST = 1,
676
+ MAP = 2,
677
+ REGISTER = 3
678
+ }
679
+ declare type SerializedCrdt = SerializedRootObject | SerializedChild;
680
+ declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
681
+ declare type SerializedRootObject = {
682
+ readonly type: CrdtType.OBJECT;
683
+ readonly data: JsonObject;
684
+ readonly parentId?: never;
685
+ readonly parentKey?: never;
686
+ };
687
+ declare type SerializedObject = {
688
+ readonly type: CrdtType.OBJECT;
689
+ readonly parentId: string;
690
+ readonly parentKey: string;
691
+ readonly data: JsonObject;
692
+ };
693
+ declare type SerializedList = {
694
+ readonly type: CrdtType.LIST;
695
+ readonly parentId: string;
696
+ readonly parentKey: string;
697
+ };
698
+ declare type SerializedMap = {
699
+ readonly type: CrdtType.MAP;
700
+ readonly parentId: string;
701
+ readonly parentKey: string;
702
+ };
703
+ declare type SerializedRegister = {
704
+ readonly type: CrdtType.REGISTER;
705
+ readonly parentId: string;
706
+ readonly parentKey: string;
707
+ readonly data: Json;
708
+ };
709
+ declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
710
+ declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
711
+
712
+ declare enum ServerMsgCode {
713
+ UPDATE_PRESENCE = 100,
714
+ USER_JOINED = 101,
715
+ USER_LEFT = 102,
716
+ BROADCASTED_EVENT = 103,
717
+ ROOM_STATE = 104,
718
+ INITIAL_STORAGE_STATE = 200,
719
+ UPDATE_STORAGE = 201,
720
+ REJECT_STORAGE_OP = 299,
721
+ UPDATE_YDOC = 300
722
+ }
723
+ /**
724
+ * Messages that can be sent from the server to the client.
725
+ */
726
+ declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg | RejectedStorageOpServerMsg | YDocUpdate;
727
+ /**
728
+ * Sent by the WebSocket server and broadcasted to all clients to announce that
729
+ * a User updated their presence. For example, when a user moves their cursor.
730
+ *
731
+ * In most cases, the data payload will only include the fields from the
732
+ * Presence that have been changed since the last announcement. However, after
733
+ * a new user joins a room, a "full presence" will be announced so the newly
734
+ * connected user will get each other's user full presence at least once. In
735
+ * those cases, the `targetActor` field indicates the newly connected client,
736
+ * so all other existing clients can ignore this broadcasted message.
737
+ */
738
+ declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
739
+ readonly type: ServerMsgCode.UPDATE_PRESENCE;
740
+ /**
741
+ * The User whose Presence has changed.
742
+ */
743
+ readonly actor: number;
744
+ /**
745
+ * When set, signifies that this is a Full Presence™ update, not a patch.
746
+ *
747
+ * The numeric value itself no longer has specific meaning. Historically,
748
+ * this field was intended so that clients could ignore these broadcasted
749
+ * full presence messages, but it turned out that getting a full presence
750
+ * "keyframe" from time to time was useful.
751
+ *
752
+ * So nowadays, the presence (pun intended) of this `targetActor` field
753
+ * is a backward-compatible way of expressing that the `data` contains
754
+ * all presence fields, and isn't a partial "patch".
755
+ */
756
+ readonly targetActor: number;
757
+ /**
758
+ * The partial or full Presence of a User. If the `targetActor` field is set,
759
+ * this will be the full Presence, otherwise it only contain the fields that
760
+ * have changed since the last broadcast.
761
+ */
762
+ readonly data: TPresence;
763
+ } | {
764
+ readonly type: ServerMsgCode.UPDATE_PRESENCE;
765
+ /**
766
+ * The User whose Presence has changed.
767
+ */
768
+ readonly actor: number;
769
+ /**
770
+ * Not set for partial presence updates.
771
+ */
772
+ readonly targetActor?: undefined;
773
+ /**
774
+ * A partial Presence patch to apply to the User. It will only contain the
775
+ * fields that have changed since the last broadcast.
776
+ */
777
+ readonly data: Partial<TPresence>;
778
+ };
779
+ /**
780
+ * Sent by the WebSocket server and broadcasted to all clients to announce that
781
+ * a new User has joined the Room.
782
+ */
783
+ declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
784
+ readonly type: ServerMsgCode.USER_JOINED;
785
+ readonly actor: number;
786
+ /**
787
+ * The id of the User that has been set in the authentication endpoint.
788
+ * Useful to get additional information about the connected user.
789
+ */
790
+ readonly id: TUserMeta["id"];
791
+ /**
792
+ * Additional user information that has been set in the authentication
793
+ * endpoint.
794
+ */
795
+ readonly info: TUserMeta["info"];
796
+ /**
797
+ * Permissions that the user has in the Room.
798
+ */
799
+ readonly scopes: string[];
800
+ };
801
+ /**
802
+ * Sent by the WebSocket server and broadcasted to all clients to announce that
803
+ * a new User has left the Room.
804
+ */
805
+ declare type UserLeftServerMsg = {
806
+ readonly type: ServerMsgCode.USER_LEFT;
807
+ readonly actor: number;
808
+ };
809
+ /**
810
+ * Sent by the WebSocket server when the ydoc is updated or when requested based on stateVector passed.
811
+ * Contains a base64 encoded update
812
+ */
813
+ declare type YDocUpdate = {
814
+ readonly type: ServerMsgCode.UPDATE_YDOC;
815
+ readonly update: string;
816
+ readonly isSync: boolean;
817
+ };
818
+ /**
819
+ * Sent by the WebSocket server and broadcasted to all clients to announce that
820
+ * a User broadcasted an Event to everyone in the Room.
821
+ */
822
+ declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
823
+ readonly type: ServerMsgCode.BROADCASTED_EVENT;
824
+ /**
825
+ * The User who broadcasted the Event.
826
+ */
827
+ readonly actor: number;
828
+ /**
829
+ * The arbitrary payload of the Event. This can be any JSON value. Clients
830
+ * will have to manually verify/decode this event.
831
+ */
832
+ readonly event: TRoomEvent;
833
+ };
834
+ /**
835
+ * Sent by the WebSocket server to a single client in response to the client
836
+ * joining the Room, to provide the initial state of the Room. The payload
837
+ * includes a list of all other Users that already are in the Room.
838
+ */
839
+ declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
840
+ readonly type: ServerMsgCode.ROOM_STATE;
841
+ readonly users: {
842
+ readonly [actor: number]: TUserMeta & {
843
+ scopes: string[];
844
+ };
845
+ };
846
+ };
847
+ /**
848
+ * Sent by the WebSocket server to a single client in response to the client
849
+ * joining the Room, to provide the initial Storage state of the Room. The
850
+ * payload includes the entire Storage document.
851
+ */
852
+ declare type InitialDocumentStateServerMsg = {
853
+ readonly type: ServerMsgCode.INITIAL_STORAGE_STATE;
854
+ readonly items: IdTuple<SerializedCrdt>[];
855
+ };
856
+ /**
857
+ * Sent by the WebSocket server and broadcasted to all clients to announce that
858
+ * a change occurred in the Storage document.
859
+ *
860
+ * The payload of this message contains a list of Ops (aka incremental
861
+ * mutations to make to the initially loaded document).
862
+ */
863
+ declare type UpdateStorageServerMsg = {
864
+ readonly type: ServerMsgCode.UPDATE_STORAGE;
865
+ readonly ops: Op[];
866
+ };
867
+ /**
868
+ * Sent by the WebSocket server to the client to indicate that certain opIds
869
+ * have been received but were rejected because they caused mutations that are
870
+ * incompatible with the Room's schema.
871
+ */
872
+ declare type RejectedStorageOpServerMsg = {
873
+ readonly type: ServerMsgCode.REJECT_STORAGE_OP;
874
+ readonly opIds: string[];
875
+ readonly reason: string;
876
+ };
877
+
672
878
  declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
673
879
  /**
674
880
  * @deprecated Prefer the normal .length property on arrays.
@@ -1120,7 +1326,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1120
1326
  */
1121
1327
  readonly storageDidLoad: Observable<void>;
1122
1328
  readonly storageStatus: Observable<StorageStatus>;
1123
- readonly ydoc: Observable<string>;
1329
+ readonly ydoc: Observable<YDocUpdate>;
1124
1330
  };
1125
1331
  /**
1126
1332
  * Batches modifications made during the given function.
@@ -1497,211 +1703,6 @@ declare type UpdateYDocClientMsg = {
1497
1703
  readonly update: string;
1498
1704
  };
1499
1705
 
1500
- declare type IdTuple<T> = [id: string, value: T];
1501
- declare enum CrdtType {
1502
- OBJECT = 0,
1503
- LIST = 1,
1504
- MAP = 2,
1505
- REGISTER = 3
1506
- }
1507
- declare type SerializedCrdt = SerializedRootObject | SerializedChild;
1508
- declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
1509
- declare type SerializedRootObject = {
1510
- readonly type: CrdtType.OBJECT;
1511
- readonly data: JsonObject;
1512
- readonly parentId?: never;
1513
- readonly parentKey?: never;
1514
- };
1515
- declare type SerializedObject = {
1516
- readonly type: CrdtType.OBJECT;
1517
- readonly parentId: string;
1518
- readonly parentKey: string;
1519
- readonly data: JsonObject;
1520
- };
1521
- declare type SerializedList = {
1522
- readonly type: CrdtType.LIST;
1523
- readonly parentId: string;
1524
- readonly parentKey: string;
1525
- };
1526
- declare type SerializedMap = {
1527
- readonly type: CrdtType.MAP;
1528
- readonly parentId: string;
1529
- readonly parentKey: string;
1530
- };
1531
- declare type SerializedRegister = {
1532
- readonly type: CrdtType.REGISTER;
1533
- readonly parentId: string;
1534
- readonly parentKey: string;
1535
- readonly data: Json;
1536
- };
1537
- declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
1538
- declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
1539
-
1540
- declare enum ServerMsgCode {
1541
- UPDATE_PRESENCE = 100,
1542
- USER_JOINED = 101,
1543
- USER_LEFT = 102,
1544
- BROADCASTED_EVENT = 103,
1545
- ROOM_STATE = 104,
1546
- INITIAL_STORAGE_STATE = 200,
1547
- UPDATE_STORAGE = 201,
1548
- REJECT_STORAGE_OP = 299,
1549
- UPDATE_YDOC = 300
1550
- }
1551
- /**
1552
- * Messages that can be sent from the server to the client.
1553
- */
1554
- declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg | RejectedStorageOpServerMsg | YDocUpdate;
1555
- /**
1556
- * Sent by the WebSocket server and broadcasted to all clients to announce that
1557
- * a User updated their presence. For example, when a user moves their cursor.
1558
- *
1559
- * In most cases, the data payload will only include the fields from the
1560
- * Presence that have been changed since the last announcement. However, after
1561
- * a new user joins a room, a "full presence" will be announced so the newly
1562
- * connected user will get each other's user full presence at least once. In
1563
- * those cases, the `targetActor` field indicates the newly connected client,
1564
- * so all other existing clients can ignore this broadcasted message.
1565
- */
1566
- declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
1567
- readonly type: ServerMsgCode.UPDATE_PRESENCE;
1568
- /**
1569
- * The User whose Presence has changed.
1570
- */
1571
- readonly actor: number;
1572
- /**
1573
- * When set, signifies that this is a Full Presence™ update, not a patch.
1574
- *
1575
- * The numeric value itself no longer has specific meaning. Historically,
1576
- * this field was intended so that clients could ignore these broadcasted
1577
- * full presence messages, but it turned out that getting a full presence
1578
- * "keyframe" from time to time was useful.
1579
- *
1580
- * So nowadays, the presence (pun intended) of this `targetActor` field
1581
- * is a backward-compatible way of expressing that the `data` contains
1582
- * all presence fields, and isn't a partial "patch".
1583
- */
1584
- readonly targetActor: number;
1585
- /**
1586
- * The partial or full Presence of a User. If the `targetActor` field is set,
1587
- * this will be the full Presence, otherwise it only contain the fields that
1588
- * have changed since the last broadcast.
1589
- */
1590
- readonly data: TPresence;
1591
- } | {
1592
- readonly type: ServerMsgCode.UPDATE_PRESENCE;
1593
- /**
1594
- * The User whose Presence has changed.
1595
- */
1596
- readonly actor: number;
1597
- /**
1598
- * Not set for partial presence updates.
1599
- */
1600
- readonly targetActor?: undefined;
1601
- /**
1602
- * A partial Presence patch to apply to the User. It will only contain the
1603
- * fields that have changed since the last broadcast.
1604
- */
1605
- readonly data: Partial<TPresence>;
1606
- };
1607
- /**
1608
- * Sent by the WebSocket server and broadcasted to all clients to announce that
1609
- * a new User has joined the Room.
1610
- */
1611
- declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
1612
- readonly type: ServerMsgCode.USER_JOINED;
1613
- readonly actor: number;
1614
- /**
1615
- * The id of the User that has been set in the authentication endpoint.
1616
- * Useful to get additional information about the connected user.
1617
- */
1618
- readonly id: TUserMeta["id"];
1619
- /**
1620
- * Additional user information that has been set in the authentication
1621
- * endpoint.
1622
- */
1623
- readonly info: TUserMeta["info"];
1624
- /**
1625
- * Permissions that the user has in the Room.
1626
- */
1627
- readonly scopes: string[];
1628
- };
1629
- /**
1630
- * Sent by the WebSocket server and broadcasted to all clients to announce that
1631
- * a new User has left the Room.
1632
- */
1633
- declare type UserLeftServerMsg = {
1634
- readonly type: ServerMsgCode.USER_LEFT;
1635
- readonly actor: number;
1636
- };
1637
- /**
1638
- * Sent by the WebSocket server when the ydoc is updated or when requested based on stateVector passed.
1639
- * Contains a base64 encoded update
1640
- */
1641
- declare type YDocUpdate = {
1642
- readonly type: ServerMsgCode.UPDATE_YDOC;
1643
- readonly update: string;
1644
- };
1645
- /**
1646
- * Sent by the WebSocket server and broadcasted to all clients to announce that
1647
- * a User broadcasted an Event to everyone in the Room.
1648
- */
1649
- declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
1650
- readonly type: ServerMsgCode.BROADCASTED_EVENT;
1651
- /**
1652
- * The User who broadcasted the Event.
1653
- */
1654
- readonly actor: number;
1655
- /**
1656
- * The arbitrary payload of the Event. This can be any JSON value. Clients
1657
- * will have to manually verify/decode this event.
1658
- */
1659
- readonly event: TRoomEvent;
1660
- };
1661
- /**
1662
- * Sent by the WebSocket server to a single client in response to the client
1663
- * joining the Room, to provide the initial state of the Room. The payload
1664
- * includes a list of all other Users that already are in the Room.
1665
- */
1666
- declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
1667
- readonly type: ServerMsgCode.ROOM_STATE;
1668
- readonly users: {
1669
- readonly [actor: number]: TUserMeta & {
1670
- scopes: string[];
1671
- };
1672
- };
1673
- };
1674
- /**
1675
- * Sent by the WebSocket server to a single client in response to the client
1676
- * joining the Room, to provide the initial Storage state of the Room. The
1677
- * payload includes the entire Storage document.
1678
- */
1679
- declare type InitialDocumentStateServerMsg = {
1680
- readonly type: ServerMsgCode.INITIAL_STORAGE_STATE;
1681
- readonly items: IdTuple<SerializedCrdt>[];
1682
- };
1683
- /**
1684
- * Sent by the WebSocket server and broadcasted to all clients to announce that
1685
- * a change occurred in the Storage document.
1686
- *
1687
- * The payload of this message contains a list of Ops (aka incremental
1688
- * mutations to make to the initially loaded document).
1689
- */
1690
- declare type UpdateStorageServerMsg = {
1691
- readonly type: ServerMsgCode.UPDATE_STORAGE;
1692
- readonly ops: Op[];
1693
- };
1694
- /**
1695
- * Sent by the WebSocket server to the client to indicate that certain opIds
1696
- * have been received but were rejected because they caused mutations that are
1697
- * incompatible with the Room's schema.
1698
- */
1699
- declare type RejectedStorageOpServerMsg = {
1700
- readonly type: ServerMsgCode.REJECT_STORAGE_OP;
1701
- readonly opIds: string[];
1702
- readonly reason: string;
1703
- };
1704
-
1705
1706
  /**
1706
1707
  * Lookup table for nodes (= SerializedCrdt values) by their IDs.
1707
1708
  */