@liveblocks/core 2.0.5 → 2.1.1-test1
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 +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +54 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -31,6 +31,9 @@ declare type CustomAuthenticationResult = {
|
|
|
31
31
|
declare type Json = JsonScalar | JsonArray | JsonObject;
|
|
32
32
|
declare type JsonScalar = string | number | boolean | null;
|
|
33
33
|
declare type JsonArray = Json[];
|
|
34
|
+
/**
|
|
35
|
+
* Any valid JSON object.
|
|
36
|
+
*/
|
|
34
37
|
declare type JsonObject = {
|
|
35
38
|
[key: string]: Json | undefined;
|
|
36
39
|
};
|
|
@@ -1880,6 +1883,12 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
|
|
|
1880
1883
|
* const root = room.getStorageSnapshot();
|
|
1881
1884
|
*/
|
|
1882
1885
|
getStorageSnapshot(): LiveObject<S> | null;
|
|
1886
|
+
/**
|
|
1887
|
+
* All possible room events, subscribable from a single place.
|
|
1888
|
+
*
|
|
1889
|
+
* @private These event sources are private for now, but will become public
|
|
1890
|
+
* once they're stable.
|
|
1891
|
+
*/
|
|
1883
1892
|
readonly events: {
|
|
1884
1893
|
readonly status: Observable<Status>;
|
|
1885
1894
|
readonly lostConnection: Observable<LostConnectionEvent>;
|
|
@@ -1888,7 +1897,12 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
|
|
|
1888
1897
|
readonly myPresence: Observable<P>;
|
|
1889
1898
|
readonly others: Observable<OthersEvent<P, U>>;
|
|
1890
1899
|
readonly error: Observable<LiveblocksError>;
|
|
1900
|
+
/**
|
|
1901
|
+
* @deprecated Renamed to `storageBatch`. The `storage` event source will
|
|
1902
|
+
* soon be replaced by another/incompatible API.
|
|
1903
|
+
*/
|
|
1891
1904
|
readonly storage: Observable<StorageUpdate[]>;
|
|
1905
|
+
readonly storageBatch: Observable<StorageUpdate[]>;
|
|
1892
1906
|
readonly history: Observable<HistoryEvent>;
|
|
1893
1907
|
/**
|
|
1894
1908
|
* Subscribe to the storage loaded event. Will fire any time a full Storage
|
|
@@ -1923,6 +1937,24 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
|
|
|
1923
1937
|
* - `synchronized`: Storage is in sync with Liveblocks servers.
|
|
1924
1938
|
*/
|
|
1925
1939
|
getStorageStatus(): StorageStatus;
|
|
1940
|
+
isPresenceReady(): boolean;
|
|
1941
|
+
isStorageReady(): boolean;
|
|
1942
|
+
/**
|
|
1943
|
+
* Returns a Promise that resolves as soon as Presence is available, which
|
|
1944
|
+
* happens shortly after the WebSocket connection has been established. Once
|
|
1945
|
+
* this happens, `self` and `others` are known and available to use. After
|
|
1946
|
+
* awaiting this promise, `.isPresenceReady()` will be guaranteed to be true.
|
|
1947
|
+
* Even when calling this function multiple times, it's guaranteed to return
|
|
1948
|
+
* the same Promise instance.
|
|
1949
|
+
*/
|
|
1950
|
+
waitUntilPresenceReady(): Promise<void>;
|
|
1951
|
+
/**
|
|
1952
|
+
* Returns a Promise that resolves as soon as Storage has been loaded and
|
|
1953
|
+
* available. After awaiting this promise, `.isStorageReady()` will be
|
|
1954
|
+
* guaranteed to be true. Even when calling this function multiple times,
|
|
1955
|
+
* it's guaranteed to return the same Promise instance.
|
|
1956
|
+
*/
|
|
1957
|
+
waitUntilStorageReady(): Promise<void>;
|
|
1926
1958
|
/**
|
|
1927
1959
|
* Start an attempt to connect the room (aka "enter" it). Calling
|
|
1928
1960
|
* `.connect()` only has an effect if the room is still in its idle initial
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ declare type CustomAuthenticationResult = {
|
|
|
31
31
|
declare type Json = JsonScalar | JsonArray | JsonObject;
|
|
32
32
|
declare type JsonScalar = string | number | boolean | null;
|
|
33
33
|
declare type JsonArray = Json[];
|
|
34
|
+
/**
|
|
35
|
+
* Any valid JSON object.
|
|
36
|
+
*/
|
|
34
37
|
declare type JsonObject = {
|
|
35
38
|
[key: string]: Json | undefined;
|
|
36
39
|
};
|
|
@@ -1880,6 +1883,12 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
|
|
|
1880
1883
|
* const root = room.getStorageSnapshot();
|
|
1881
1884
|
*/
|
|
1882
1885
|
getStorageSnapshot(): LiveObject<S> | null;
|
|
1886
|
+
/**
|
|
1887
|
+
* All possible room events, subscribable from a single place.
|
|
1888
|
+
*
|
|
1889
|
+
* @private These event sources are private for now, but will become public
|
|
1890
|
+
* once they're stable.
|
|
1891
|
+
*/
|
|
1883
1892
|
readonly events: {
|
|
1884
1893
|
readonly status: Observable<Status>;
|
|
1885
1894
|
readonly lostConnection: Observable<LostConnectionEvent>;
|
|
@@ -1888,7 +1897,12 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
|
|
|
1888
1897
|
readonly myPresence: Observable<P>;
|
|
1889
1898
|
readonly others: Observable<OthersEvent<P, U>>;
|
|
1890
1899
|
readonly error: Observable<LiveblocksError>;
|
|
1900
|
+
/**
|
|
1901
|
+
* @deprecated Renamed to `storageBatch`. The `storage` event source will
|
|
1902
|
+
* soon be replaced by another/incompatible API.
|
|
1903
|
+
*/
|
|
1891
1904
|
readonly storage: Observable<StorageUpdate[]>;
|
|
1905
|
+
readonly storageBatch: Observable<StorageUpdate[]>;
|
|
1892
1906
|
readonly history: Observable<HistoryEvent>;
|
|
1893
1907
|
/**
|
|
1894
1908
|
* Subscribe to the storage loaded event. Will fire any time a full Storage
|
|
@@ -1923,6 +1937,24 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
|
|
|
1923
1937
|
* - `synchronized`: Storage is in sync with Liveblocks servers.
|
|
1924
1938
|
*/
|
|
1925
1939
|
getStorageStatus(): StorageStatus;
|
|
1940
|
+
isPresenceReady(): boolean;
|
|
1941
|
+
isStorageReady(): boolean;
|
|
1942
|
+
/**
|
|
1943
|
+
* Returns a Promise that resolves as soon as Presence is available, which
|
|
1944
|
+
* happens shortly after the WebSocket connection has been established. Once
|
|
1945
|
+
* this happens, `self` and `others` are known and available to use. After
|
|
1946
|
+
* awaiting this promise, `.isPresenceReady()` will be guaranteed to be true.
|
|
1947
|
+
* Even when calling this function multiple times, it's guaranteed to return
|
|
1948
|
+
* the same Promise instance.
|
|
1949
|
+
*/
|
|
1950
|
+
waitUntilPresenceReady(): Promise<void>;
|
|
1951
|
+
/**
|
|
1952
|
+
* Returns a Promise that resolves as soon as Storage has been loaded and
|
|
1953
|
+
* available. After awaiting this promise, `.isStorageReady()` will be
|
|
1954
|
+
* guaranteed to be true. Even when calling this function multiple times,
|
|
1955
|
+
* it's guaranteed to return the same Promise instance.
|
|
1956
|
+
*/
|
|
1957
|
+
waitUntilStorageReady(): Promise<void>;
|
|
1926
1958
|
/**
|
|
1927
1959
|
* Start an attempt to connect the room (aka "enter" it). Calling
|
|
1928
1960
|
* `.connect()` only has an effect if the room is still in its idle initial
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "2.
|
|
9
|
+
var PKG_VERSION = "2.1.1-test1";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -72,14 +72,17 @@ function nn(value, errmsg = "Expected value to be non-nullable") {
|
|
|
72
72
|
|
|
73
73
|
// src/lib/controlledPromise.ts
|
|
74
74
|
function controlledPromise() {
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
let resolve;
|
|
76
|
+
let reject;
|
|
77
|
+
const promise = new Promise((res, rej) => {
|
|
78
|
+
resolve = res;
|
|
79
|
+
reject = rej;
|
|
78
80
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
return [promise, resolve, reject];
|
|
82
|
+
}
|
|
83
|
+
function Promise_withResolvers() {
|
|
84
|
+
const [promise, resolve, reject] = controlledPromise();
|
|
85
|
+
return { promise, resolve, reject };
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
// src/lib/EventSource.ts
|
|
@@ -634,6 +637,15 @@ async function withTimeout(promise, millis, errmsg) {
|
|
|
634
637
|
});
|
|
635
638
|
return Promise.race([promise, timer$]).finally(() => clearTimeout(timerID));
|
|
636
639
|
}
|
|
640
|
+
function memoize(factoryFn) {
|
|
641
|
+
let cached = null;
|
|
642
|
+
return () => {
|
|
643
|
+
if (cached === null) {
|
|
644
|
+
cached = { value: factoryFn() };
|
|
645
|
+
}
|
|
646
|
+
return cached.value;
|
|
647
|
+
};
|
|
648
|
+
}
|
|
637
649
|
|
|
638
650
|
// src/protocol/ServerMsg.ts
|
|
639
651
|
var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
|
|
@@ -1604,7 +1616,7 @@ function startSyncStream(room) {
|
|
|
1604
1616
|
// When storage initializes, send the update
|
|
1605
1617
|
room.events.storageDidLoad.subscribeOnce(() => partialSyncStorage(room)),
|
|
1606
1618
|
// Any time storage updates, send the new storage root
|
|
1607
|
-
room.events.
|
|
1619
|
+
room.events.storageBatch.subscribe(() => partialSyncStorage(room)),
|
|
1608
1620
|
// Any time "me" or "others" updates, send the new values accordingly
|
|
1609
1621
|
room.events.self.subscribe(() => partialSyncMe(room)),
|
|
1610
1622
|
room.events.others.subscribe(() => partialSyncOthers(room)),
|
|
@@ -5541,7 +5553,7 @@ function createRoom(options, config) {
|
|
|
5541
5553
|
myPresence: makeEventSource(),
|
|
5542
5554
|
others: makeEventSource(),
|
|
5543
5555
|
error: makeEventSource(),
|
|
5544
|
-
|
|
5556
|
+
storageBatch: makeEventSource(),
|
|
5545
5557
|
history: makeEventSource(),
|
|
5546
5558
|
storageDidLoad: makeEventSource(),
|
|
5547
5559
|
storageStatus: makeEventSource(),
|
|
@@ -5751,7 +5763,7 @@ function createRoom(options, config) {
|
|
|
5751
5763
|
}
|
|
5752
5764
|
if (storageUpdates !== void 0 && storageUpdates.size > 0) {
|
|
5753
5765
|
const updates2 = Array.from(storageUpdates.values());
|
|
5754
|
-
eventHub.
|
|
5766
|
+
eventHub.storageBatch.notify(updates2);
|
|
5755
5767
|
}
|
|
5756
5768
|
notifyStorageStatus();
|
|
5757
5769
|
});
|
|
@@ -6415,6 +6427,27 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6415
6427
|
eventHub.storageStatus.notify(storageStatus);
|
|
6416
6428
|
}
|
|
6417
6429
|
}
|
|
6430
|
+
function isPresenceReady() {
|
|
6431
|
+
return self.current !== null;
|
|
6432
|
+
}
|
|
6433
|
+
async function waitUntilPresenceReady() {
|
|
6434
|
+
while (!isPresenceReady()) {
|
|
6435
|
+
const { promise, resolve } = Promise_withResolvers();
|
|
6436
|
+
const unsub1 = events.self.subscribeOnce(resolve);
|
|
6437
|
+
const unsub2 = events.status.subscribeOnce(resolve);
|
|
6438
|
+
await promise;
|
|
6439
|
+
unsub1();
|
|
6440
|
+
unsub2();
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
function isStorageReady() {
|
|
6444
|
+
return getStorageSnapshot() !== null;
|
|
6445
|
+
}
|
|
6446
|
+
async function waitUntilStorageReady() {
|
|
6447
|
+
while (!isStorageReady()) {
|
|
6448
|
+
await getStorage();
|
|
6449
|
+
}
|
|
6450
|
+
}
|
|
6418
6451
|
const others_forDevTools = new DerivedRef(
|
|
6419
6452
|
context.others,
|
|
6420
6453
|
(others) => others.map((other, index) => userToTreeNode(`Other ${index}`, other))
|
|
@@ -6427,7 +6460,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6427
6460
|
self: eventHub.self.observable,
|
|
6428
6461
|
myPresence: eventHub.myPresence.observable,
|
|
6429
6462
|
error: eventHub.error.observable,
|
|
6430
|
-
|
|
6463
|
+
/** @deprecated */
|
|
6464
|
+
storage: eventHub.storageBatch.observable,
|
|
6465
|
+
storageBatch: eventHub.storageBatch.observable,
|
|
6431
6466
|
history: eventHub.history.observable,
|
|
6432
6467
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
6433
6468
|
storageStatus: eventHub.storageStatus.observable,
|
|
@@ -6578,6 +6613,10 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6578
6613
|
getStorage,
|
|
6579
6614
|
getStorageSnapshot,
|
|
6580
6615
|
getStorageStatus,
|
|
6616
|
+
isPresenceReady,
|
|
6617
|
+
isStorageReady,
|
|
6618
|
+
waitUntilPresenceReady: memoize(waitUntilPresenceReady),
|
|
6619
|
+
waitUntilStorageReady: memoize(waitUntilStorageReady),
|
|
6581
6620
|
events,
|
|
6582
6621
|
// Core
|
|
6583
6622
|
getStatus: () => managedSocket.getStatus(),
|
|
@@ -6594,7 +6633,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6594
6633
|
}
|
|
6595
6634
|
function makeClassicSubscribeFn(events) {
|
|
6596
6635
|
function subscribeToLiveStructureDeeply(node, callback) {
|
|
6597
|
-
return events.
|
|
6636
|
+
return events.storageBatch.subscribe((updates) => {
|
|
6598
6637
|
const relatedUpdates = updates.filter(
|
|
6599
6638
|
(update) => isSameNodeOrChildOf(update.node, node)
|
|
6600
6639
|
);
|
|
@@ -6604,7 +6643,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
6604
6643
|
});
|
|
6605
6644
|
}
|
|
6606
6645
|
function subscribeToLiveStructureShallowly(node, callback) {
|
|
6607
|
-
return events.
|
|
6646
|
+
return events.storageBatch.subscribe((updates) => {
|
|
6608
6647
|
for (const update of updates) {
|
|
6609
6648
|
if (update.node._id === node._id) {
|
|
6610
6649
|
callback(update.node);
|
|
@@ -6656,7 +6695,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
6656
6695
|
if (second === void 0 || typeof first === "function") {
|
|
6657
6696
|
if (typeof first === "function") {
|
|
6658
6697
|
const storageCallback = first;
|
|
6659
|
-
return events.
|
|
6698
|
+
return events.storageBatch.subscribe(storageCallback);
|
|
6660
6699
|
} else {
|
|
6661
6700
|
throw new Error("Please specify a listener callback");
|
|
6662
6701
|
}
|