@liveblocks/core 1.4.6-test1 → 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.d.mts CHANGED
@@ -1825,6 +1825,7 @@ declare type ClientOptions = {
1825
1825
  lostConnectionTimeout?: number;
1826
1826
  polyfills?: Polyfills;
1827
1827
  unstable_fallbackToHTTP?: boolean;
1828
+ unstable_streamData?: boolean;
1828
1829
  /**
1829
1830
  * @deprecated Use `polyfills: { fetch: ... }` instead.
1830
1831
  * This option will be removed in a future release.
package/dist/index.d.ts CHANGED
@@ -1825,6 +1825,7 @@ declare type ClientOptions = {
1825
1825
  lostConnectionTimeout?: number;
1826
1826
  polyfills?: Polyfills;
1827
1827
  unstable_fallbackToHTTP?: boolean;
1828
+ unstable_streamData?: boolean;
1828
1829
  /**
1829
1830
  * @deprecated Use `polyfills: { fetch: ... }` instead.
1830
1831
  * This option will be removed in a future release.
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 = "1.4.6-test1";
9
+ var PKG_VERSION = "1.4.7-test1";
10
10
  var PKG_FORMAT = "cjs";
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 = _optionalChain([config, 'access', _115 => _115.polyfills, 'optionalAccess', _116 => _116.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";
@@ -4907,7 +4924,7 @@ function createRoom(options, config) {
4907
4924
  `/v2/c/rooms/${encodeURIComponent(roomId)}/send-message`,
4908
4925
  baseUrl
4909
4926
  );
4910
- const fetcher = _optionalChain([config, 'access', _115 => _115.polyfills, 'optionalAccess', _116 => _116.fetch]) || /* istanbul ignore next */
4927
+ const fetcher = _optionalChain([config, 'access', _117 => _117.polyfills, 'optionalAccess', _118 => _118.fetch]) || /* istanbul ignore next */
4911
4928
  fetch;
4912
4929
  return fetcher(url.toString(), {
4913
4930
  method: "POST",
@@ -4920,7 +4937,7 @@ function createRoom(options, config) {
4920
4937
  }
4921
4938
  function sendMessages(messages) {
4922
4939
  const serializedPayload = JSON.stringify(messages);
4923
- const nonce = _optionalChain([context, 'access', _117 => _117.dynamicSessionInfo, 'access', _118 => _118.current, 'optionalAccess', _119 => _119.nonce]);
4940
+ const nonce = _optionalChain([context, 'access', _119 => _119.dynamicSessionInfo, 'access', _120 => _120.current, 'optionalAccess', _121 => _121.nonce]);
4924
4941
  if (config.unstable_fallbackToHTTP && managedSocket.authValue && nonce) {
4925
4942
  const size = new TextEncoder().encode(serializedPayload).length;
4926
4943
  if (size > MAX_SOCKET_MESSAGE_SIZE) {
@@ -5187,7 +5204,7 @@ function createRoom(options, config) {
5187
5204
  }
5188
5205
  context.myPresence.patch(patch);
5189
5206
  if (context.activeBatch) {
5190
- if (_optionalChain([options2, 'optionalAccess', _120 => _120.addToHistory])) {
5207
+ if (_optionalChain([options2, 'optionalAccess', _122 => _122.addToHistory])) {
5191
5208
  context.activeBatch.reverseOps.unshift({
5192
5209
  type: "presence",
5193
5210
  data: oldValues
@@ -5197,7 +5214,7 @@ function createRoom(options, config) {
5197
5214
  } else {
5198
5215
  flushNowOrSoon();
5199
5216
  batchUpdates(() => {
5200
- if (_optionalChain([options2, 'optionalAccess', _121 => _121.addToHistory])) {
5217
+ if (_optionalChain([options2, 'optionalAccess', _123 => _123.addToHistory])) {
5201
5218
  addToUndoStack(
5202
5219
  [{ type: "presence", data: oldValues }],
5203
5220
  doNotBatchUpdates
@@ -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
- _optionalChain([_resolveStoragePromise, 'optionalCall', _122 => _122()]);
5381
- notifyStorageStatus();
5382
- eventHub.storageDidLoad.notify();
5394
+ processInitialStorage(message);
5383
5395
  break;
5384
5396
  }
5385
5397
  case 201 /* UPDATE_STORAGE */: {
@@ -5400,7 +5412,7 @@ function createRoom(options, config) {
5400
5412
  if (process.env.NODE_ENV !== "production") {
5401
5413
  const traces = /* @__PURE__ */ new Set();
5402
5414
  for (const opId of message.opIds) {
5403
- const trace = _optionalChain([context, 'access', _123 => _123.opStackTraces, 'optionalAccess', _124 => _124.get, 'call', _125 => _125(opId)]);
5415
+ const trace = _optionalChain([context, 'access', _124 => _124.opStackTraces, 'optionalAccess', _125 => _125.get, 'call', _126 => _126(opId)]);
5404
5416
  if (trace) {
5405
5417
  traces.add(trace);
5406
5418
  }
@@ -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
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _127 => _127()]);
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) {
@@ -5712,7 +5745,7 @@ ${Array.from(traces).join("\n\n")}`
5712
5745
  /* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
5713
5746
  __internal: {
5714
5747
  get presenceBuffer() {
5715
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _126 => _126.buffer, 'access', _127 => _127.presenceUpdates, 'optionalAccess', _128 => _128.data]), () => ( null)));
5748
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _128 => _128.buffer, 'access', _129 => _129.presenceUpdates, 'optionalAccess', _130 => _130.data]), () => ( null)));
5716
5749
  },
5717
5750
  // prettier-ignore
5718
5751
  get undoStack() {
@@ -5848,7 +5881,7 @@ function makeClassicSubscribeFn(events) {
5848
5881
  }
5849
5882
  if (isLiveNode(first)) {
5850
5883
  const node = first;
5851
- if (_optionalChain([options, 'optionalAccess', _129 => _129.isDeep])) {
5884
+ if (_optionalChain([options, 'optionalAccess', _131 => _131.isDeep])) {
5852
5885
  const storageCallback = second;
5853
5886
  return subscribeToLiveStructureDeeply(node, storageCallback);
5854
5887
  } else {
@@ -5939,14 +5972,15 @@ function createClient(options) {
5939
5972
  createSocket: makeCreateSocketDelegateForRoom(
5940
5973
  roomId,
5941
5974
  getServerFromClientOptions(clientOptions),
5942
- _optionalChain([clientOptions, 'access', _130 => _130.polyfills, 'optionalAccess', _131 => _131.WebSocket])
5975
+ _optionalChain([clientOptions, 'access', _132 => _132.polyfills, 'optionalAccess', _133 => _133.WebSocket])
5943
5976
  ),
5944
5977
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
5945
5978
  })),
5946
5979
  enableDebugLogging: clientOptions.enableDebugLogging,
5947
- unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _132 => _132.unstable_batchedUpdates]),
5980
+ unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _134 => _134.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);
@@ -5955,7 +5989,7 @@ function createClient(options) {
5955
5989
  const shouldConnect = _nullishCoalesce(options2.shouldInitiallyConnect, () => ( true));
5956
5990
  if (shouldConnect) {
5957
5991
  if (typeof atob === "undefined") {
5958
- if (_optionalChain([clientOptions, 'access', _133 => _133.polyfills, 'optionalAccess', _134 => _134.atob]) === void 0) {
5992
+ if (_optionalChain([clientOptions, 'access', _135 => _135.polyfills, 'optionalAccess', _136 => _136.atob]) === void 0) {
5959
5993
  throw new Error(
5960
5994
  "You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
5961
5995
  );
@@ -6230,12 +6264,12 @@ function legacy_patchImmutableNode(state, path, update) {
6230
6264
  }
6231
6265
  const newState = Object.assign({}, state);
6232
6266
  for (const key in update.updates) {
6233
- if (_optionalChain([update, 'access', _135 => _135.updates, 'access', _136 => _136[key], 'optionalAccess', _137 => _137.type]) === "update") {
6267
+ if (_optionalChain([update, 'access', _137 => _137.updates, 'access', _138 => _138[key], 'optionalAccess', _139 => _139.type]) === "update") {
6234
6268
  const val = update.node.get(key);
6235
6269
  if (val !== void 0) {
6236
6270
  newState[key] = lsonToJson(val);
6237
6271
  }
6238
- } else if (_optionalChain([update, 'access', _138 => _138.updates, 'access', _139 => _139[key], 'optionalAccess', _140 => _140.type]) === "delete") {
6272
+ } else if (_optionalChain([update, 'access', _140 => _140.updates, 'access', _141 => _141[key], 'optionalAccess', _142 => _142.type]) === "delete") {
6239
6273
  delete newState[key];
6240
6274
  }
6241
6275
  }
@@ -6296,12 +6330,12 @@ function legacy_patchImmutableNode(state, path, update) {
6296
6330
  }
6297
6331
  const newState = Object.assign({}, state);
6298
6332
  for (const key in update.updates) {
6299
- if (_optionalChain([update, 'access', _141 => _141.updates, 'access', _142 => _142[key], 'optionalAccess', _143 => _143.type]) === "update") {
6333
+ if (_optionalChain([update, 'access', _143 => _143.updates, 'access', _144 => _144[key], 'optionalAccess', _145 => _145.type]) === "update") {
6300
6334
  const value = update.node.get(key);
6301
6335
  if (value !== void 0) {
6302
6336
  newState[key] = lsonToJson(value);
6303
6337
  }
6304
- } else if (_optionalChain([update, 'access', _144 => _144.updates, 'access', _145 => _145[key], 'optionalAccess', _146 => _146.type]) === "delete") {
6338
+ } else if (_optionalChain([update, 'access', _146 => _146.updates, 'access', _147 => _147[key], 'optionalAccess', _148 => _148.type]) === "delete") {
6305
6339
  delete newState[key];
6306
6340
  }
6307
6341
  }
@@ -6391,7 +6425,7 @@ function createCacheItem(key, asyncFunction, options) {
6391
6425
  let previousState = { isLoading: false };
6392
6426
  const eventSource2 = makeEventSource();
6393
6427
  function notify() {
6394
- const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _147 => _147.isStateEqual]), () => ( isShallowEqual));
6428
+ const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _149 => _149.isStateEqual]), () => ( isShallowEqual));
6395
6429
  if (!isEqual(previousState, state)) {
6396
6430
  previousState = state;
6397
6431
  eventSource2.notify(state);
@@ -6459,7 +6493,7 @@ function createAsyncCache(asyncFunction, options) {
6459
6493
  return create(key).get();
6460
6494
  }
6461
6495
  function getState(key) {
6462
- return _optionalChain([cache, 'access', _148 => _148.get, 'call', _149 => _149(key), 'optionalAccess', _150 => _150.getState, 'call', _151 => _151()]);
6496
+ return _optionalChain([cache, 'access', _150 => _150.get, 'call', _151 => _151(key), 'optionalAccess', _152 => _152.getState, 'call', _153 => _153()]);
6463
6497
  }
6464
6498
  function revalidate(key) {
6465
6499
  return create(key).revalidate();