@liveblocks/client 0.17.0-test1 → 0.17.1

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/shared.js CHANGED
@@ -945,14 +945,14 @@ var LiveList = (function (_AbstractCrdt) {
945
945
  var parentKey = nn(child._parentKey),
946
946
  reverse = child._serialize(nn(this._id), parentKey, this._doc),
947
947
  indexToDelete = this._items.indexOf(child);
948
- return (
949
- this._items.splice(indexToDelete, 1),
950
- child._detach(),
951
- {
952
- modified: makeUpdate(this, [deleteDelta(indexToDelete)]),
953
- reverse: reverse,
954
- }
955
- );
948
+ return -1 === indexToDelete
949
+ ? { modified: !1 }
950
+ : (this._items.splice(indexToDelete, 1),
951
+ child._detach(),
952
+ {
953
+ modified: makeUpdate(this, [deleteDelta(indexToDelete)]),
954
+ reverse: reverse,
955
+ });
956
956
  }
957
957
  return { modified: !1 };
958
958
  }),
@@ -1448,10 +1448,12 @@ var LiveMap = (function (_AbstractCrdt) {
1448
1448
  var _this;
1449
1449
  if (
1450
1450
  (((_this = _AbstractCrdt.call(this) || this)._map = void 0),
1451
+ (_this.unacknowledgedSet = void 0),
1451
1452
  errorIf(
1452
1453
  null === entries,
1453
1454
  "Support for calling `new LiveMap(null)` will be removed in @liveblocks/client 0.18. Please call as `new LiveMap()`, or `new LiveMap([])`."
1454
1455
  ),
1456
+ (_this.unacknowledgedSet = new Map()),
1455
1457
  entries)
1456
1458
  ) {
1457
1459
  for (
@@ -1531,14 +1533,24 @@ var LiveMap = (function (_AbstractCrdt) {
1531
1533
  isLiveNode(_value3) && _value3._attach(doc.generateId(), doc);
1532
1534
  }
1533
1535
  }),
1534
- (_proto._attachChild = function (op) {
1536
+ (_proto._attachChild = function (op, source) {
1535
1537
  var _updates;
1536
1538
  if (null == this._doc)
1537
1539
  throw new Error("Can't attach child if doc is not present");
1538
1540
  var id = op.id,
1539
- key = op.parentKey,
1541
+ parentKey = op.parentKey,
1542
+ opId = op.opId,
1543
+ key = parentKey,
1540
1544
  child = creationOpToLiveNode(op);
1541
1545
  if (void 0 !== this._doc.getItem(id)) return { modified: !1 };
1546
+ if (source === exports.OpSource.ACK) {
1547
+ var lastUpdateOpId = this.unacknowledgedSet.get(key);
1548
+ if (lastUpdateOpId === opId)
1549
+ return this.unacknowledgedSet.delete(key), { modified: !1 };
1550
+ if (null != lastUpdateOpId) return { modified: !1 };
1551
+ } else
1552
+ source === exports.OpSource.REMOTE &&
1553
+ this.unacknowledgedSet.delete(key);
1542
1554
  var reverse,
1543
1555
  previousValue = this._map.get(key);
1544
1556
  if (previousValue) {
@@ -1637,7 +1649,9 @@ var LiveMap = (function (_AbstractCrdt) {
1637
1649
  ((_updates3 = {}),
1638
1650
  (_updates3[key] = { type: "update" }),
1639
1651
  _updates3),
1640
- }),
1652
+ });
1653
+ var ops = item._serialize(this._id, key, this._doc);
1654
+ this.unacknowledgedSet.set(key, nn(ops[0].opId)),
1641
1655
  this._doc.dispatch(
1642
1656
  item._serialize(this._id, key, this._doc),
1643
1657
  oldValue
@@ -2385,9 +2399,6 @@ function isRoomAuthToken(data) {
2385
2399
  "number" == typeof data.maxConnectionsPerRoom)
2386
2400
  );
2387
2401
  }
2388
- function isAuthToken(data) {
2389
- return isAppOnlyAuthToken(data) || isRoomAuthToken(data);
2390
- }
2391
2402
  function parseJwtToken(token) {
2392
2403
  var tokenParts = token.split(".");
2393
2404
  if (3 !== tokenParts.length)
@@ -2542,7 +2553,9 @@ function isJsonArray(data) {
2542
2553
  );
2543
2554
  }),
2544
2555
  (exports.isAppOnlyAuthToken = isAppOnlyAuthToken),
2545
- (exports.isAuthToken = isAuthToken),
2556
+ (exports.isAuthToken = function (data) {
2557
+ return isAppOnlyAuthToken(data) || isRoomAuthToken(data);
2558
+ }),
2546
2559
  (exports.isChildCrdt = isChildCrdt),
2547
2560
  (exports.isJsonArray = isJsonArray),
2548
2561
  (exports.isJsonObject = function (data) {
@@ -2554,6 +2567,15 @@ function isJsonArray(data) {
2554
2567
  (exports.isLiveObject = isLiveObject),
2555
2568
  (exports.isPlainObject = isPlainObject),
2556
2569
  (exports.isRoomAuthToken = isRoomAuthToken),
2570
+ (exports.isRoomEventName = function (value) {
2571
+ return (
2572
+ "my-presence" === value ||
2573
+ "others" === value ||
2574
+ "event" === value ||
2575
+ "error" === value ||
2576
+ "connection" === value
2577
+ );
2578
+ }),
2557
2579
  (exports.isRootCrdt = function (crdt) {
2558
2580
  return crdt.type === exports.CrdtType.OBJECT && !isChildCrdt(crdt);
2559
2581
  }),
@@ -2620,20 +2642,15 @@ function isJsonArray(data) {
2620
2642
  : second;
2621
2643
  }),
2622
2644
  (exports.nn = nn),
2623
- (exports.parseAuthToken = function (token) {
2624
- var data = parseJwtToken(token);
2625
- if (data && isAuthToken(data)) return data;
2626
- throw new Error(
2627
- "Authentication error. Liveblocks could not parse the response of your authentication endpoint"
2628
- );
2629
- }),
2630
2645
  (exports.parseRoomAuthToken = function (tokenString) {
2631
2646
  var data = parseJwtToken(tokenString);
2632
2647
  if (data && isRoomAuthToken(data))
2633
2648
  return (
2634
2649
  data.maxConnections, _objectWithoutPropertiesLoose(data, _excluded)
2635
2650
  );
2636
- throw new Error("Authentication error: invalid room auth token");
2651
+ throw new Error(
2652
+ "Authentication error: we expected a room token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
2653
+ );
2637
2654
  }),
2638
2655
  (exports.remove = function (array, item) {
2639
2656
  for (var i = 0; i < array.length; i++)
package/shared.mjs CHANGED
@@ -60,6 +60,15 @@ function isRootCrdt(crdt) {
60
60
  function isChildCrdt(crdt) {
61
61
  return void 0 !== crdt.parentId && void 0 !== crdt.parentKey;
62
62
  }
63
+ function isRoomEventName(value) {
64
+ return (
65
+ "my-presence" === value ||
66
+ "others" === value ||
67
+ "event" === value ||
68
+ "error" === value ||
69
+ "connection" === value
70
+ );
71
+ }
63
72
  function HasParent(node, key) {
64
73
  return Object.freeze({ type: "HasParent", node: node, key: key });
65
74
  }
@@ -684,14 +693,14 @@ class LiveList extends AbstractCrdt {
684
693
  const parentKey = nn(child._parentKey),
685
694
  reverse = child._serialize(nn(this._id), parentKey, this._doc),
686
695
  indexToDelete = this._items.indexOf(child);
687
- return (
688
- this._items.splice(indexToDelete, 1),
689
- child._detach(),
690
- {
691
- modified: makeUpdate(this, [deleteDelta(indexToDelete)]),
692
- reverse: reverse,
693
- }
694
- );
696
+ return -1 === indexToDelete
697
+ ? { modified: !1 }
698
+ : (this._items.splice(indexToDelete, 1),
699
+ child._detach(),
700
+ {
701
+ modified: makeUpdate(this, [deleteDelta(indexToDelete)]),
702
+ reverse: reverse,
703
+ });
695
704
  }
696
705
  return { modified: !1 };
697
706
  }
@@ -1143,6 +1152,7 @@ class LiveMap extends AbstractCrdt {
1143
1152
  null === entries,
1144
1153
  "Support for calling `new LiveMap(null)` will be removed in @liveblocks/client 0.18. Please call as `new LiveMap()`, or `new LiveMap([])`."
1145
1154
  ),
1155
+ (this.unacknowledgedSet = new Map()),
1146
1156
  entries)
1147
1157
  ) {
1148
1158
  const mappedEntries = [];
@@ -1187,12 +1197,19 @@ class LiveMap extends AbstractCrdt {
1187
1197
  for (const [_key, value] of this._map)
1188
1198
  isLiveNode(value) && value._attach(doc.generateId(), doc);
1189
1199
  }
1190
- _attachChild(op) {
1200
+ _attachChild(op, source) {
1191
1201
  if (null == this._doc)
1192
1202
  throw new Error("Can't attach child if doc is not present");
1193
- const { id: id, parentKey: key } = op,
1203
+ const { id: id, parentKey: parentKey, opId: opId } = op,
1204
+ key = parentKey,
1194
1205
  child = creationOpToLiveNode(op);
1195
1206
  if (void 0 !== this._doc.getItem(id)) return { modified: !1 };
1207
+ if (source === OpSource.ACK) {
1208
+ const lastUpdateOpId = this.unacknowledgedSet.get(key);
1209
+ if (lastUpdateOpId === opId)
1210
+ return this.unacknowledgedSet.delete(key), { modified: !1 };
1211
+ if (null != lastUpdateOpId) return { modified: !1 };
1212
+ } else source === OpSource.REMOTE && this.unacknowledgedSet.delete(key);
1196
1213
  const previousValue = this._map.get(key);
1197
1214
  let reverse;
1198
1215
  if (previousValue) {
@@ -1263,7 +1280,9 @@ class LiveMap extends AbstractCrdt {
1263
1280
  node: this,
1264
1281
  type: "LiveMap",
1265
1282
  updates: { [key]: { type: "update" } },
1266
- }),
1283
+ });
1284
+ const ops = item._serialize(this._id, key, this._doc);
1285
+ this.unacknowledgedSet.set(key, nn(ops[0].opId)),
1267
1286
  this._doc.dispatch(
1268
1287
  item._serialize(this._id, key, this._doc),
1269
1288
  oldValue
@@ -1989,13 +2008,8 @@ function parseRoomAuthToken(tokenString) {
1989
2008
  if (data && isRoomAuthToken(data)) {
1990
2009
  return __rest(data, ["maxConnections"]);
1991
2010
  }
1992
- throw new Error("Authentication error: invalid room auth token");
1993
- }
1994
- function parseAuthToken(token) {
1995
- const data = parseJwtToken(token);
1996
- if (data && isAuthToken(data)) return data;
1997
2011
  throw new Error(
1998
- "Authentication error. Liveblocks could not parse the response of your authentication endpoint"
2012
+ "Authentication error: we expected a room token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
1999
2013
  );
2000
2014
  }
2001
2015
  function isJsonScalar(data) {
@@ -2013,8 +2027,8 @@ function isJsonObject(data) {
2013
2027
  return !isJsonScalar(data) && !isJsonArray(data);
2014
2028
  }
2015
2029
  export {
2016
- isScope as A,
2017
- parseAuthToken as B,
2030
+ isRoomAuthToken as A,
2031
+ isScope as B,
2018
2032
  ClientMsgCode as C,
2019
2033
  deprecate as D,
2020
2034
  deprecateIf as E,
@@ -2030,30 +2044,30 @@ export {
2030
2044
  ServerMsgCode as S,
2031
2045
  WebsocketCloseCodes as W,
2032
2046
  __rest as _,
2033
- isPlainObject as a,
2034
- isTokenExpired as b,
2035
- isSameNodeOrChildOf as c,
2036
- OpCode as d,
2037
- isLiveList as e,
2038
- isJsonArray as f,
2047
+ isRoomEventName as a,
2048
+ isPlainObject as b,
2049
+ isTokenExpired as c,
2050
+ isSameNodeOrChildOf as d,
2051
+ OpCode as e,
2052
+ isLiveList as f,
2039
2053
  getTreesDiffOperations as g,
2040
- compact as h,
2054
+ isJsonArray as h,
2041
2055
  isLiveNode as i,
2042
- isRootCrdt as j,
2043
- isJsonObject as k,
2044
- errorIf as l,
2056
+ compact as j,
2057
+ isRootCrdt as k,
2058
+ isJsonObject as l,
2045
2059
  mergeStorageUpdates as m,
2046
2060
  nn as n,
2047
- LiveList as o,
2061
+ errorIf as o,
2048
2062
  parseRoomAuthToken as p,
2049
- LiveMap as q,
2063
+ LiveList as q,
2050
2064
  remove as r,
2051
- LiveRegister as s,
2065
+ LiveMap as s,
2052
2066
  tryParseJson as t,
2053
- findNonSerializableValue as u,
2054
- isLiveObject as v,
2055
- assertNever as w,
2056
- isAppOnlyAuthToken as x,
2057
- isAuthToken as y,
2058
- isRoomAuthToken as z,
2067
+ LiveRegister as u,
2068
+ findNonSerializableValue as v,
2069
+ isLiveObject as w,
2070
+ assertNever as x,
2071
+ isAppOnlyAuthToken as y,
2072
+ isAuthToken as z,
2059
2073
  };