@liveblocks/core 2.7.0-beta1 → 2.7.0-versions

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 = "2.7.0-beta1";
9
+ var PKG_VERSION = "2.7.0-versions";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1859,7 +1859,8 @@ var Batch = class {
1859
1859
  this.clearDelayTimeout();
1860
1860
  }
1861
1861
  };
1862
- function createBatchStore(batch) {
1862
+ function createBatchStore(callback, options) {
1863
+ const batch = new Batch(callback, options);
1863
1864
  const cache = /* @__PURE__ */ new Map();
1864
1865
  const eventSource2 = makeEventSource();
1865
1866
  function getCacheKey(args) {
@@ -4748,19 +4749,9 @@ function findNonSerializableValue(value, path = "") {
4748
4749
  return false;
4749
4750
  }
4750
4751
 
4751
- // src/lib/chunk.ts
4752
- function chunk(array, size) {
4753
- const chunks = [];
4754
- for (let i = 0, j = array.length; i < j; i += size) {
4755
- chunks.push(array.slice(i, i + size));
4756
- }
4757
- return chunks;
4758
- }
4759
-
4760
4752
  // src/lib/createIds.ts
4761
4753
  var THREAD_ID_PREFIX = "th";
4762
4754
  var COMMENT_ID_PREFIX = "cm";
4763
- var COMMENT_ATTACHMENT_ID_PREFIX = "at";
4764
4755
  var INBOX_NOTIFICATION_ID_PREFIX = "in";
4765
4756
  function createOptimisticId(prefix) {
4766
4757
  return `${prefix}_${nanoid()}`;
@@ -4771,9 +4762,6 @@ function createThreadId() {
4771
4762
  function createCommentId() {
4772
4763
  return createOptimisticId(COMMENT_ID_PREFIX);
4773
4764
  }
4774
- function createCommentAttachmentId() {
4775
- return createOptimisticId(COMMENT_ATTACHMENT_ID_PREFIX);
4776
- }
4777
4765
  function createInboxNotificationId() {
4778
4766
  return createOptimisticId(INBOX_NOTIFICATION_ID_PREFIX);
4779
4767
  }
@@ -5176,22 +5164,6 @@ function installBackgroundTabSpy() {
5176
5164
  };
5177
5165
  return [inBackgroundSince, unsub];
5178
5166
  }
5179
- var GET_ATTACHMENT_URLS_BATCH_DELAY = 50;
5180
- var ATTACHMENT_PART_SIZE = 5 * 1024 * 1024;
5181
- var ATTACHMENT_PART_BATCH_SIZE = 5;
5182
- function splitFileIntoParts(file) {
5183
- const parts = [];
5184
- let start = 0;
5185
- while (start < file.size) {
5186
- const end = Math.min(start + ATTACHMENT_PART_SIZE, file.size);
5187
- parts.push({
5188
- partNumber: parts.length + 1,
5189
- part: file.slice(start, end)
5190
- });
5191
- start = end;
5192
- }
5193
- return parts;
5194
- }
5195
5167
  var CommentsApiError = class extends Error {
5196
5168
  constructor(message, status, details) {
5197
5169
  super(message);
@@ -5501,6 +5473,29 @@ function createRoom(options, config) {
5501
5473
  })
5502
5474
  });
5503
5475
  }
5476
+ async function listTextVersions() {
5477
+ const authValue = await delegates.authenticate();
5478
+ return fetchClientApi(config.roomId, "/versions/", authValue, {
5479
+ method: "GET"
5480
+ });
5481
+ }
5482
+ async function getTextVersion(versionId) {
5483
+ const authValue = await delegates.authenticate();
5484
+ return fetchClientApi(
5485
+ config.roomId,
5486
+ `/y-version/${encodeURIComponent(versionId)}`,
5487
+ authValue,
5488
+ {
5489
+ method: "GET"
5490
+ }
5491
+ );
5492
+ }
5493
+ async function createTextVersion() {
5494
+ const authValue = await delegates.authenticate();
5495
+ return fetchClientApi(config.roomId, "/version", authValue, {
5496
+ method: "POST"
5497
+ });
5498
+ }
5504
5499
  function sendMessages(messages) {
5505
5500
  const serializedPayload = JSON.stringify(messages);
5506
5501
  const nonce = context.dynamicSessionInfo.current?.nonce;
@@ -6462,8 +6457,7 @@ ${Array.from(traces).join("\n\n")}`
6462
6457
  metadata,
6463
6458
  body,
6464
6459
  commentId = createCommentId(),
6465
- threadId = createThreadId(),
6466
- attachmentIds
6460
+ threadId = createThreadId()
6467
6461
  }) {
6468
6462
  const thread = await fetchCommentsJson("/threads", {
6469
6463
  method: "POST",
@@ -6474,8 +6468,7 @@ ${Array.from(traces).join("\n\n")}`
6474
6468
  id: threadId,
6475
6469
  comment: {
6476
6470
  id: commentId,
6477
- body,
6478
- attachmentIds
6471
+ body
6479
6472
  },
6480
6473
  metadata
6481
6474
  })
@@ -6521,8 +6514,7 @@ ${Array.from(traces).join("\n\n")}`
6521
6514
  async function createComment({
6522
6515
  threadId,
6523
6516
  commentId = createCommentId(),
6524
- body,
6525
- attachmentIds
6517
+ body
6526
6518
  }) {
6527
6519
  const comment = await fetchCommentsJson(
6528
6520
  `/threads/${encodeURIComponent(threadId)}/comments`,
@@ -6533,8 +6525,7 @@ ${Array.from(traces).join("\n\n")}`
6533
6525
  },
6534
6526
  body: JSON.stringify({
6535
6527
  id: commentId,
6536
- body,
6537
- attachmentIds
6528
+ body
6538
6529
  })
6539
6530
  }
6540
6531
  );
@@ -6543,8 +6534,7 @@ ${Array.from(traces).join("\n\n")}`
6543
6534
  async function editComment({
6544
6535
  threadId,
6545
6536
  commentId,
6546
- body,
6547
- attachmentIds
6537
+ body
6548
6538
  }) {
6549
6539
  const comment = await fetchCommentsJson(
6550
6540
  `/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
@@ -6556,8 +6546,7 @@ ${Array.from(traces).join("\n\n")}`
6556
6546
  "Content-Type": "application/json"
6557
6547
  },
6558
6548
  body: JSON.stringify({
6559
- body,
6560
- attachmentIds
6549
+ body
6561
6550
  })
6562
6551
  }
6563
6552
  );
@@ -6609,126 +6598,6 @@ ${Array.from(traces).join("\n\n")}`
6609
6598
  }
6610
6599
  );
6611
6600
  }
6612
- function prepareAttachment(file) {
6613
- return {
6614
- type: "localAttachment",
6615
- status: "idle",
6616
- id: createCommentAttachmentId(),
6617
- name: file.name,
6618
- size: file.size,
6619
- mimeType: file.type,
6620
- file
6621
- };
6622
- }
6623
- async function uploadAttachment(attachment, options2 = {}) {
6624
- const abortSignal = options2.signal;
6625
- const abortError = abortSignal ? new DOMException(
6626
- `Upload of attachment ${attachment.id} was aborted.`,
6627
- "AbortError"
6628
- ) : void 0;
6629
- if (abortSignal?.aborted) {
6630
- throw abortError;
6631
- }
6632
- if (attachment.size <= ATTACHMENT_PART_SIZE) {
6633
- return fetchCommentsJson(
6634
- `/attachments/${encodeURIComponent(attachment.id)}/upload/${encodeURIComponent(attachment.name)}`,
6635
- {
6636
- method: "PUT",
6637
- body: attachment.file,
6638
- signal: abortSignal
6639
- }
6640
- );
6641
- } else {
6642
- let uploadId;
6643
- const uploadedParts = [];
6644
- try {
6645
- const createMultiPartUpload = await fetchCommentsJson(
6646
- `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(attachment.name)}`,
6647
- {
6648
- method: "POST",
6649
- signal: abortSignal
6650
- }
6651
- );
6652
- uploadId = createMultiPartUpload.uploadId;
6653
- const parts = splitFileIntoParts(attachment.file);
6654
- if (abortSignal?.aborted) {
6655
- throw abortError;
6656
- }
6657
- const batches = chunk(parts, ATTACHMENT_PART_BATCH_SIZE);
6658
- for (const parts2 of batches) {
6659
- const uploadedPartsPromises = [];
6660
- for (const { part, partNumber } of parts2) {
6661
- uploadedPartsPromises.push(
6662
- fetchCommentsJson(
6663
- `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}/${encodeURIComponent(partNumber)}`,
6664
- {
6665
- method: "PUT",
6666
- body: part,
6667
- signal: abortSignal
6668
- }
6669
- )
6670
- );
6671
- }
6672
- uploadedParts.push(...await Promise.all(uploadedPartsPromises));
6673
- }
6674
- if (abortSignal?.aborted) {
6675
- throw abortError;
6676
- }
6677
- const sortedUploadedParts = uploadedParts.sort(
6678
- (a, b) => a.partNumber - b.partNumber
6679
- );
6680
- return fetchCommentsJson(
6681
- `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}/complete`,
6682
- {
6683
- method: "POST",
6684
- headers: {
6685
- "Content-Type": "application/json"
6686
- },
6687
- body: JSON.stringify({ parts: sortedUploadedParts }),
6688
- signal: abortSignal
6689
- }
6690
- );
6691
- } catch (error3) {
6692
- if (uploadId && error3?.name && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
6693
- await fetchCommentsApi(
6694
- `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}`,
6695
- void 0,
6696
- {
6697
- method: "DELETE"
6698
- }
6699
- );
6700
- }
6701
- throw error3;
6702
- }
6703
- }
6704
- }
6705
- async function getAttachmentUrls(attachmentIds) {
6706
- const { urls } = await fetchCommentsJson(
6707
- "/attachments/presigned-urls",
6708
- {
6709
- method: "POST",
6710
- headers: {
6711
- "Content-Type": "application/json"
6712
- },
6713
- body: JSON.stringify({ attachmentIds })
6714
- }
6715
- );
6716
- return urls;
6717
- }
6718
- const batchedGetAttachmentUrls = new Batch(
6719
- async (batchedAttachmentIds) => {
6720
- const attachmentIds = batchedAttachmentIds.flat();
6721
- const attachmentUrls = await getAttachmentUrls(attachmentIds);
6722
- return attachmentUrls.map(
6723
- (url) => url ?? new Error("There was an error while getting this attachment's URL")
6724
- );
6725
- },
6726
- { delay: GET_ATTACHMENT_URLS_BATCH_DELAY }
6727
- );
6728
- const attachmentUrlsStore = createBatchStore(batchedGetAttachmentUrls);
6729
- function getAttachmentUrl(attachmentId) {
6730
- return batchedGetAttachmentUrls.get(attachmentId);
6731
- }
6732
6601
  async function fetchNotificationsJson(endpoint, options2) {
6733
6602
  const authValue = await delegates.authenticate();
6734
6603
  const response = await fetchClientApi(
@@ -6830,6 +6699,12 @@ ${Array.from(traces).join("\n\n")}`
6830
6699
  createTextMention,
6831
6700
  // delete a text mention when using a text editor
6832
6701
  deleteTextMention,
6702
+ // list versions of the document
6703
+ listTextVersions,
6704
+ // get a specific version
6705
+ getTextVersion,
6706
+ // create a version
6707
+ createTextVersion,
6833
6708
  // Support for the Liveblocks browser extension
6834
6709
  getSelf_forDevTools: () => selfAsTreeNode.current,
6835
6710
  getOthers_forDevTools: () => others_forDevTools.current,
@@ -6838,8 +6713,7 @@ ${Array.from(traces).join("\n\n")}`
6838
6713
  // These exist only for our E2E testing app
6839
6714
  explicitClose: (event) => managedSocket._privateSendMachineEvent({ type: "EXPLICIT_SOCKET_CLOSE", event }),
6840
6715
  rawSend: (data) => managedSocket.send(data)
6841
- },
6842
- attachmentUrlsStore
6716
+ }
6843
6717
  },
6844
6718
  id: config.roomId,
6845
6719
  subscribe: makeClassicSubscribeFn(events),
@@ -6894,9 +6768,6 @@ ${Array.from(traces).join("\n\n")}`
6894
6768
  deleteComment: deleteComment2,
6895
6769
  addReaction: addReaction2,
6896
6770
  removeReaction: removeReaction2,
6897
- prepareAttachment,
6898
- uploadAttachment,
6899
- getAttachmentUrl,
6900
6771
  // Notifications
6901
6772
  getNotificationSettings,
6902
6773
  updateNotificationSettings,
@@ -7036,7 +6907,8 @@ function createClientStore() {
7036
6907
  queries: {},
7037
6908
  optimisticUpdates: [],
7038
6909
  inboxNotifications: {},
7039
- notificationSettings: {}
6910
+ notificationSettings: {},
6911
+ versions: {}
7040
6912
  });
7041
6913
  const optimisticUpdatesEventSource = makeEventSource();
7042
6914
  return {
@@ -7067,6 +6939,19 @@ function createClientStore() {
7067
6939
  };
7068
6940
  });
7069
6941
  },
6942
+ updateRoomVersions(roomId, versions, queryKey) {
6943
+ store.set((state) => ({
6944
+ ...state,
6945
+ versions: {
6946
+ ...state.versions,
6947
+ [roomId]: versions
6948
+ },
6949
+ queries: queryKey !== void 0 ? {
6950
+ ...state.queries,
6951
+ [queryKey]: { isLoading: false, data: void 0 }
6952
+ } : state.queries
6953
+ }));
6954
+ },
7070
6955
  updateThreadsAndNotifications(threads, inboxNotifications, deletedThreads, deletedInboxNotifications, queryKey) {
7071
6956
  store.set((state) => ({
7072
6957
  ...state,
@@ -7691,7 +7576,7 @@ function createClient(options) {
7691
7576
  () => !resolveUsers,
7692
7577
  "Set the resolveUsers option in createClient to specify user info."
7693
7578
  );
7694
- const batchedResolveUsers = new Batch(
7579
+ const usersStore = createBatchStore(
7695
7580
  async (batchedUserIds) => {
7696
7581
  const userIds = batchedUserIds.flat();
7697
7582
  const users = await resolveUsers?.({ userIds });
@@ -7700,13 +7585,12 @@ function createClient(options) {
7700
7585
  },
7701
7586
  { delay: RESOLVE_USERS_BATCH_DELAY }
7702
7587
  );
7703
- const usersStore = createBatchStore(batchedResolveUsers);
7704
7588
  const resolveRoomsInfo = clientOptions.resolveRoomsInfo;
7705
7589
  const warnIfNoResolveRoomsInfo = createDevelopmentWarning(
7706
7590
  () => !resolveRoomsInfo,
7707
7591
  "Set the resolveRoomsInfo option in createClient to specify room info."
7708
7592
  );
7709
- const batchedResolveRoomsInfo = new Batch(
7593
+ const roomsInfoStore = createBatchStore(
7710
7594
  async (batchedRoomIds) => {
7711
7595
  const roomIds = batchedRoomIds.flat();
7712
7596
  const roomsInfo = await resolveRoomsInfo?.({ roomIds });
@@ -7715,7 +7599,6 @@ function createClient(options) {
7715
7599
  },
7716
7600
  { delay: RESOLVE_ROOMS_INFO_BATCH_DELAY }
7717
7601
  );
7718
- const roomsInfoStore = createBatchStore(batchedResolveRoomsInfo);
7719
7602
  return Object.defineProperty(
7720
7603
  {
7721
7604
  enterRoom,
@@ -8621,7 +8504,6 @@ export {
8621
8504
  assert,
8622
8505
  assertNever,
8623
8506
  b64decode,
8624
- chunk,
8625
8507
  cloneLson,
8626
8508
  fancy_console_exports as console,
8627
8509
  convertToCommentData,