@liveblocks/core 3.13.0-ack1 → 3.13.0-metadata1

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.cjs 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 = "3.13.0-ack1";
9
+ var PKG_VERSION = "3.13.0-metadata1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1606,6 +1606,7 @@ function createApiClient({
1606
1606
  comment: {
1607
1607
  id: commentId,
1608
1608
  body: options.body,
1609
+ metadata: options.commentMetadata,
1609
1610
  attachmentIds: options.attachmentIds
1610
1611
  },
1611
1612
  metadata: options.metadata
@@ -1659,6 +1660,16 @@ function createApiClient({
1659
1660
  options.metadata
1660
1661
  );
1661
1662
  }
1663
+ async function editCommentMetadata(options) {
1664
+ return await httpClient.post(
1665
+ url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}/metadata`,
1666
+ await authManager.getAuthValue({
1667
+ requestedScope: "comments:read",
1668
+ roomId: options.roomId
1669
+ }),
1670
+ options.metadata
1671
+ );
1672
+ }
1662
1673
  async function createComment(options) {
1663
1674
  const commentId = _nullishCoalesce(options.commentId, () => ( createCommentId()));
1664
1675
  const comment = await httpClient.post(
@@ -1670,6 +1681,7 @@ function createApiClient({
1670
1681
  {
1671
1682
  id: commentId,
1672
1683
  body: options.body,
1684
+ metadata: options.metadata,
1673
1685
  attachmentIds: options.attachmentIds
1674
1686
  }
1675
1687
  );
@@ -1684,7 +1696,8 @@ function createApiClient({
1684
1696
  }),
1685
1697
  {
1686
1698
  body: options.body,
1687
- attachmentIds: options.attachmentIds
1699
+ attachmentIds: options.attachmentIds,
1700
+ metadata: options.metadata
1688
1701
  }
1689
1702
  );
1690
1703
  return convertToCommentData(comment);
@@ -2426,6 +2439,7 @@ function createApiClient({
2426
2439
  editThreadMetadata,
2427
2440
  createComment,
2428
2441
  editComment,
2442
+ editCommentMetadata,
2429
2443
  deleteComment,
2430
2444
  addReaction,
2431
2445
  removeReaction,
@@ -3092,7 +3106,6 @@ var ServerMsgCode = Object.freeze({
3092
3106
  // For Storage
3093
3107
  INITIAL_STORAGE_STATE: 200,
3094
3108
  UPDATE_STORAGE: 201,
3095
- STORAGE_ACK: 202,
3096
3109
  // For Yjs Docs
3097
3110
  UPDATE_YDOC: 300,
3098
3111
  // For Comments
@@ -3105,6 +3118,7 @@ var ServerMsgCode = Object.freeze({
3105
3118
  COMMENT_DELETED: 404,
3106
3119
  COMMENT_REACTION_ADDED: 405,
3107
3120
  COMMENT_REACTION_REMOVED: 406,
3121
+ COMMENT_METADATA_UPDATED: 409,
3108
3122
  // Error codes
3109
3123
  REJECT_STORAGE_OP: 299
3110
3124
  // Sent if a mutation was not allowed on the server (i.e. due to permissions, limit exceeded, etc)
@@ -5927,6 +5941,10 @@ var OpCode = Object.freeze({
5927
5941
  ACK: 9
5928
5942
  // Will only appear in v8+
5929
5943
  });
5944
+ function isAck(op) {
5945
+ return op.type === OpCode.ACK || // >= v8
5946
+ op.type === OpCode.DELETE_CRDT && op.id === "ACK";
5947
+ }
5930
5948
 
5931
5949
  // src/crdts/AbstractCrdt.ts
5932
5950
  function createManagedPool(roomId, options) {
@@ -6381,7 +6399,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6381
6399
  };
6382
6400
  }
6383
6401
  }
6384
- #applySetFixop(op) {
6402
+ #applySetAck(op) {
6385
6403
  if (this._pool === void 0) {
6386
6404
  throw new Error("Can't attach child if managed pool is not present");
6387
6405
  }
@@ -6491,7 +6509,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6491
6509
  reverse: []
6492
6510
  };
6493
6511
  }
6494
- #applyInsertFixop(op) {
6512
+ #applyInsertAck(op) {
6495
6513
  const existingItem = this.#items.find((item) => item._id === op.id);
6496
6514
  const key = asPos(op.parentKey);
6497
6515
  const itemIndexAtPosition = this._indexOfPosition(key);
@@ -6613,16 +6631,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
6613
6631
  if (op.intent === "set") {
6614
6632
  if (source === 1 /* REMOTE */) {
6615
6633
  result = this.#applySetRemote(op);
6616
- } else if (source === 2 /* FIXOP */) {
6617
- result = this.#applySetFixop(op);
6634
+ } else if (source === 2 /* ACK */) {
6635
+ result = this.#applySetAck(op);
6618
6636
  } else {
6619
6637
  result = this.#applySetUndoRedo(op);
6620
6638
  }
6621
6639
  } else {
6622
6640
  if (source === 1 /* REMOTE */) {
6623
6641
  result = this.#applyRemoteInsert(op);
6624
- } else if (source === 2 /* FIXOP */) {
6625
- result = this.#applyInsertFixop(op);
6642
+ } else if (source === 2 /* ACK */) {
6643
+ result = this.#applyInsertAck(op);
6626
6644
  } else {
6627
6645
  result = this.#applyInsertUndoRedo(op);
6628
6646
  }
@@ -6705,7 +6723,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6705
6723
  };
6706
6724
  }
6707
6725
  }
6708
- #applySetChildKeyFixop(newKey, child) {
6726
+ #applySetChildKeyAck(newKey, child) {
6709
6727
  const previousKey = nn(child._parentKey);
6710
6728
  if (this.#implicitlyDeletedItems.has(child)) {
6711
6729
  const existingItemIndex = this._indexOfPosition(newKey);
@@ -6786,8 +6804,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6786
6804
  _setChildKey(newKey, child, source) {
6787
6805
  if (source === 1 /* REMOTE */) {
6788
6806
  return this.#applySetChildKeyRemote(newKey, child);
6789
- } else if (source === 2 /* FIXOP */) {
6790
- return this.#applySetChildKeyFixop(newKey, child);
6807
+ } else if (source === 2 /* ACK */) {
6808
+ return this.#applySetChildKeyAck(newKey, child);
6791
6809
  } else {
6792
6810
  return this.#applySetChildKeyUndoRedo(newKey, child);
6793
6811
  }
@@ -7300,7 +7318,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7300
7318
  if (this._pool.getNode(id) !== void 0) {
7301
7319
  return { modified: false };
7302
7320
  }
7303
- if (source === 2 /* FIXOP */) {
7321
+ if (source === 2 /* ACK */) {
7304
7322
  const lastUpdateOpId = this.#unacknowledgedSet.get(key);
7305
7323
  if (lastUpdateOpId === opId) {
7306
7324
  this.#unacknowledgedSet.delete(key);
@@ -7701,7 +7719,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7701
7719
  }
7702
7720
  return { modified: false };
7703
7721
  }
7704
- if (source === 0 /* LOCAL */) {
7722
+ if (source === 0 /* UNDOREDO_RECONNECT */) {
7705
7723
  this.#propToLastUpdate.set(key, nn(opId));
7706
7724
  } else if (this.#propToLastUpdate.get(key) === void 0) {
7707
7725
  } else if (this.#propToLastUpdate.get(key) === opId) {
@@ -8660,6 +8678,8 @@ function defaultMessageFromContext(context) {
8660
8678
  return "Could not delete thread";
8661
8679
  case "EDIT_THREAD_METADATA_ERROR":
8662
8680
  return "Could not edit thread metadata";
8681
+ case "EDIT_COMMENT_METADATA_ERROR":
8682
+ return "Could not edit comment metadata";
8663
8683
  case "MARK_THREAD_AS_RESOLVED_ERROR":
8664
8684
  return "Could not mark thread as resolved";
8665
8685
  case "MARK_THREAD_AS_UNRESOLVED_ERROR":
@@ -9107,11 +9127,7 @@ function createRoom(options, config) {
9107
9127
  currentItems.set(id, node._serialize());
9108
9128
  }
9109
9129
  const ops = getTreesDiffOperations(currentItems, new Map(items));
9110
- const result = applyOps(
9111
- ops,
9112
- /* isLocal */
9113
- false
9114
- );
9130
+ const result = applyOps(ops, false);
9115
9131
  notify(result.updates);
9116
9132
  }
9117
9133
  function _addToRealUndoStack(historyOps) {
@@ -9192,12 +9208,11 @@ function createRoom(options, config) {
9192
9208
  } else {
9193
9209
  let source;
9194
9210
  if (isLocal) {
9195
- source = 0 /* LOCAL */;
9196
- } else if (op.opId) {
9197
- context.unacknowledgedOps.delete(op.opId);
9198
- source = 2 /* FIXOP */;
9211
+ source = 0 /* UNDOREDO_RECONNECT */;
9199
9212
  } else {
9200
- source = 1 /* REMOTE */;
9213
+ const opId = nn(op.opId);
9214
+ const deleted = context.unacknowledgedOps.delete(opId);
9215
+ source = deleted ? 2 /* ACK */ : 1 /* REMOTE */;
9201
9216
  }
9202
9217
  const applyOpResult = applyOp(op, source);
9203
9218
  if (applyOpResult.modified) {
@@ -9228,6 +9243,9 @@ function createRoom(options, config) {
9228
9243
  };
9229
9244
  }
9230
9245
  function applyOp(op, source) {
9246
+ if (isAck(op)) {
9247
+ return { modified: false };
9248
+ }
9231
9249
  switch (op.type) {
9232
9250
  case OpCode.DELETE_OBJECT_KEY:
9233
9251
  case OpCode.UPDATE_OBJECT:
@@ -9236,7 +9254,7 @@ function createRoom(options, config) {
9236
9254
  if (node === void 0) {
9237
9255
  return { modified: false };
9238
9256
  }
9239
- return node._apply(op, source === 0 /* LOCAL */);
9257
+ return node._apply(op, source === 0 /* UNDOREDO_RECONNECT */);
9240
9258
  }
9241
9259
  case OpCode.SET_PARENT_KEY: {
9242
9260
  const node = context.pool.nodes.get(op.id);
@@ -9407,11 +9425,7 @@ function createRoom(options, config) {
9407
9425
  }
9408
9426
  const messages = [];
9409
9427
  const inOps = Array.from(offlineOps.values());
9410
- const result = applyOps(
9411
- inOps,
9412
- /* isLocal */
9413
- true
9414
- );
9428
+ const result = applyOps(inOps, true);
9415
9429
  messages.push({
9416
9430
  type: ClientMsgCode.UPDATE_STORAGE,
9417
9431
  ops: result.ops
@@ -9475,12 +9489,9 @@ function createRoom(options, config) {
9475
9489
  processInitialStorage(message);
9476
9490
  break;
9477
9491
  }
9492
+ // Write event
9478
9493
  case ServerMsgCode.UPDATE_STORAGE: {
9479
- const applyResult = applyOps(
9480
- message.ops,
9481
- /* isLocal */
9482
- false
9483
- );
9494
+ const applyResult = applyOps(message.ops, false);
9484
9495
  for (const [key, value] of applyResult.updates.storageUpdates) {
9485
9496
  updates.storageUpdates.set(
9486
9497
  key,
@@ -9489,14 +9500,6 @@ function createRoom(options, config) {
9489
9500
  }
9490
9501
  break;
9491
9502
  }
9492
- // Since V8. On V7, acks were sent disguised as an Ops in UPDATE_STORAGE messages.
9493
- case ServerMsgCode.STORAGE_ACK: {
9494
- for (const opId of message.opIds) {
9495
- context.unacknowledgedOps.delete(opId);
9496
- }
9497
- notifyStorageStatus();
9498
- break;
9499
- }
9500
9503
  // Receiving a RejectedOps message in the client means that the server is no
9501
9504
  // longer in sync with the client. Trying to synchronize the client again by
9502
9505
  // rolling back particular Ops may be hard/impossible. It's fine to not try and
@@ -9521,7 +9524,8 @@ function createRoom(options, config) {
9521
9524
  case ServerMsgCode.COMMENT_REACTION_REMOVED:
9522
9525
  case ServerMsgCode.COMMENT_CREATED:
9523
9526
  case ServerMsgCode.COMMENT_EDITED:
9524
- case ServerMsgCode.COMMENT_DELETED: {
9527
+ case ServerMsgCode.COMMENT_DELETED:
9528
+ case ServerMsgCode.COMMENT_METADATA_UPDATED: {
9525
9529
  eventHub.comments.notify(message);
9526
9530
  break;
9527
9531
  }
@@ -9702,11 +9706,7 @@ function createRoom(options, config) {
9702
9706
  return;
9703
9707
  }
9704
9708
  context.pausedHistory = null;
9705
- const result = applyOps(
9706
- historyOps,
9707
- /* isLocal */
9708
- true
9709
- );
9709
+ const result = applyOps(historyOps, true);
9710
9710
  notify(result.updates);
9711
9711
  context.redoStack.push(result.reverse);
9712
9712
  onHistoryChange();
@@ -9726,11 +9726,7 @@ function createRoom(options, config) {
9726
9726
  return;
9727
9727
  }
9728
9728
  context.pausedHistory = null;
9729
- const result = applyOps(
9730
- historyOps,
9731
- /* isLocal */
9732
- true
9733
- );
9729
+ const result = applyOps(historyOps, true);
9734
9730
  notify(result.updates);
9735
9731
  context.undoStack.push(result.reverse);
9736
9732
  onHistoryChange();
@@ -9873,6 +9869,7 @@ function createRoom(options, config) {
9873
9869
  commentId: options2.commentId,
9874
9870
  metadata: options2.metadata,
9875
9871
  body: options2.body,
9872
+ commentMetadata: options2.commentMetadata,
9876
9873
  attachmentIds: options2.attachmentIds
9877
9874
  });
9878
9875
  }
@@ -9885,6 +9882,18 @@ function createRoom(options, config) {
9885
9882
  }) {
9886
9883
  return httpClient.editThreadMetadata({ roomId, threadId, metadata });
9887
9884
  }
9885
+ async function editCommentMetadata({
9886
+ threadId,
9887
+ commentId,
9888
+ metadata
9889
+ }) {
9890
+ return httpClient.editCommentMetadata({
9891
+ roomId,
9892
+ threadId,
9893
+ commentId,
9894
+ metadata
9895
+ });
9896
+ }
9888
9897
  async function markThreadAsResolved(threadId) {
9889
9898
  return httpClient.markThreadAsResolved({ roomId, threadId });
9890
9899
  }
@@ -9906,6 +9915,7 @@ function createRoom(options, config) {
9906
9915
  threadId: options2.threadId,
9907
9916
  commentId: options2.commentId,
9908
9917
  body: options2.body,
9918
+ metadata: options2.metadata,
9909
9919
  attachmentIds: options2.attachmentIds
9910
9920
  });
9911
9921
  }
@@ -9915,6 +9925,7 @@ function createRoom(options, config) {
9915
9925
  threadId: options2.threadId,
9916
9926
  commentId: options2.commentId,
9917
9927
  body: options2.body,
9928
+ metadata: options2.metadata,
9918
9929
  attachmentIds: options2.attachmentIds
9919
9930
  });
9920
9931
  }
@@ -10102,6 +10113,7 @@ function createRoom(options, config) {
10102
10113
  unsubscribeFromThread,
10103
10114
  createComment,
10104
10115
  editComment,
10116
+ editCommentMetadata,
10105
10117
  deleteComment,
10106
10118
  addReaction,
10107
10119
  removeReaction,
@@ -10234,7 +10246,7 @@ function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
10234
10246
  }
10235
10247
  const url2 = new URL(baseUrl);
10236
10248
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
10237
- url2.pathname = "/v8";
10249
+ url2.pathname = "/v7";
10238
10250
  url2.searchParams.set("roomId", roomId);
10239
10251
  if (authValue.type === "secret") {
10240
10252
  url2.searchParams.set("tok", authValue.token.raw);