@liveblocks/core 1.1.6 → 1.1.7
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 +223 -208
- package/dist/index.d.ts +223 -208
- package/dist/index.js +43 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -676,6 +676,212 @@ declare type Delegates<T extends BaseAuthResult> = {
|
|
|
676
676
|
createSocket: (token: T) => IWebSocketInstance;
|
|
677
677
|
};
|
|
678
678
|
|
|
679
|
+
declare type IdTuple<T> = [id: string, value: T];
|
|
680
|
+
declare enum CrdtType {
|
|
681
|
+
OBJECT = 0,
|
|
682
|
+
LIST = 1,
|
|
683
|
+
MAP = 2,
|
|
684
|
+
REGISTER = 3
|
|
685
|
+
}
|
|
686
|
+
declare type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
687
|
+
declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
|
|
688
|
+
declare type SerializedRootObject = {
|
|
689
|
+
readonly type: CrdtType.OBJECT;
|
|
690
|
+
readonly data: JsonObject;
|
|
691
|
+
readonly parentId?: never;
|
|
692
|
+
readonly parentKey?: never;
|
|
693
|
+
};
|
|
694
|
+
declare type SerializedObject = {
|
|
695
|
+
readonly type: CrdtType.OBJECT;
|
|
696
|
+
readonly parentId: string;
|
|
697
|
+
readonly parentKey: string;
|
|
698
|
+
readonly data: JsonObject;
|
|
699
|
+
};
|
|
700
|
+
declare type SerializedList = {
|
|
701
|
+
readonly type: CrdtType.LIST;
|
|
702
|
+
readonly parentId: string;
|
|
703
|
+
readonly parentKey: string;
|
|
704
|
+
};
|
|
705
|
+
declare type SerializedMap = {
|
|
706
|
+
readonly type: CrdtType.MAP;
|
|
707
|
+
readonly parentId: string;
|
|
708
|
+
readonly parentKey: string;
|
|
709
|
+
};
|
|
710
|
+
declare type SerializedRegister = {
|
|
711
|
+
readonly type: CrdtType.REGISTER;
|
|
712
|
+
readonly parentId: string;
|
|
713
|
+
readonly parentKey: string;
|
|
714
|
+
readonly data: Json;
|
|
715
|
+
};
|
|
716
|
+
declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
|
|
717
|
+
declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
|
|
718
|
+
|
|
719
|
+
declare enum ServerMsgCode {
|
|
720
|
+
UPDATE_PRESENCE = 100,
|
|
721
|
+
USER_JOINED = 101,
|
|
722
|
+
USER_LEFT = 102,
|
|
723
|
+
BROADCASTED_EVENT = 103,
|
|
724
|
+
ROOM_STATE = 104,
|
|
725
|
+
INITIAL_STORAGE_STATE = 200,
|
|
726
|
+
UPDATE_STORAGE = 201,
|
|
727
|
+
REJECT_STORAGE_OP = 299,
|
|
728
|
+
UPDATE_YDOC = 300
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Messages that can be sent from the server to the client.
|
|
732
|
+
*/
|
|
733
|
+
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;
|
|
734
|
+
/**
|
|
735
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
736
|
+
* a User updated their presence. For example, when a user moves their cursor.
|
|
737
|
+
*
|
|
738
|
+
* In most cases, the data payload will only include the fields from the
|
|
739
|
+
* Presence that have been changed since the last announcement. However, after
|
|
740
|
+
* a new user joins a room, a "full presence" will be announced so the newly
|
|
741
|
+
* connected user will get each other's user full presence at least once. In
|
|
742
|
+
* those cases, the `targetActor` field indicates the newly connected client,
|
|
743
|
+
* so all other existing clients can ignore this broadcasted message.
|
|
744
|
+
*/
|
|
745
|
+
declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
|
|
746
|
+
readonly type: ServerMsgCode.UPDATE_PRESENCE;
|
|
747
|
+
/**
|
|
748
|
+
* The User whose Presence has changed.
|
|
749
|
+
*/
|
|
750
|
+
readonly actor: number;
|
|
751
|
+
/**
|
|
752
|
+
* When set, signifies that this is a Full Presence™ update, not a patch.
|
|
753
|
+
*
|
|
754
|
+
* The numeric value itself no longer has specific meaning. Historically,
|
|
755
|
+
* this field was intended so that clients could ignore these broadcasted
|
|
756
|
+
* full presence messages, but it turned out that getting a full presence
|
|
757
|
+
* "keyframe" from time to time was useful.
|
|
758
|
+
*
|
|
759
|
+
* So nowadays, the presence (pun intended) of this `targetActor` field
|
|
760
|
+
* is a backward-compatible way of expressing that the `data` contains
|
|
761
|
+
* all presence fields, and isn't a partial "patch".
|
|
762
|
+
*/
|
|
763
|
+
readonly targetActor: number;
|
|
764
|
+
/**
|
|
765
|
+
* The partial or full Presence of a User. If the `targetActor` field is set,
|
|
766
|
+
* this will be the full Presence, otherwise it only contain the fields that
|
|
767
|
+
* have changed since the last broadcast.
|
|
768
|
+
*/
|
|
769
|
+
readonly data: TPresence;
|
|
770
|
+
} | {
|
|
771
|
+
readonly type: ServerMsgCode.UPDATE_PRESENCE;
|
|
772
|
+
/**
|
|
773
|
+
* The User whose Presence has changed.
|
|
774
|
+
*/
|
|
775
|
+
readonly actor: number;
|
|
776
|
+
/**
|
|
777
|
+
* Not set for partial presence updates.
|
|
778
|
+
*/
|
|
779
|
+
readonly targetActor?: undefined;
|
|
780
|
+
/**
|
|
781
|
+
* A partial Presence patch to apply to the User. It will only contain the
|
|
782
|
+
* fields that have changed since the last broadcast.
|
|
783
|
+
*/
|
|
784
|
+
readonly data: Partial<TPresence>;
|
|
785
|
+
};
|
|
786
|
+
/**
|
|
787
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
788
|
+
* a new User has joined the Room.
|
|
789
|
+
*/
|
|
790
|
+
declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
791
|
+
readonly type: ServerMsgCode.USER_JOINED;
|
|
792
|
+
readonly actor: number;
|
|
793
|
+
/**
|
|
794
|
+
* The id of the User that has been set in the authentication endpoint.
|
|
795
|
+
* Useful to get additional information about the connected user.
|
|
796
|
+
*/
|
|
797
|
+
readonly id: TUserMeta["id"];
|
|
798
|
+
/**
|
|
799
|
+
* Additional user information that has been set in the authentication
|
|
800
|
+
* endpoint.
|
|
801
|
+
*/
|
|
802
|
+
readonly info: TUserMeta["info"];
|
|
803
|
+
/**
|
|
804
|
+
* Permissions that the user has in the Room.
|
|
805
|
+
*/
|
|
806
|
+
readonly scopes: string[];
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
810
|
+
* a new User has left the Room.
|
|
811
|
+
*/
|
|
812
|
+
declare type UserLeftServerMsg = {
|
|
813
|
+
readonly type: ServerMsgCode.USER_LEFT;
|
|
814
|
+
readonly actor: number;
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Sent by the WebSocket server when the ydoc is updated or when requested based on stateVector passed.
|
|
818
|
+
* Contains a base64 encoded update
|
|
819
|
+
*/
|
|
820
|
+
declare type YDocUpdate = {
|
|
821
|
+
readonly type: ServerMsgCode.UPDATE_YDOC;
|
|
822
|
+
readonly update: string;
|
|
823
|
+
readonly isSync: boolean;
|
|
824
|
+
};
|
|
825
|
+
/**
|
|
826
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
827
|
+
* a User broadcasted an Event to everyone in the Room.
|
|
828
|
+
*/
|
|
829
|
+
declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
|
|
830
|
+
readonly type: ServerMsgCode.BROADCASTED_EVENT;
|
|
831
|
+
/**
|
|
832
|
+
* The User who broadcasted the Event.
|
|
833
|
+
*/
|
|
834
|
+
readonly actor: number;
|
|
835
|
+
/**
|
|
836
|
+
* The arbitrary payload of the Event. This can be any JSON value. Clients
|
|
837
|
+
* will have to manually verify/decode this event.
|
|
838
|
+
*/
|
|
839
|
+
readonly event: TRoomEvent;
|
|
840
|
+
};
|
|
841
|
+
/**
|
|
842
|
+
* Sent by the WebSocket server to a single client in response to the client
|
|
843
|
+
* joining the Room, to provide the initial state of the Room. The payload
|
|
844
|
+
* includes a list of all other Users that already are in the Room.
|
|
845
|
+
*/
|
|
846
|
+
declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
847
|
+
readonly type: ServerMsgCode.ROOM_STATE;
|
|
848
|
+
readonly users: {
|
|
849
|
+
readonly [actor: number]: TUserMeta & {
|
|
850
|
+
scopes: string[];
|
|
851
|
+
};
|
|
852
|
+
};
|
|
853
|
+
};
|
|
854
|
+
/**
|
|
855
|
+
* Sent by the WebSocket server to a single client in response to the client
|
|
856
|
+
* joining the Room, to provide the initial Storage state of the Room. The
|
|
857
|
+
* payload includes the entire Storage document.
|
|
858
|
+
*/
|
|
859
|
+
declare type InitialDocumentStateServerMsg = {
|
|
860
|
+
readonly type: ServerMsgCode.INITIAL_STORAGE_STATE;
|
|
861
|
+
readonly items: IdTuple<SerializedCrdt>[];
|
|
862
|
+
};
|
|
863
|
+
/**
|
|
864
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
865
|
+
* a change occurred in the Storage document.
|
|
866
|
+
*
|
|
867
|
+
* The payload of this message contains a list of Ops (aka incremental
|
|
868
|
+
* mutations to make to the initially loaded document).
|
|
869
|
+
*/
|
|
870
|
+
declare type UpdateStorageServerMsg = {
|
|
871
|
+
readonly type: ServerMsgCode.UPDATE_STORAGE;
|
|
872
|
+
readonly ops: Op[];
|
|
873
|
+
};
|
|
874
|
+
/**
|
|
875
|
+
* Sent by the WebSocket server to the client to indicate that certain opIds
|
|
876
|
+
* have been received but were rejected because they caused mutations that are
|
|
877
|
+
* incompatible with the Room's schema.
|
|
878
|
+
*/
|
|
879
|
+
declare type RejectedStorageOpServerMsg = {
|
|
880
|
+
readonly type: ServerMsgCode.REJECT_STORAGE_OP;
|
|
881
|
+
readonly opIds: string[];
|
|
882
|
+
readonly reason: string;
|
|
883
|
+
};
|
|
884
|
+
|
|
679
885
|
declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
|
|
680
886
|
/**
|
|
681
887
|
* @deprecated Prefer the normal .length property on arrays.
|
|
@@ -1112,7 +1318,8 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1112
1318
|
connectionId: number;
|
|
1113
1319
|
event: TRoomEvent;
|
|
1114
1320
|
}>;
|
|
1115
|
-
readonly
|
|
1321
|
+
readonly self: Observable<User<TPresence, TUserMeta>>;
|
|
1322
|
+
readonly myPresence: Observable<TPresence>;
|
|
1116
1323
|
readonly others: Observable<{
|
|
1117
1324
|
others: Others<TPresence, TUserMeta>;
|
|
1118
1325
|
event: OthersEvent<TPresence, TUserMeta>;
|
|
@@ -1127,7 +1334,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1127
1334
|
*/
|
|
1128
1335
|
readonly storageDidLoad: Observable<void>;
|
|
1129
1336
|
readonly storageStatus: Observable<StorageStatus>;
|
|
1130
|
-
readonly ydoc: Observable<
|
|
1337
|
+
readonly ydoc: Observable<YDocUpdate>;
|
|
1131
1338
|
};
|
|
1132
1339
|
/**
|
|
1133
1340
|
* Batches modifications made during the given function.
|
|
@@ -1446,6 +1653,19 @@ declare function asPos(str: string): Pos;
|
|
|
1446
1653
|
*/
|
|
1447
1654
|
declare function shallow(a: unknown, b: unknown): boolean;
|
|
1448
1655
|
|
|
1656
|
+
declare type CustomAuthenticationResult = {
|
|
1657
|
+
token: string;
|
|
1658
|
+
error?: never;
|
|
1659
|
+
} | {
|
|
1660
|
+
token?: never;
|
|
1661
|
+
error: "forbidden";
|
|
1662
|
+
reason: string;
|
|
1663
|
+
} | {
|
|
1664
|
+
token?: never;
|
|
1665
|
+
error: string;
|
|
1666
|
+
reason: string;
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1449
1669
|
declare enum ClientMsgCode {
|
|
1450
1670
|
UPDATE_PRESENCE = 100,
|
|
1451
1671
|
BROADCAST_EVENT = 103,
|
|
@@ -1504,211 +1724,6 @@ declare type UpdateYDocClientMsg = {
|
|
|
1504
1724
|
readonly update: string;
|
|
1505
1725
|
};
|
|
1506
1726
|
|
|
1507
|
-
declare type IdTuple<T> = [id: string, value: T];
|
|
1508
|
-
declare enum CrdtType {
|
|
1509
|
-
OBJECT = 0,
|
|
1510
|
-
LIST = 1,
|
|
1511
|
-
MAP = 2,
|
|
1512
|
-
REGISTER = 3
|
|
1513
|
-
}
|
|
1514
|
-
declare type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
1515
|
-
declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
|
|
1516
|
-
declare type SerializedRootObject = {
|
|
1517
|
-
readonly type: CrdtType.OBJECT;
|
|
1518
|
-
readonly data: JsonObject;
|
|
1519
|
-
readonly parentId?: never;
|
|
1520
|
-
readonly parentKey?: never;
|
|
1521
|
-
};
|
|
1522
|
-
declare type SerializedObject = {
|
|
1523
|
-
readonly type: CrdtType.OBJECT;
|
|
1524
|
-
readonly parentId: string;
|
|
1525
|
-
readonly parentKey: string;
|
|
1526
|
-
readonly data: JsonObject;
|
|
1527
|
-
};
|
|
1528
|
-
declare type SerializedList = {
|
|
1529
|
-
readonly type: CrdtType.LIST;
|
|
1530
|
-
readonly parentId: string;
|
|
1531
|
-
readonly parentKey: string;
|
|
1532
|
-
};
|
|
1533
|
-
declare type SerializedMap = {
|
|
1534
|
-
readonly type: CrdtType.MAP;
|
|
1535
|
-
readonly parentId: string;
|
|
1536
|
-
readonly parentKey: string;
|
|
1537
|
-
};
|
|
1538
|
-
declare type SerializedRegister = {
|
|
1539
|
-
readonly type: CrdtType.REGISTER;
|
|
1540
|
-
readonly parentId: string;
|
|
1541
|
-
readonly parentKey: string;
|
|
1542
|
-
readonly data: Json;
|
|
1543
|
-
};
|
|
1544
|
-
declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
|
|
1545
|
-
declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
|
|
1546
|
-
|
|
1547
|
-
declare enum ServerMsgCode {
|
|
1548
|
-
UPDATE_PRESENCE = 100,
|
|
1549
|
-
USER_JOINED = 101,
|
|
1550
|
-
USER_LEFT = 102,
|
|
1551
|
-
BROADCASTED_EVENT = 103,
|
|
1552
|
-
ROOM_STATE = 104,
|
|
1553
|
-
INITIAL_STORAGE_STATE = 200,
|
|
1554
|
-
UPDATE_STORAGE = 201,
|
|
1555
|
-
REJECT_STORAGE_OP = 299,
|
|
1556
|
-
UPDATE_YDOC = 300
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Messages that can be sent from the server to the client.
|
|
1560
|
-
*/
|
|
1561
|
-
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;
|
|
1562
|
-
/**
|
|
1563
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1564
|
-
* a User updated their presence. For example, when a user moves their cursor.
|
|
1565
|
-
*
|
|
1566
|
-
* In most cases, the data payload will only include the fields from the
|
|
1567
|
-
* Presence that have been changed since the last announcement. However, after
|
|
1568
|
-
* a new user joins a room, a "full presence" will be announced so the newly
|
|
1569
|
-
* connected user will get each other's user full presence at least once. In
|
|
1570
|
-
* those cases, the `targetActor` field indicates the newly connected client,
|
|
1571
|
-
* so all other existing clients can ignore this broadcasted message.
|
|
1572
|
-
*/
|
|
1573
|
-
declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
|
|
1574
|
-
readonly type: ServerMsgCode.UPDATE_PRESENCE;
|
|
1575
|
-
/**
|
|
1576
|
-
* The User whose Presence has changed.
|
|
1577
|
-
*/
|
|
1578
|
-
readonly actor: number;
|
|
1579
|
-
/**
|
|
1580
|
-
* When set, signifies that this is a Full Presence™ update, not a patch.
|
|
1581
|
-
*
|
|
1582
|
-
* The numeric value itself no longer has specific meaning. Historically,
|
|
1583
|
-
* this field was intended so that clients could ignore these broadcasted
|
|
1584
|
-
* full presence messages, but it turned out that getting a full presence
|
|
1585
|
-
* "keyframe" from time to time was useful.
|
|
1586
|
-
*
|
|
1587
|
-
* So nowadays, the presence (pun intended) of this `targetActor` field
|
|
1588
|
-
* is a backward-compatible way of expressing that the `data` contains
|
|
1589
|
-
* all presence fields, and isn't a partial "patch".
|
|
1590
|
-
*/
|
|
1591
|
-
readonly targetActor: number;
|
|
1592
|
-
/**
|
|
1593
|
-
* The partial or full Presence of a User. If the `targetActor` field is set,
|
|
1594
|
-
* this will be the full Presence, otherwise it only contain the fields that
|
|
1595
|
-
* have changed since the last broadcast.
|
|
1596
|
-
*/
|
|
1597
|
-
readonly data: TPresence;
|
|
1598
|
-
} | {
|
|
1599
|
-
readonly type: ServerMsgCode.UPDATE_PRESENCE;
|
|
1600
|
-
/**
|
|
1601
|
-
* The User whose Presence has changed.
|
|
1602
|
-
*/
|
|
1603
|
-
readonly actor: number;
|
|
1604
|
-
/**
|
|
1605
|
-
* Not set for partial presence updates.
|
|
1606
|
-
*/
|
|
1607
|
-
readonly targetActor?: undefined;
|
|
1608
|
-
/**
|
|
1609
|
-
* A partial Presence patch to apply to the User. It will only contain the
|
|
1610
|
-
* fields that have changed since the last broadcast.
|
|
1611
|
-
*/
|
|
1612
|
-
readonly data: Partial<TPresence>;
|
|
1613
|
-
};
|
|
1614
|
-
/**
|
|
1615
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1616
|
-
* a new User has joined the Room.
|
|
1617
|
-
*/
|
|
1618
|
-
declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
1619
|
-
readonly type: ServerMsgCode.USER_JOINED;
|
|
1620
|
-
readonly actor: number;
|
|
1621
|
-
/**
|
|
1622
|
-
* The id of the User that has been set in the authentication endpoint.
|
|
1623
|
-
* Useful to get additional information about the connected user.
|
|
1624
|
-
*/
|
|
1625
|
-
readonly id: TUserMeta["id"];
|
|
1626
|
-
/**
|
|
1627
|
-
* Additional user information that has been set in the authentication
|
|
1628
|
-
* endpoint.
|
|
1629
|
-
*/
|
|
1630
|
-
readonly info: TUserMeta["info"];
|
|
1631
|
-
/**
|
|
1632
|
-
* Permissions that the user has in the Room.
|
|
1633
|
-
*/
|
|
1634
|
-
readonly scopes: string[];
|
|
1635
|
-
};
|
|
1636
|
-
/**
|
|
1637
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1638
|
-
* a new User has left the Room.
|
|
1639
|
-
*/
|
|
1640
|
-
declare type UserLeftServerMsg = {
|
|
1641
|
-
readonly type: ServerMsgCode.USER_LEFT;
|
|
1642
|
-
readonly actor: number;
|
|
1643
|
-
};
|
|
1644
|
-
/**
|
|
1645
|
-
* Sent by the WebSocket server when the ydoc is updated or when requested based on stateVector passed.
|
|
1646
|
-
* Contains a base64 encoded update
|
|
1647
|
-
*/
|
|
1648
|
-
declare type YDocUpdate = {
|
|
1649
|
-
readonly type: ServerMsgCode.UPDATE_YDOC;
|
|
1650
|
-
readonly update: string;
|
|
1651
|
-
};
|
|
1652
|
-
/**
|
|
1653
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1654
|
-
* a User broadcasted an Event to everyone in the Room.
|
|
1655
|
-
*/
|
|
1656
|
-
declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
|
|
1657
|
-
readonly type: ServerMsgCode.BROADCASTED_EVENT;
|
|
1658
|
-
/**
|
|
1659
|
-
* The User who broadcasted the Event.
|
|
1660
|
-
*/
|
|
1661
|
-
readonly actor: number;
|
|
1662
|
-
/**
|
|
1663
|
-
* The arbitrary payload of the Event. This can be any JSON value. Clients
|
|
1664
|
-
* will have to manually verify/decode this event.
|
|
1665
|
-
*/
|
|
1666
|
-
readonly event: TRoomEvent;
|
|
1667
|
-
};
|
|
1668
|
-
/**
|
|
1669
|
-
* Sent by the WebSocket server to a single client in response to the client
|
|
1670
|
-
* joining the Room, to provide the initial state of the Room. The payload
|
|
1671
|
-
* includes a list of all other Users that already are in the Room.
|
|
1672
|
-
*/
|
|
1673
|
-
declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
1674
|
-
readonly type: ServerMsgCode.ROOM_STATE;
|
|
1675
|
-
readonly users: {
|
|
1676
|
-
readonly [actor: number]: TUserMeta & {
|
|
1677
|
-
scopes: string[];
|
|
1678
|
-
};
|
|
1679
|
-
};
|
|
1680
|
-
};
|
|
1681
|
-
/**
|
|
1682
|
-
* Sent by the WebSocket server to a single client in response to the client
|
|
1683
|
-
* joining the Room, to provide the initial Storage state of the Room. The
|
|
1684
|
-
* payload includes the entire Storage document.
|
|
1685
|
-
*/
|
|
1686
|
-
declare type InitialDocumentStateServerMsg = {
|
|
1687
|
-
readonly type: ServerMsgCode.INITIAL_STORAGE_STATE;
|
|
1688
|
-
readonly items: IdTuple<SerializedCrdt>[];
|
|
1689
|
-
};
|
|
1690
|
-
/**
|
|
1691
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1692
|
-
* a change occurred in the Storage document.
|
|
1693
|
-
*
|
|
1694
|
-
* The payload of this message contains a list of Ops (aka incremental
|
|
1695
|
-
* mutations to make to the initially loaded document).
|
|
1696
|
-
*/
|
|
1697
|
-
declare type UpdateStorageServerMsg = {
|
|
1698
|
-
readonly type: ServerMsgCode.UPDATE_STORAGE;
|
|
1699
|
-
readonly ops: Op[];
|
|
1700
|
-
};
|
|
1701
|
-
/**
|
|
1702
|
-
* Sent by the WebSocket server to the client to indicate that certain opIds
|
|
1703
|
-
* have been received but were rejected because they caused mutations that are
|
|
1704
|
-
* incompatible with the Room's schema.
|
|
1705
|
-
*/
|
|
1706
|
-
declare type RejectedStorageOpServerMsg = {
|
|
1707
|
-
readonly type: ServerMsgCode.REJECT_STORAGE_OP;
|
|
1708
|
-
readonly opIds: string[];
|
|
1709
|
-
readonly reason: string;
|
|
1710
|
-
};
|
|
1711
|
-
|
|
1712
1727
|
/**
|
|
1713
1728
|
* Lookup table for nodes (= SerializedCrdt values) by their IDs.
|
|
1714
1729
|
*/
|
|
@@ -1884,4 +1899,4 @@ declare type EnsureJson<T> = [
|
|
|
1884
1899
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
1885
1900
|
};
|
|
1886
1901
|
|
|
1887
|
-
export { AckOp, BaseAuthResult, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ToImmutable, ToJson, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asArrayWithLegacyMethods, asPos, assert, assertNever, b64decode, createClient, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
|
1902
|
+
export { AckOp, BaseAuthResult, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ToImmutable, ToJson, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asArrayWithLegacyMethods, asPos, assert, assertNever, b64decode, createClient, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/version.ts
|
|
2
2
|
var PKG_NAME = "@liveblocks/core";
|
|
3
|
-
var PKG_VERSION = "1.1.
|
|
3
|
+
var PKG_VERSION = "1.1.7";
|
|
4
4
|
var PKG_FORMAT = "cjs";
|
|
5
5
|
|
|
6
6
|
// src/dupe-detection.ts
|
|
@@ -195,7 +195,7 @@ function startSyncStream(room) {
|
|
|
195
195
|
// Any time storage updates, send the new storage root
|
|
196
196
|
room.events.storage.subscribe(() => partialSyncStorage(room)),
|
|
197
197
|
// Any time "me" or "others" updates, send the new values accordingly
|
|
198
|
-
room.events.
|
|
198
|
+
room.events.self.subscribe(() => partialSyncMe(room)),
|
|
199
199
|
room.events.others.subscribe(() => partialSyncOthers(room))
|
|
200
200
|
]);
|
|
201
201
|
}
|
|
@@ -3893,16 +3893,11 @@ function isJsonObject(data) {
|
|
|
3893
3893
|
}
|
|
3894
3894
|
|
|
3895
3895
|
// src/protocol/AuthToken.ts
|
|
3896
|
-
function isTokenExpired(token) {
|
|
3897
|
-
const now = Date.now() / 1e3;
|
|
3898
|
-
const valid = now <= token.exp - 300 && now >= token.iat - 300;
|
|
3899
|
-
return !valid;
|
|
3900
|
-
}
|
|
3901
3896
|
function isStringList(value) {
|
|
3902
3897
|
return Array.isArray(value) && value.every((i) => typeof i === "string");
|
|
3903
3898
|
}
|
|
3904
3899
|
function isMinimalTokenPayload(data) {
|
|
3905
|
-
return isPlainObject(data) && typeof data.
|
|
3900
|
+
return isPlainObject(data) && typeof data.actor === "number" && (data.id === void 0 || typeof data.id === "string") && isStringList(data.scopes);
|
|
3906
3901
|
}
|
|
3907
3902
|
function parseAuthToken(rawTokenString) {
|
|
3908
3903
|
const tokenParts = rawTokenString.split(".");
|
|
@@ -4243,6 +4238,7 @@ function createRoom(options, config) {
|
|
|
4243
4238
|
batchUpdates(() => {
|
|
4244
4239
|
eventHub.status.notify(newStatus);
|
|
4245
4240
|
eventHub.connection.notify(newToLegacyStatus(newStatus));
|
|
4241
|
+
notifySelfChanged(doNotBatchUpdates);
|
|
4246
4242
|
});
|
|
4247
4243
|
}
|
|
4248
4244
|
let _connectionLossTimerId;
|
|
@@ -4366,7 +4362,8 @@ function createRoom(options, config) {
|
|
|
4366
4362
|
// New/recommended API
|
|
4367
4363
|
lostConnection: makeEventSource(),
|
|
4368
4364
|
customEvent: makeEventSource(),
|
|
4369
|
-
|
|
4365
|
+
self: makeEventSource(),
|
|
4366
|
+
myPresence: makeEventSource(),
|
|
4370
4367
|
others: makeEventSource(),
|
|
4371
4368
|
error: makeEventSource(),
|
|
4372
4369
|
storage: makeEventSource(),
|
|
@@ -4380,15 +4377,16 @@ function createRoom(options, config) {
|
|
|
4380
4377
|
if (config.unstable_fallbackToHTTP) {
|
|
4381
4378
|
const size = new TextEncoder().encode(message).length;
|
|
4382
4379
|
if (size > MAX_MESSAGE_SIZE && _optionalChain([managedSocket, 'access', _117 => _117.token, 'optionalAccess', _118 => _118.raw]) && config.httpSendEndpoint) {
|
|
4383
|
-
if (isTokenExpired(managedSocket.token.parsed)) {
|
|
4384
|
-
return managedSocket.reconnect();
|
|
4385
|
-
}
|
|
4386
4380
|
void httpSend(
|
|
4387
4381
|
message,
|
|
4388
4382
|
managedSocket.token.raw,
|
|
4389
4383
|
config.httpSendEndpoint,
|
|
4390
4384
|
_optionalChain([config, 'access', _119 => _119.polyfills, 'optionalAccess', _120 => _120.fetch])
|
|
4391
|
-
)
|
|
4385
|
+
).then((resp) => {
|
|
4386
|
+
if (!resp.ok && resp.status === 403) {
|
|
4387
|
+
managedSocket.reconnect();
|
|
4388
|
+
}
|
|
4389
|
+
});
|
|
4392
4390
|
warn(
|
|
4393
4391
|
"Message was too large for websockets and sent over HTTP instead"
|
|
4394
4392
|
);
|
|
@@ -4410,6 +4408,16 @@ function createRoom(options, config) {
|
|
|
4410
4408
|
} : null;
|
|
4411
4409
|
}
|
|
4412
4410
|
);
|
|
4411
|
+
let _lastSelf;
|
|
4412
|
+
function notifySelfChanged(batchedUpdatesWrapper) {
|
|
4413
|
+
const currSelf = self.current;
|
|
4414
|
+
if (currSelf !== null && currSelf !== _lastSelf) {
|
|
4415
|
+
batchedUpdatesWrapper(() => {
|
|
4416
|
+
eventHub.self.notify(currSelf);
|
|
4417
|
+
});
|
|
4418
|
+
_lastSelf = currSelf;
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4413
4421
|
const selfAsTreeNode = new DerivedRef(
|
|
4414
4422
|
self,
|
|
4415
4423
|
(me) => me !== null ? userToTreeNode("Me", me) : null
|
|
@@ -4468,12 +4476,14 @@ function createRoom(options, config) {
|
|
|
4468
4476
|
}
|
|
4469
4477
|
}
|
|
4470
4478
|
if (presence) {
|
|
4471
|
-
|
|
4479
|
+
notifySelfChanged(doNotBatchUpdates);
|
|
4480
|
+
eventHub.myPresence.notify(context.me.current);
|
|
4472
4481
|
}
|
|
4473
4482
|
if (storageUpdates.size > 0) {
|
|
4474
4483
|
const updates = Array.from(storageUpdates.values());
|
|
4475
4484
|
eventHub.storage.notify(updates);
|
|
4476
4485
|
}
|
|
4486
|
+
notifyStorageStatus();
|
|
4477
4487
|
});
|
|
4478
4488
|
}
|
|
4479
4489
|
function getConnectionId() {
|
|
@@ -4549,7 +4559,6 @@ function createRoom(options, config) {
|
|
|
4549
4559
|
}
|
|
4550
4560
|
}
|
|
4551
4561
|
}
|
|
4552
|
-
notifyStorageStatus();
|
|
4553
4562
|
return {
|
|
4554
4563
|
ops,
|
|
4555
4564
|
reverse: output.reverse,
|
|
@@ -4793,7 +4802,7 @@ function createRoom(options, config) {
|
|
|
4793
4802
|
break;
|
|
4794
4803
|
}
|
|
4795
4804
|
case 300 /* UPDATE_YDOC */: {
|
|
4796
|
-
eventHub.ydoc.notify(message
|
|
4805
|
+
eventHub.ydoc.notify(message);
|
|
4797
4806
|
break;
|
|
4798
4807
|
}
|
|
4799
4808
|
case 104 /* ROOM_STATE */: {
|
|
@@ -5101,7 +5110,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5101
5110
|
lostConnection: eventHub.lostConnection.observable,
|
|
5102
5111
|
customEvent: eventHub.customEvent.observable,
|
|
5103
5112
|
others: eventHub.others.observable,
|
|
5104
|
-
|
|
5113
|
+
self: eventHub.self.observable,
|
|
5114
|
+
myPresence: eventHub.myPresence.observable,
|
|
5105
5115
|
error: eventHub.error.observable,
|
|
5106
5116
|
storage: eventHub.storage.observable,
|
|
5107
5117
|
history: eventHub.history.observable,
|
|
@@ -5207,7 +5217,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
5207
5217
|
callback
|
|
5208
5218
|
);
|
|
5209
5219
|
case "my-presence":
|
|
5210
|
-
return events.
|
|
5220
|
+
return events.myPresence.subscribe(callback);
|
|
5211
5221
|
case "others": {
|
|
5212
5222
|
const cb = callback;
|
|
5213
5223
|
return events.others.subscribe(
|
|
@@ -5315,12 +5325,25 @@ function makeAuthDelegateForRoom(roomId, authentication, fetchPolyfill) {
|
|
|
5315
5325
|
} else if (authentication.type === "custom") {
|
|
5316
5326
|
return async () => {
|
|
5317
5327
|
const response = await authentication.callback(roomId);
|
|
5318
|
-
if (!response ||
|
|
5328
|
+
if (!response || typeof response !== "object") {
|
|
5329
|
+
throw new Error(
|
|
5330
|
+
'We expect the authentication callback to return a token, but it does not. Hint: the return value should look like: { token: "..." }'
|
|
5331
|
+
);
|
|
5332
|
+
}
|
|
5333
|
+
if (typeof response.token === "string") {
|
|
5334
|
+
return parseAuthToken(response.token);
|
|
5335
|
+
} else if (typeof response.error === "string") {
|
|
5336
|
+
const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
|
|
5337
|
+
if (response.error === "forbidden") {
|
|
5338
|
+
throw new StopRetrying(reason);
|
|
5339
|
+
} else {
|
|
5340
|
+
throw new Error(reason);
|
|
5341
|
+
}
|
|
5342
|
+
} else {
|
|
5319
5343
|
throw new Error(
|
|
5320
5344
|
'We expect the authentication callback to return a token, but it does not. Hint: the return value should look like: { token: "..." }'
|
|
5321
5345
|
);
|
|
5322
5346
|
}
|
|
5323
|
-
return parseAuthToken(response.token);
|
|
5324
5347
|
};
|
|
5325
5348
|
} else {
|
|
5326
5349
|
throw new Error("Internal error. Unexpected authentication type");
|