@liveblocks/core 0.19.3-beta0 → 0.19.3-beta2
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.ts +24 -5
- package/dist/index.js +22 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -514,9 +514,15 @@ declare type RoomAuthToken = {
|
|
|
514
514
|
scopes: string[];
|
|
515
515
|
actor: number;
|
|
516
516
|
maxConnectionsPerRoom?: number;
|
|
517
|
-
id?: string;
|
|
518
517
|
info?: Json;
|
|
519
|
-
|
|
518
|
+
groupIds?: string[];
|
|
519
|
+
} & ({
|
|
520
|
+
id: string;
|
|
521
|
+
anonymousId?: never;
|
|
522
|
+
} | {
|
|
523
|
+
id?: never;
|
|
524
|
+
anonymousId: string;
|
|
525
|
+
});
|
|
520
526
|
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
521
527
|
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
522
528
|
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
@@ -726,10 +732,13 @@ interface History {
|
|
|
726
732
|
*/
|
|
727
733
|
resume: () => void;
|
|
728
734
|
}
|
|
729
|
-
|
|
735
|
+
declare type HistoryEvent = {
|
|
730
736
|
canUndo: boolean;
|
|
731
737
|
canRedo: boolean;
|
|
732
|
-
}
|
|
738
|
+
};
|
|
739
|
+
declare type PendingHasModificationsEvent = {
|
|
740
|
+
hasPendingStorageModifications: boolean;
|
|
741
|
+
};
|
|
733
742
|
declare type BroadcastOptions = {
|
|
734
743
|
/**
|
|
735
744
|
* Whether or not event is queued if the connection is currently closed.
|
|
@@ -846,9 +855,19 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
846
855
|
* room.subscribe("history", ({ canUndo, canRedo }) => {
|
|
847
856
|
* // Do something
|
|
848
857
|
* });
|
|
849
|
-
*
|
|
850
858
|
*/
|
|
851
859
|
(type: "history", listener: Callback<HistoryEvent>): () => void;
|
|
860
|
+
/**
|
|
861
|
+
* Subscribe to pending storage modifications updates.
|
|
862
|
+
*
|
|
863
|
+
* @returns Unsubscribe function.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* room.subscribe("pending-storage-modifications", ({ hasPendingStorageModifications }) => {
|
|
867
|
+
* // Do something
|
|
868
|
+
* });
|
|
869
|
+
*/
|
|
870
|
+
(type: "pending-storage-modifications", listener: Callback<PendingHasModificationsEvent>): () => void;
|
|
852
871
|
};
|
|
853
872
|
/**
|
|
854
873
|
* Room's history contains functions that let you undo and redo operation made on by the current client on the presence and storage.
|
package/dist/index.js
CHANGED
|
@@ -2725,7 +2725,8 @@ function makeStateMachine(state, config, mockedEffects) {
|
|
|
2725
2725
|
connection: makeEventSource(),
|
|
2726
2726
|
storage: makeEventSource(),
|
|
2727
2727
|
history: makeEventSource(),
|
|
2728
|
-
storageDidLoad: makeEventSource()
|
|
2728
|
+
storageDidLoad: makeEventSource(),
|
|
2729
|
+
pendingStorageModifications: makeEventSource()
|
|
2729
2730
|
};
|
|
2730
2731
|
const effects = mockedEffects || {
|
|
2731
2732
|
authenticate(auth, createWebSocket) {
|
|
@@ -2893,6 +2894,7 @@ function makeStateMachine(state, config, mockedEffects) {
|
|
|
2893
2894
|
return op;
|
|
2894
2895
|
}
|
|
2895
2896
|
});
|
|
2897
|
+
const hasPendingStorageModifs = hasPendingStorageModifications();
|
|
2896
2898
|
for (const op of ops) {
|
|
2897
2899
|
if (op.type === "presence") {
|
|
2898
2900
|
const reverse = {
|
|
@@ -2944,6 +2946,11 @@ function makeStateMachine(state, config, mockedEffects) {
|
|
|
2944
2946
|
}
|
|
2945
2947
|
}
|
|
2946
2948
|
}
|
|
2949
|
+
if (hasPendingStorageModifs && hasPendingStorageModifications() === false) {
|
|
2950
|
+
eventHub.pendingStorageModifications.notify({
|
|
2951
|
+
hasPendingStorageModifications: false
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2947
2954
|
return {
|
|
2948
2955
|
ops,
|
|
2949
2956
|
reverse: output.reverse,
|
|
@@ -3039,6 +3046,10 @@ function makeStateMachine(state, config, mockedEffects) {
|
|
|
3039
3046
|
);
|
|
3040
3047
|
case "history":
|
|
3041
3048
|
return eventHub.history.subscribe(callback);
|
|
3049
|
+
case "pending-storage-modifications":
|
|
3050
|
+
return eventHub.pendingStorageModifications.subscribe(
|
|
3051
|
+
callback
|
|
3052
|
+
);
|
|
3042
3053
|
default:
|
|
3043
3054
|
return assertNever(first, "Unknown event");
|
|
3044
3055
|
}
|
|
@@ -3444,9 +3455,15 @@ function makeStateMachine(state, config, mockedEffects) {
|
|
|
3444
3455
|
function tryFlushing() {
|
|
3445
3456
|
const storageOps = state.buffer.storageOperations;
|
|
3446
3457
|
if (storageOps.length > 0) {
|
|
3458
|
+
const hasAlreadyPendingModifications = hasPendingStorageModifications();
|
|
3447
3459
|
storageOps.forEach((op) => {
|
|
3448
3460
|
state.offlineOperations.set(nn(op.opId), op);
|
|
3449
3461
|
});
|
|
3462
|
+
if (!hasAlreadyPendingModifications) {
|
|
3463
|
+
eventHub.pendingStorageModifications.notify({
|
|
3464
|
+
hasPendingStorageModifications: true
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3450
3467
|
}
|
|
3451
3468
|
if (state.socket === null || state.socket.readyState !== state.socket.OPEN) {
|
|
3452
3469
|
state.buffer.storageOperations = [];
|
|
@@ -3719,7 +3736,8 @@ function makeStateMachine(state, config, mockedEffects) {
|
|
|
3719
3736
|
connection: eventHub.connection.observable,
|
|
3720
3737
|
storage: eventHub.storage.observable,
|
|
3721
3738
|
history: eventHub.history.observable,
|
|
3722
|
-
storageDidLoad: eventHub.storageDidLoad.observable
|
|
3739
|
+
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
3740
|
+
pendingStorageModifications: eventHub.pendingStorageModifications
|
|
3723
3741
|
},
|
|
3724
3742
|
getConnectionState,
|
|
3725
3743
|
isSelfAware: () => isConnectionSelfAware(state.connection.current),
|
|
@@ -3831,7 +3849,7 @@ function prepareCreateWebSocket(liveblocksServer, WebSocketPolyfill) {
|
|
|
3831
3849
|
const ws = WebSocketPolyfill || WebSocket;
|
|
3832
3850
|
return (token) => {
|
|
3833
3851
|
return new ws(
|
|
3834
|
-
`${liveblocksServer}/?token=${token}&version=${true ? "0.19.3-
|
|
3852
|
+
`${liveblocksServer}/?token=${token}&version=${true ? "0.19.3-beta2" : "dev"}`
|
|
3835
3853
|
);
|
|
3836
3854
|
};
|
|
3837
3855
|
}
|
|
@@ -3881,6 +3899,7 @@ function fetchAuthEndpoint(fetch2, endpoint, body) {
|
|
|
3881
3899
|
headers: {
|
|
3882
3900
|
"Content-Type": "application/json"
|
|
3883
3901
|
},
|
|
3902
|
+
credentials: "include",
|
|
3884
3903
|
body: JSON.stringify(body)
|
|
3885
3904
|
});
|
|
3886
3905
|
if (!res.ok) {
|