@liveblocks/core 1.6.0-subdocs2 → 1.7.0-stream2

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.6.0-subdocs2";
9
+ var PKG_VERSION = "1.7.0-stream2";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -4977,6 +4977,21 @@ function createRoom(options, config) {
4977
4977
  ydoc: makeEventSource(),
4978
4978
  comments: makeEventSource()
4979
4979
  };
4980
+ async function streamFetch(authTokenOrPublicApiKey, roomId) {
4981
+ const url = new URL(
4982
+ `/v2/c/rooms/${encodeURIComponent(roomId)}/storage`,
4983
+ config.baseUrl
4984
+ ).toString();
4985
+ const fetcher = config.polyfills?.fetch || /* istanbul ignore next */
4986
+ fetch;
4987
+ return fetcher(url.toString(), {
4988
+ method: "GET",
4989
+ headers: {
4990
+ "Content-Type": "application/json",
4991
+ Authorization: `Bearer ${authTokenOrPublicApiKey}`
4992
+ }
4993
+ });
4994
+ }
4980
4995
  async function httpSend(authTokenOrPublicApiKey, roomId, nonce, messages) {
4981
4996
  const url = new URL(
4982
4997
  `/v2/c/rooms/${encodeURIComponent(roomId)}/send-message`,
@@ -5447,12 +5462,7 @@ function createRoom(options, config) {
5447
5462
  break;
5448
5463
  }
5449
5464
  case 200 /* INITIAL_STORAGE_STATE */: {
5450
- const unacknowledgedOps = new Map(context.unacknowledgedOps);
5451
- createOrUpdateRootFromMessage(message, doNotBatchUpdates);
5452
- applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
5453
- _resolveStoragePromise?.();
5454
- notifyStorageStatus();
5455
- eventHub.storageDidLoad.notify();
5465
+ processInitialStorage(message);
5456
5466
  break;
5457
5467
  }
5458
5468
  case 201 /* UPDATE_STORAGE */: {
@@ -5570,11 +5580,10 @@ ${Array.from(traces).join("\n\n")}`
5570
5580
  }
5571
5581
  return messages;
5572
5582
  }
5573
- function updateYDoc(update, guid) {
5583
+ function updateYDoc(update) {
5574
5584
  const clientMsg = {
5575
5585
  type: 301 /* UPDATE_YDOC */,
5576
- update,
5577
- guid
5586
+ update
5578
5587
  };
5579
5588
  context.buffer.messages.push(clientMsg);
5580
5589
  eventHub.ydoc.notify(clientMsg);
@@ -5598,9 +5607,30 @@ ${Array.from(traces).join("\n\n")}`
5598
5607
  }
5599
5608
  let _getStorage$ = null;
5600
5609
  let _resolveStoragePromise = null;
5610
+ function processInitialStorage(message) {
5611
+ const unacknowledgedOps = new Map(context.unacknowledgedOps);
5612
+ createOrUpdateRootFromMessage(message, doNotBatchUpdates);
5613
+ applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
5614
+ _resolveStoragePromise?.();
5615
+ notifyStorageStatus();
5616
+ eventHub.storageDidLoad.notify();
5617
+ }
5618
+ async function streamStorage() {
5619
+ if (!managedSocket.authValue) {
5620
+ return;
5621
+ }
5622
+ const result = await streamFetch(
5623
+ managedSocket.authValue.type === "public" ? managedSocket.authValue.publicApiKey : managedSocket.authValue.token.raw,
5624
+ config.roomId
5625
+ );
5626
+ const items = await result.json();
5627
+ processInitialStorage({ type: 200 /* INITIAL_STORAGE_STATE */, items });
5628
+ }
5601
5629
  function refreshStorage(options2) {
5602
5630
  const messages = context.buffer.messages;
5603
- if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
5631
+ if (config.unstable_streamData) {
5632
+ void streamStorage();
5633
+ } else if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
5604
5634
  messages.push({ type: 200 /* FETCH_STORAGE */ });
5605
5635
  }
5606
5636
  if (options2.flush) {
@@ -5637,14 +5667,13 @@ ${Array.from(traces).join("\n\n")}`
5637
5667
  root: nn(context.root)
5638
5668
  };
5639
5669
  }
5640
- function fetchYDoc(vector, guid) {
5670
+ function fetchYDoc(vector) {
5641
5671
  if (!context.buffer.messages.find((m) => {
5642
- return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid;
5672
+ return m.type === 300 /* FETCH_YDOC */ && m.vector === vector;
5643
5673
  })) {
5644
5674
  context.buffer.messages.push({
5645
5675
  type: 300 /* FETCH_YDOC */,
5646
- vector,
5647
- guid
5676
+ vector
5648
5677
  });
5649
5678
  }
5650
5679
  flushNowOrSoon();
@@ -6058,7 +6087,8 @@ function createClient(options) {
6058
6087
  enableDebugLogging: clientOptions.enableDebugLogging,
6059
6088
  unstable_batchedUpdates: options2?.unstable_batchedUpdates,
6060
6089
  baseUrl,
6061
- unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
6090
+ unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
6091
+ unstable_streamData: !!clientOptions.unstable_streamData
6062
6092
  }
6063
6093
  );
6064
6094
  const newRoomInfo = {