@liveblocks/core 1.9.2 → 1.9.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/dist/index.mjs 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 = "1.9.2";
9
+ var PKG_VERSION = "1.9.3";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -5371,6 +5371,21 @@ function createRoom(options, config) {
5371
5371
  ydoc: makeEventSource(),
5372
5372
  comments: makeEventSource()
5373
5373
  };
5374
+ async function streamFetch(authTokenOrPublicApiKey, roomId) {
5375
+ const url = new URL(
5376
+ `/v2/c/rooms/${encodeURIComponent(roomId)}/storage`,
5377
+ config.baseUrl
5378
+ ).toString();
5379
+ const fetcher = config.polyfills?.fetch || /* istanbul ignore next */
5380
+ fetch;
5381
+ return fetcher(url.toString(), {
5382
+ method: "GET",
5383
+ headers: {
5384
+ "Content-Type": "application/json",
5385
+ Authorization: `Bearer ${authTokenOrPublicApiKey}`
5386
+ }
5387
+ });
5388
+ }
5374
5389
  async function httpPostToRoom(endpoint, body) {
5375
5390
  if (!managedSocket.authValue) {
5376
5391
  throw new Error("Not authorized");
@@ -5842,12 +5857,7 @@ function createRoom(options, config) {
5842
5857
  break;
5843
5858
  }
5844
5859
  case 200 /* INITIAL_STORAGE_STATE */: {
5845
- const unacknowledgedOps = new Map(context.unacknowledgedOps);
5846
- createOrUpdateRootFromMessage(message, doNotBatchUpdates);
5847
- applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
5848
- _resolveStoragePromise?.();
5849
- notifyStorageStatus();
5850
- eventHub.storageDidLoad.notify();
5860
+ processInitialStorage(message);
5851
5861
  break;
5852
5862
  }
5853
5863
  case 201 /* UPDATE_STORAGE */: {
@@ -5993,9 +6003,30 @@ ${Array.from(traces).join("\n\n")}`
5993
6003
  }
5994
6004
  let _getStorage$ = null;
5995
6005
  let _resolveStoragePromise = null;
6006
+ function processInitialStorage(message) {
6007
+ const unacknowledgedOps = new Map(context.unacknowledgedOps);
6008
+ createOrUpdateRootFromMessage(message, doNotBatchUpdates);
6009
+ applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
6010
+ _resolveStoragePromise?.();
6011
+ notifyStorageStatus();
6012
+ eventHub.storageDidLoad.notify();
6013
+ }
6014
+ async function streamStorage() {
6015
+ if (!managedSocket.authValue) {
6016
+ return;
6017
+ }
6018
+ const result = await streamFetch(
6019
+ managedSocket.authValue.type === "public" ? managedSocket.authValue.publicApiKey : managedSocket.authValue.token.raw,
6020
+ config.roomId
6021
+ );
6022
+ const items = await result.json();
6023
+ processInitialStorage({ type: 200 /* INITIAL_STORAGE_STATE */, items });
6024
+ }
5996
6025
  function refreshStorage(options2) {
5997
6026
  const messages = context.buffer.messages;
5998
- if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
6027
+ if (config.unstable_streamData) {
6028
+ void streamStorage();
6029
+ } else if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
5999
6030
  messages.push({ type: 200 /* FETCH_STORAGE */ });
6000
6031
  }
6001
6032
  if (options2.flush) {
@@ -6455,7 +6486,8 @@ function createClient(options) {
6455
6486
  enableDebugLogging: clientOptions.enableDebugLogging,
6456
6487
  unstable_batchedUpdates: options2?.unstable_batchedUpdates,
6457
6488
  baseUrl,
6458
- unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
6489
+ unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
6490
+ unstable_streamData: !!clientOptions.unstable_streamData
6459
6491
  }
6460
6492
  );
6461
6493
  const newRoomInfo = {