@liveblocks/core 1.4.6 → 1.4.7-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.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.4.6";
9
+ var PKG_VERSION = "1.4.7-test1";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -4900,6 +4900,23 @@ function createRoom(options, config) {
4900
4900
  ydoc: makeEventSource(),
4901
4901
  comments: makeEventSource()
4902
4902
  };
4903
+ async function streamFetch(authTokenOrPublicApiKey, roomId) {
4904
+ const baseUrl = new URL(config.liveblocksServer);
4905
+ baseUrl.protocol = "https";
4906
+ const url = new URL(
4907
+ `/v2/c/rooms/${encodeURIComponent(roomId)}/storage`,
4908
+ baseUrl
4909
+ );
4910
+ const fetcher = config.polyfills?.fetch || /* istanbul ignore next */
4911
+ fetch;
4912
+ return fetcher(url.toString(), {
4913
+ method: "GET",
4914
+ headers: {
4915
+ "Content-Type": "application/json",
4916
+ Authorization: `Bearer ${authTokenOrPublicApiKey}`
4917
+ }
4918
+ });
4919
+ }
4903
4920
  async function httpSend(authTokenOrPublicApiKey, roomId, nonce, messages) {
4904
4921
  const baseUrl = new URL(config.liveblocksServer);
4905
4922
  baseUrl.protocol = "https";
@@ -5374,12 +5391,7 @@ function createRoom(options, config) {
5374
5391
  break;
5375
5392
  }
5376
5393
  case 200 /* INITIAL_STORAGE_STATE */: {
5377
- const unacknowledgedOps = new Map(context.unacknowledgedOps);
5378
- createOrUpdateRootFromMessage(message, doNotBatchUpdates);
5379
- applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
5380
- _resolveStoragePromise?.();
5381
- notifyStorageStatus();
5382
- eventHub.storageDidLoad.notify();
5394
+ processInitialStorage(message);
5383
5395
  break;
5384
5396
  }
5385
5397
  case 201 /* UPDATE_STORAGE */: {
@@ -5524,9 +5536,30 @@ ${Array.from(traces).join("\n\n")}`
5524
5536
  }
5525
5537
  let _getStorage$ = null;
5526
5538
  let _resolveStoragePromise = null;
5539
+ function processInitialStorage(message) {
5540
+ const unacknowledgedOps = new Map(context.unacknowledgedOps);
5541
+ createOrUpdateRootFromMessage(message, doNotBatchUpdates);
5542
+ applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
5543
+ _resolveStoragePromise?.();
5544
+ notifyStorageStatus();
5545
+ eventHub.storageDidLoad.notify();
5546
+ }
5547
+ async function streamStorage() {
5548
+ if (!managedSocket.authValue) {
5549
+ return;
5550
+ }
5551
+ const result = await streamFetch(
5552
+ managedSocket.authValue.type === "public" ? managedSocket.authValue.publicApiKey : managedSocket.authValue.token.raw,
5553
+ config.roomId
5554
+ );
5555
+ const items = await result.json();
5556
+ processInitialStorage({ type: 200 /* INITIAL_STORAGE_STATE */, items });
5557
+ }
5527
5558
  function refreshStorage(options2) {
5528
5559
  const messages = context.buffer.messages;
5529
- if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
5560
+ if (config.unstable_streamData) {
5561
+ void streamStorage();
5562
+ } else if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
5530
5563
  messages.push({ type: 200 /* FETCH_STORAGE */ });
5531
5564
  }
5532
5565
  if (options2.flush) {
@@ -5946,7 +5979,8 @@ function createClient(options) {
5946
5979
  enableDebugLogging: clientOptions.enableDebugLogging,
5947
5980
  unstable_batchedUpdates: options2?.unstable_batchedUpdates,
5948
5981
  liveblocksServer: getServerFromClientOptions(clientOptions),
5949
- unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
5982
+ unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
5983
+ unstable_streamData: !!clientOptions.unstable_streamData
5950
5984
  }
5951
5985
  );
5952
5986
  rooms.set(roomId, newRoom);