@liveblocks/client 0.16.6 → 0.16.7

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/internal.d.ts CHANGED
@@ -229,6 +229,16 @@ declare type DeleteObjectKeyOp = {
229
229
  type: OpType.DeleteObjectKey;
230
230
  key: string;
231
231
  };
232
+ declare enum WebsocketCloseCodes {
233
+ CLOSE_ABNORMAL = 1006,
234
+ INVALID_MESSAGE_FORMAT = 4000,
235
+ NOT_ALLOWED = 4001,
236
+ MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
237
+ MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
238
+ MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
239
+ MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
240
+ CLOSE_WITHOUT_RETRY = 4999
241
+ }
232
242
 
233
243
  /**
234
244
  * Tools to help with the controlled deprecation of public APIs.
@@ -265,4 +275,7 @@ declare function lsonToJson(value: Lson | AbstractCrdt): Json;
265
275
  declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
266
276
  declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
267
277
 
268
- export { ClientMessageType, CrdtType, OpType, RoomStateMessage, SerializedCrdtWithId, ServerMessage, ServerMessageType, deprecate, deprecateIf, errorIf, lsonToJson, patchImmutableObject, patchLiveObjectKey, throwUsageError };
278
+ declare function makePosition(before?: string, after?: string): string;
279
+ declare function comparePosition(posA: string, posB: string): number;
280
+
281
+ export { ClientMessageType, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateRegisterOp, DeleteCrdtOp, DeleteObjectKeyOp, Op, OpType, RoomStateMessage, SerializedCrdt, SerializedCrdtWithId, SerializedList, SerializedMap, SerializedObject, SerializedRegister, ServerMessage, ServerMessageType, WebsocketCloseCodes, comparePosition, deprecate, deprecateIf, errorIf, lsonToJson, makePosition, patchImmutableObject, patchLiveObjectKey, throwUsageError };
package/internal.js CHANGED
@@ -160,8 +160,14 @@ Object.defineProperty(exports, "ClientMessageType", {
160
160
  get: function() {
161
161
  return LiveObject.ServerMessageType;
162
162
  }
163
- }), exports.deprecate = LiveObject.deprecate, exports.deprecateIf = LiveObject.deprecateIf,
164
- exports.errorIf = LiveObject.errorIf, exports.throwUsageError = LiveObject.throwUsageError,
163
+ }), Object.defineProperty(exports, "WebsocketCloseCodes", {
164
+ enumerable: !0,
165
+ get: function() {
166
+ return LiveObject.WebsocketCloseCodes;
167
+ }
168
+ }), exports.comparePosition = LiveObject.comparePosition, exports.deprecate = LiveObject.deprecate,
169
+ exports.deprecateIf = LiveObject.deprecateIf, exports.errorIf = LiveObject.errorIf,
170
+ exports.makePosition = LiveObject.makePosition, exports.throwUsageError = LiveObject.throwUsageError,
165
171
  exports.lsonToJson = lsonToJson, exports.patchImmutableObject = function(state, updates) {
166
172
  return updates.reduce((function(state, update) {
167
173
  return function(state, update) {
package/internal.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { L as LiveObject, b as LiveList, h as LiveMap, j as LiveRegister, A as AbstractCrdt, k as findNonSerializableValue } from "./shared.mjs";
2
2
 
3
- export { C as ClientMessageType, l as CrdtType, O as OpType, S as ServerMessageType, n as deprecate, f as deprecateIf, o as errorIf, t as throwUsageError } from "./shared.mjs";
3
+ export { C as ClientMessageType, o as CrdtType, O as OpType, S as ServerMessageType, W as WebsocketCloseCodes, q as comparePosition, l as deprecate, f as deprecateIf, n as errorIf, s as makePosition, t as throwUsageError } from "./shared.mjs";
4
4
 
5
5
  function lsonObjectToJson(obj) {
6
6
  const result = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.16.6",
3
+ "version": "0.16.7",
4
4
  "description": "A client that lets you interact with Liveblocks servers.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
package/shared.js CHANGED
@@ -312,7 +312,7 @@ function pos(codes) {
312
312
  return String.fromCharCode.apply(String, codes);
313
313
  }
314
314
 
315
- function compare(posA, posB) {
315
+ function comparePosition(posA, posB) {
316
316
  for (var aCodes = posCodes(posA), bCodes = posCodes(posB), maxLength = Math.max(aCodes.length, bCodes.length), i = 0; i < maxLength; i++) {
317
317
  var a = null == aCodes[i] ? 32 : aCodes[i], b = null == bCodes[i] ? 32 : bCodes[i];
318
318
  if (a !== b) return a - b;
@@ -342,7 +342,7 @@ var LiveList = function(_AbstractCrdt) {
342
342
  var entry = _step.value, child = deserialize(entry, parentToChildren, doc);
343
343
  child._setParentLink(list, entry[1].parentKey), list._items.push([ child, entry[1].parentKey ]),
344
344
  list._items.sort((function(itemA, itemB) {
345
- return compare(itemA[1], itemB[1]);
345
+ return comparePosition(itemA[1], itemB[1]);
346
346
  }));
347
347
  }
348
348
  return list;
@@ -416,7 +416,7 @@ var LiveList = function(_AbstractCrdt) {
416
416
  }
417
417
  }
418
418
  this._items.push([ child, newKey ]), this._items.sort((function(itemA, itemB) {
419
- return compare(itemA[1], itemB[1]);
419
+ return comparePosition(itemA[1], itemB[1]);
420
420
  }));
421
421
  var newIndex = this._items.findIndex((function(entry) {
422
422
  return entry[1] === newKey;
@@ -468,7 +468,7 @@ var LiveList = function(_AbstractCrdt) {
468
468
  return item[0] === child;
469
469
  }));
470
470
  item && (item[1] = key), this._items.sort((function(itemA, itemB) {
471
- return compare(itemA[1], itemB[1]);
471
+ return comparePosition(itemA[1], itemB[1]);
472
472
  }));
473
473
  var newIndex = this._items.findIndex((function(entry) {
474
474
  return entry[0]._id === child._id;
@@ -505,7 +505,7 @@ var LiveList = function(_AbstractCrdt) {
505
505
  if (index < 0 || index > this._items.length) throw new Error('Cannot insert list item at index "' + index + '". index should be between 0 and ' + this._items.length);
506
506
  var position = makePosition(this._items[index - 1] ? this._items[index - 1][1] : void 0, this._items[index] ? this._items[index][1] : void 0), value = selfOrRegister(element);
507
507
  value._setParentLink(this, position), this._items.push([ value, position ]), this._items.sort((function(itemA, itemB) {
508
- return compare(itemA[1], itemB[1]);
508
+ return comparePosition(itemA[1], itemB[1]);
509
509
  }));
510
510
  var newIndex = this._items.findIndex((function(entry) {
511
511
  return entry[1] === position;
@@ -538,7 +538,7 @@ var LiveList = function(_AbstractCrdt) {
538
538
  beforePosition = 0 === targetIndex ? void 0 : this._items[targetIndex - 1][1]);
539
539
  var position = makePosition(beforePosition, afterPosition), item = this._items[index], previousPosition = item[1];
540
540
  item[1] = position, item[0]._setParentLink(this, position), this._items.sort((function(itemA, itemB) {
541
- return compare(itemA[1], itemB[1]);
541
+ return comparePosition(itemA[1], itemB[1]);
542
542
  }));
543
543
  var newIndex = this._items.findIndex((function(entry) {
544
544
  return entry[1] === position;
@@ -1264,7 +1264,8 @@ exports._extends = _extends, exports._inheritsLoose = _inheritsLoose, exports._o
1264
1264
  return items.filter((function(item) {
1265
1265
  return null != item;
1266
1266
  }));
1267
- }, exports.deprecate = deprecate, exports.deprecateIf = deprecateIf, exports.errorIf = function(condition, message) {
1267
+ }, exports.comparePosition = comparePosition, exports.deprecate = deprecate, exports.deprecateIf = deprecateIf,
1268
+ exports.errorIf = function(condition, message) {
1268
1269
  "production" !== process.env.NODE_ENV && condition && throwUsageError(message);
1269
1270
  }, exports.findNonSerializableValue = function findNonSerializableValue(value, path) {
1270
1271
  if (void 0 === path && (path = ""), !isPlain) return {
@@ -1347,7 +1348,7 @@ exports._extends = _extends, exports._inheritsLoose = _inheritsLoose, exports._o
1347
1348
  if (3 !== tokenParts.length) return !1;
1348
1349
  var data = parseJson(atob(tokenParts[1]));
1349
1350
  return !(void 0 === data || !isJsonObject(data) || "number" != typeof data.exp) && !(Date.now() / 1e3 > data.exp - 300);
1350
- }, exports.mergeStorageUpdates = function(first, second) {
1351
+ }, exports.makePosition = makePosition, exports.mergeStorageUpdates = function(first, second) {
1351
1352
  return first ? "LiveObject" === first.type && "LiveObject" === second.type ? function(first, second) {
1352
1353
  for (var _step, updates = first.updates, _iterator = _createForOfIteratorHelperLoose(entries(second.updates)); !(_step = _iterator()).done; ) {
1353
1354
  var _step$value = _step.value, _key = _step$value[0], value = _step$value[1];
package/shared.mjs CHANGED
@@ -185,7 +185,7 @@ function pos(codes) {
185
185
  return String.fromCharCode(...codes);
186
186
  }
187
187
 
188
- function compare(posA, posB) {
188
+ function comparePosition(posA, posB) {
189
189
  const aCodes = posCodes(posA), bCodes = posCodes(posB), maxLength = Math.max(aCodes.length, bCodes.length);
190
190
  for (let i = 0; i < maxLength; i++) {
191
191
  const a = null == aCodes[i] ? 32 : aCodes[i], b = null == bCodes[i] ? 32 : bCodes[i];
@@ -211,7 +211,7 @@ class LiveList extends AbstractCrdt {
211
211
  for (const entry of children) {
212
212
  const child = deserialize(entry, parentToChildren, doc);
213
213
  child._setParentLink(list, entry[1].parentKey), list._items.push([ child, entry[1].parentKey ]),
214
- list._items.sort(((itemA, itemB) => compare(itemA[1], itemB[1])));
214
+ list._items.sort(((itemA, itemB) => comparePosition(itemA[1], itemB[1])));
215
215
  }
216
216
  return list;
217
217
  }
@@ -274,7 +274,7 @@ class LiveList extends AbstractCrdt {
274
274
  newKey = makePosition(before, after), child._setParentLink(this, newKey);
275
275
  } else this._items[index][1] = makePosition(key, null === (_a = this._items[index + 1]) || void 0 === _a ? void 0 : _a[1]);
276
276
  }
277
- this._items.push([ child, newKey ]), this._items.sort(((itemA, itemB) => compare(itemA[1], itemB[1])));
277
+ this._items.push([ child, newKey ]), this._items.sort(((itemA, itemB) => comparePosition(itemA[1], itemB[1])));
278
278
  const newIndex = this._items.findIndex((entry => entry[1] === newKey));
279
279
  return {
280
280
  reverse: [ {
@@ -318,7 +318,7 @@ class LiveList extends AbstractCrdt {
318
318
  const previousIndex = this._items.findIndex((entry => entry[0]._id === child._id)), index = this._items.findIndex((entry => entry[1] === key));
319
319
  -1 !== index && (this._items[index][1] = makePosition(key, null === (_a = this._items[index + 1]) || void 0 === _a ? void 0 : _a[1]));
320
320
  const item = this._items.find((item => item[0] === child));
321
- item && (item[1] = key), this._items.sort(((itemA, itemB) => compare(itemA[1], itemB[1])));
321
+ item && (item[1] = key), this._items.sort(((itemA, itemB) => comparePosition(itemA[1], itemB[1])));
322
322
  const newIndex = this._items.findIndex((entry => entry[0]._id === child._id));
323
323
  return {
324
324
  modified: {
@@ -358,7 +358,7 @@ class LiveList extends AbstractCrdt {
358
358
  insert(element, index) {
359
359
  if (index < 0 || index > this._items.length) throw new Error(`Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`);
360
360
  const position = makePosition(this._items[index - 1] ? this._items[index - 1][1] : void 0, this._items[index] ? this._items[index][1] : void 0), value = selfOrRegister(element);
361
- value._setParentLink(this, position), this._items.push([ value, position ]), this._items.sort(((itemA, itemB) => compare(itemA[1], itemB[1])));
361
+ value._setParentLink(this, position), this._items.push([ value, position ]), this._items.sort(((itemA, itemB) => comparePosition(itemA[1], itemB[1])));
362
362
  const newIndex = this._items.findIndex((entry => entry[1] === position));
363
363
  if (this._doc && this._id) {
364
364
  const id = this._doc.generateId();
@@ -388,7 +388,7 @@ class LiveList extends AbstractCrdt {
388
388
  beforePosition = this._items[targetIndex][1]) : (afterPosition = this._items[targetIndex][1],
389
389
  beforePosition = 0 === targetIndex ? void 0 : this._items[targetIndex - 1][1]);
390
390
  const position = makePosition(beforePosition, afterPosition), item = this._items[index], previousPosition = item[1];
391
- item[1] = position, item[0]._setParentLink(this, position), this._items.sort(((itemA, itemB) => compare(itemA[1], itemB[1])));
391
+ item[1] = position, item[0]._setParentLink(this, position), this._items.sort(((itemA, itemB) => comparePosition(itemA[1], itemB[1])));
392
392
  const newIndex = this._items.findIndex((entry => entry[1] === position));
393
393
  if (this._doc && this._id) {
394
394
  const storageUpdates = new Map;
@@ -1240,4 +1240,4 @@ class LiveObject extends AbstractCrdt {
1240
1240
  }
1241
1241
  }
1242
1242
 
1243
- export { AbstractCrdt as A, ClientMessageType as C, LiveObject as L, OpType as O, ServerMessageType as S, WebsocketCloseCodes as W, isSameNodeOrChildOf as a, LiveList as b, isJsonArray as c, compact as d, isJsonObject as e, deprecateIf as f, getTreesDiffOperations as g, LiveMap as h, isTokenValid as i, LiveRegister as j, findNonSerializableValue as k, CrdtType as l, mergeStorageUpdates as m, deprecate as n, errorIf as o, parseJson as p, remove as r, throwUsageError as t };
1243
+ export { AbstractCrdt as A, ClientMessageType as C, LiveObject as L, OpType as O, ServerMessageType as S, WebsocketCloseCodes as W, isSameNodeOrChildOf as a, LiveList as b, isJsonArray as c, compact as d, isJsonObject as e, deprecateIf as f, getTreesDiffOperations as g, LiveMap as h, isTokenValid as i, LiveRegister as j, findNonSerializableValue as k, deprecate as l, mergeStorageUpdates as m, errorIf as n, CrdtType as o, parseJson as p, comparePosition as q, remove as r, makePosition as s, throwUsageError as t };