@liveblocks/server 1.4.2-pre1 → 1.5.0-rc1

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
@@ -158,6 +158,14 @@ var jsonObjectYolo = jsonYolo.refine(
158
158
  // src/decoders/Op.ts
159
159
 
160
160
 
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+ var intent = _decoders.oneOf.call(void 0, ["set", "push"]);
161
169
  var updateObjectOp = _decoders.object.call(void 0, {
162
170
  type: _decoders.constant.call(void 0, _core.OpCode.UPDATE_OBJECT),
163
171
  opId: _decoders.string,
@@ -171,7 +179,7 @@ var createObjectOp = _decoders.object.call(void 0, {
171
179
  parentId: _decoders.string,
172
180
  parentKey: _decoders.string,
173
181
  data: jsonObjectYolo,
174
- intent: _decoders.optional.call(void 0, _decoders.constant.call(void 0, "set")),
182
+ intent: _decoders.optional.call(void 0, intent),
175
183
  deletedId: _decoders.optional.call(void 0, _decoders.string)
176
184
  });
177
185
  var createListOp = _decoders.object.call(void 0, {
@@ -180,7 +188,7 @@ var createListOp = _decoders.object.call(void 0, {
180
188
  id: _decoders.string,
181
189
  parentId: _decoders.string,
182
190
  parentKey: _decoders.string,
183
- intent: _decoders.optional.call(void 0, _decoders.constant.call(void 0, "set")),
191
+ intent: _decoders.optional.call(void 0, intent),
184
192
  deletedId: _decoders.optional.call(void 0, _decoders.string)
185
193
  });
186
194
  var createMapOp = _decoders.object.call(void 0, {
@@ -189,7 +197,7 @@ var createMapOp = _decoders.object.call(void 0, {
189
197
  id: _decoders.string,
190
198
  parentId: _decoders.string,
191
199
  parentKey: _decoders.string,
192
- intent: _decoders.optional.call(void 0, _decoders.constant.call(void 0, "set")),
200
+ intent: _decoders.optional.call(void 0, intent),
193
201
  deletedId: _decoders.optional.call(void 0, _decoders.string)
194
202
  });
195
203
  var createRegisterOp = _decoders.object.call(void 0, {
@@ -199,7 +207,7 @@ var createRegisterOp = _decoders.object.call(void 0, {
199
207
  parentId: _decoders.string,
200
208
  parentKey: _decoders.string,
201
209
  data: jsonYolo,
202
- intent: _decoders.optional.call(void 0, _decoders.constant.call(void 0, "set")),
210
+ intent: _decoders.optional.call(void 0, intent),
203
211
  deletedId: _decoders.optional.call(void 0, _decoders.string)
204
212
  });
205
213
  var deleteCrdtOp = _decoders.object.call(void 0, {
@@ -1294,6 +1302,16 @@ var InMemoryDriver = class {
1294
1302
  }
1295
1303
  return nextPos;
1296
1304
  }
1305
+ function get_last_sibling(parentId) {
1306
+ let lastPos;
1307
+ for (const siblingKey of revNodes.keysAt(parentId)) {
1308
+ const siblingPos = _core.asPos.call(void 0, siblingKey);
1309
+ if (lastPos === void 0 || siblingPos > lastPos) {
1310
+ lastPos = siblingPos;
1311
+ }
1312
+ }
1313
+ return lastPos;
1314
+ }
1297
1315
  async function set_child(id, node, allowOverwrite = false) {
1298
1316
  const parentNode = nodes.get(node.parentId);
1299
1317
  if (parentNode === void 0) {
@@ -1413,6 +1431,11 @@ var InMemoryDriver = class {
1413
1431
  * does not have to exist already. Positions compare lexicographically.
1414
1432
  */
1415
1433
  get_next_sibling,
1434
+ /**
1435
+ * Return the position of the last (rightmost) child under parentId, or
1436
+ * undefined if the node has no children.
1437
+ */
1438
+ get_last_sibling,
1416
1439
  /**
1417
1440
  * Insert a child node with the given id.
1418
1441
  *
@@ -1618,8 +1641,8 @@ var Storage = class {
1618
1641
  }
1619
1642
  async createChildAsListItem(op2, node) {
1620
1643
  let fix;
1621
- const intent = _nullishCoalesce(op2.intent, () => ( "insert"));
1622
- if (intent === "insert") {
1644
+ const intent2 = _nullishCoalesce(op2.intent, () => ( "insert"));
1645
+ if (intent2 === "insert") {
1623
1646
  const insertedParentKey = await this.insertIntoList(op2.id, node);
1624
1647
  if (insertedParentKey !== node.parentKey) {
1625
1648
  op2 = { ...op2, parentKey: insertedParentKey };
@@ -1631,7 +1654,7 @@ var Storage = class {
1631
1654
  return accept(op2, fix);
1632
1655
  }
1633
1656
  return accept(op2);
1634
- } else if (intent === "set") {
1657
+ } else if (intent2 === "set") {
1635
1658
  const deletedId = op2.deletedId !== void 0 && op2.deletedId !== op2.id && _optionalChain([this, 'access', _47 => _47.loadedDriver, 'access', _48 => _48.get_node, 'call', _49 => _49(op2.deletedId), 'optionalAccess', _50 => _50.parentId]) === node.parentId ? op2.deletedId : void 0;
1636
1659
  if (deletedId !== void 0) {
1637
1660
  await this.loadedDriver.delete_node(deletedId);
@@ -1648,8 +1671,26 @@ var Storage = class {
1648
1671
  }
1649
1672
  await this.loadedDriver.set_child(op2.id, node, true);
1650
1673
  return accept(op2, fix);
1674
+ } else if (intent2 === "push") {
1675
+ const lastPos = this.loadedDriver.get_last_sibling(node.parentId);
1676
+ const guessedKey = _core.asPos.call(void 0, node.parentKey);
1677
+ const pushedKey = lastPos === void 0 || guessedKey > lastPos ? guessedKey : _core.makePosition.call(void 0, lastPos);
1678
+ await this.loadedDriver.set_child(op2.id, {
1679
+ ...node,
1680
+ parentKey: pushedKey
1681
+ });
1682
+ if (pushedKey !== node.parentKey) {
1683
+ op2 = { ...op2, parentKey: pushedKey };
1684
+ fix = {
1685
+ type: _core.OpCode.SET_PARENT_KEY,
1686
+ id: op2.id,
1687
+ parentKey: pushedKey
1688
+ };
1689
+ return accept(op2, fix);
1690
+ }
1691
+ return accept(op2);
1651
1692
  } else {
1652
- return _core.assertNever.call(void 0, intent, "Invalid intent");
1693
+ return _core.assertNever.call(void 0, intent2, "Invalid intent");
1653
1694
  }
1654
1695
  }
1655
1696
  async applyDeleteObjectKeyOp(op2) {