@liveblocks/core 3.12.1 → 3.13.0-ack1

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.12.1";
9
+ var PKG_VERSION = "3.13.0-ack1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -3092,6 +3092,7 @@ var ServerMsgCode = Object.freeze({
3092
3092
  // For Storage
3093
3093
  INITIAL_STORAGE_STATE: 200,
3094
3094
  UPDATE_STORAGE: 201,
3095
+ STORAGE_ACK: 202,
3095
3096
  // For Yjs Docs
3096
3097
  UPDATE_YDOC: 300,
3097
3098
  // For Comments
@@ -5926,10 +5927,6 @@ var OpCode = Object.freeze({
5926
5927
  ACK: 9
5927
5928
  // Will only appear in v8+
5928
5929
  });
5929
- function isAck(op) {
5930
- return op.type === OpCode.ACK || // >= v8
5931
- op.type === OpCode.DELETE_CRDT && op.id === "ACK";
5932
- }
5933
5930
 
5934
5931
  // src/crdts/AbstractCrdt.ts
5935
5932
  function createManagedPool(roomId, options) {
@@ -6384,7 +6381,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6384
6381
  };
6385
6382
  }
6386
6383
  }
6387
- #applySetAck(op) {
6384
+ #applySetFixop(op) {
6388
6385
  if (this._pool === void 0) {
6389
6386
  throw new Error("Can't attach child if managed pool is not present");
6390
6387
  }
@@ -6494,7 +6491,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6494
6491
  reverse: []
6495
6492
  };
6496
6493
  }
6497
- #applyInsertAck(op) {
6494
+ #applyInsertFixop(op) {
6498
6495
  const existingItem = this.#items.find((item) => item._id === op.id);
6499
6496
  const key = asPos(op.parentKey);
6500
6497
  const itemIndexAtPosition = this._indexOfPosition(key);
@@ -6616,16 +6613,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
6616
6613
  if (op.intent === "set") {
6617
6614
  if (source === 1 /* REMOTE */) {
6618
6615
  result = this.#applySetRemote(op);
6619
- } else if (source === 2 /* ACK */) {
6620
- result = this.#applySetAck(op);
6616
+ } else if (source === 2 /* FIXOP */) {
6617
+ result = this.#applySetFixop(op);
6621
6618
  } else {
6622
6619
  result = this.#applySetUndoRedo(op);
6623
6620
  }
6624
6621
  } else {
6625
6622
  if (source === 1 /* REMOTE */) {
6626
6623
  result = this.#applyRemoteInsert(op);
6627
- } else if (source === 2 /* ACK */) {
6628
- result = this.#applyInsertAck(op);
6624
+ } else if (source === 2 /* FIXOP */) {
6625
+ result = this.#applyInsertFixop(op);
6629
6626
  } else {
6630
6627
  result = this.#applyInsertUndoRedo(op);
6631
6628
  }
@@ -6708,7 +6705,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6708
6705
  };
6709
6706
  }
6710
6707
  }
6711
- #applySetChildKeyAck(newKey, child) {
6708
+ #applySetChildKeyFixop(newKey, child) {
6712
6709
  const previousKey = nn(child._parentKey);
6713
6710
  if (this.#implicitlyDeletedItems.has(child)) {
6714
6711
  const existingItemIndex = this._indexOfPosition(newKey);
@@ -6789,8 +6786,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6789
6786
  _setChildKey(newKey, child, source) {
6790
6787
  if (source === 1 /* REMOTE */) {
6791
6788
  return this.#applySetChildKeyRemote(newKey, child);
6792
- } else if (source === 2 /* ACK */) {
6793
- return this.#applySetChildKeyAck(newKey, child);
6789
+ } else if (source === 2 /* FIXOP */) {
6790
+ return this.#applySetChildKeyFixop(newKey, child);
6794
6791
  } else {
6795
6792
  return this.#applySetChildKeyUndoRedo(newKey, child);
6796
6793
  }
@@ -7303,7 +7300,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7303
7300
  if (this._pool.getNode(id) !== void 0) {
7304
7301
  return { modified: false };
7305
7302
  }
7306
- if (source === 2 /* ACK */) {
7303
+ if (source === 2 /* FIXOP */) {
7307
7304
  const lastUpdateOpId = this.#unacknowledgedSet.get(key);
7308
7305
  if (lastUpdateOpId === opId) {
7309
7306
  this.#unacknowledgedSet.delete(key);
@@ -7704,7 +7701,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7704
7701
  }
7705
7702
  return { modified: false };
7706
7703
  }
7707
- if (source === 0 /* UNDOREDO_RECONNECT */) {
7704
+ if (source === 0 /* LOCAL */) {
7708
7705
  this.#propToLastUpdate.set(key, nn(opId));
7709
7706
  } else if (this.#propToLastUpdate.get(key) === void 0) {
7710
7707
  } else if (this.#propToLastUpdate.get(key) === opId) {
@@ -9110,7 +9107,11 @@ function createRoom(options, config) {
9110
9107
  currentItems.set(id, node._serialize());
9111
9108
  }
9112
9109
  const ops = getTreesDiffOperations(currentItems, new Map(items));
9113
- const result = applyOps(ops, false);
9110
+ const result = applyOps(
9111
+ ops,
9112
+ /* isLocal */
9113
+ false
9114
+ );
9114
9115
  notify(result.updates);
9115
9116
  }
9116
9117
  function _addToRealUndoStack(historyOps) {
@@ -9191,11 +9192,12 @@ function createRoom(options, config) {
9191
9192
  } else {
9192
9193
  let source;
9193
9194
  if (isLocal) {
9194
- source = 0 /* UNDOREDO_RECONNECT */;
9195
+ source = 0 /* LOCAL */;
9196
+ } else if (op.opId) {
9197
+ context.unacknowledgedOps.delete(op.opId);
9198
+ source = 2 /* FIXOP */;
9195
9199
  } else {
9196
- const opId = nn(op.opId);
9197
- const deleted = context.unacknowledgedOps.delete(opId);
9198
- source = deleted ? 2 /* ACK */ : 1 /* REMOTE */;
9200
+ source = 1 /* REMOTE */;
9199
9201
  }
9200
9202
  const applyOpResult = applyOp(op, source);
9201
9203
  if (applyOpResult.modified) {
@@ -9226,9 +9228,6 @@ function createRoom(options, config) {
9226
9228
  };
9227
9229
  }
9228
9230
  function applyOp(op, source) {
9229
- if (isAck(op)) {
9230
- return { modified: false };
9231
- }
9232
9231
  switch (op.type) {
9233
9232
  case OpCode.DELETE_OBJECT_KEY:
9234
9233
  case OpCode.UPDATE_OBJECT:
@@ -9237,7 +9236,7 @@ function createRoom(options, config) {
9237
9236
  if (node === void 0) {
9238
9237
  return { modified: false };
9239
9238
  }
9240
- return node._apply(op, source === 0 /* UNDOREDO_RECONNECT */);
9239
+ return node._apply(op, source === 0 /* LOCAL */);
9241
9240
  }
9242
9241
  case OpCode.SET_PARENT_KEY: {
9243
9242
  const node = context.pool.nodes.get(op.id);
@@ -9408,7 +9407,11 @@ function createRoom(options, config) {
9408
9407
  }
9409
9408
  const messages = [];
9410
9409
  const inOps = Array.from(offlineOps.values());
9411
- const result = applyOps(inOps, true);
9410
+ const result = applyOps(
9411
+ inOps,
9412
+ /* isLocal */
9413
+ true
9414
+ );
9412
9415
  messages.push({
9413
9416
  type: ClientMsgCode.UPDATE_STORAGE,
9414
9417
  ops: result.ops
@@ -9472,9 +9475,12 @@ function createRoom(options, config) {
9472
9475
  processInitialStorage(message);
9473
9476
  break;
9474
9477
  }
9475
- // Write event
9476
9478
  case ServerMsgCode.UPDATE_STORAGE: {
9477
- const applyResult = applyOps(message.ops, false);
9479
+ const applyResult = applyOps(
9480
+ message.ops,
9481
+ /* isLocal */
9482
+ false
9483
+ );
9478
9484
  for (const [key, value] of applyResult.updates.storageUpdates) {
9479
9485
  updates.storageUpdates.set(
9480
9486
  key,
@@ -9483,6 +9489,14 @@ function createRoom(options, config) {
9483
9489
  }
9484
9490
  break;
9485
9491
  }
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
+ }
9486
9500
  // Receiving a RejectedOps message in the client means that the server is no
9487
9501
  // longer in sync with the client. Trying to synchronize the client again by
9488
9502
  // rolling back particular Ops may be hard/impossible. It's fine to not try and
@@ -9688,7 +9702,11 @@ function createRoom(options, config) {
9688
9702
  return;
9689
9703
  }
9690
9704
  context.pausedHistory = null;
9691
- const result = applyOps(historyOps, true);
9705
+ const result = applyOps(
9706
+ historyOps,
9707
+ /* isLocal */
9708
+ true
9709
+ );
9692
9710
  notify(result.updates);
9693
9711
  context.redoStack.push(result.reverse);
9694
9712
  onHistoryChange();
@@ -9708,7 +9726,11 @@ function createRoom(options, config) {
9708
9726
  return;
9709
9727
  }
9710
9728
  context.pausedHistory = null;
9711
- const result = applyOps(historyOps, true);
9729
+ const result = applyOps(
9730
+ historyOps,
9731
+ /* isLocal */
9732
+ true
9733
+ );
9712
9734
  notify(result.updates);
9713
9735
  context.undoStack.push(result.reverse);
9714
9736
  onHistoryChange();
@@ -10212,7 +10234,7 @@ function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
10212
10234
  }
10213
10235
  const url2 = new URL(baseUrl);
10214
10236
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
10215
- url2.pathname = "/v7";
10237
+ url2.pathname = "/v8";
10216
10238
  url2.searchParams.set("roomId", roomId);
10217
10239
  if (authValue.type === "secret") {
10218
10240
  url2.searchParams.set("tok", authValue.token.raw);