@liveblocks/core 1.2.2-comments1 → 1.2.2-comments3

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.js CHANGED
@@ -1,12 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/version.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/version.ts
8
2
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "1.2.2-comments1";
3
+ var PKG_VERSION = "1.2.2-comments3";
10
4
  var PKG_FORMAT = "cjs";
11
5
 
12
6
  // src/dupe-detection.ts
@@ -156,13 +150,6 @@ function makeEventSource() {
156
150
  }
157
151
 
158
152
  // src/lib/fancy-console.ts
159
- var fancy_console_exports = {};
160
- __export(fancy_console_exports, {
161
- error: () => error2,
162
- errorWithTitle: () => errorWithTitle,
163
- warn: () => warn,
164
- warnWithTitle: () => warnWithTitle
165
- });
166
153
  var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
167
154
  var bold = "font-weight:600";
168
155
  function wrap(method) {
@@ -637,11 +624,6 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
637
624
  ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
638
625
  ServerMsgCode2[ServerMsgCode2["REJECT_STORAGE_OP"] = 299] = "REJECT_STORAGE_OP";
639
626
  ServerMsgCode2[ServerMsgCode2["UPDATE_YDOC"] = 300] = "UPDATE_YDOC";
640
- ServerMsgCode2[ServerMsgCode2["THREAD_CREATED"] = 400] = "THREAD_CREATED";
641
- ServerMsgCode2[ServerMsgCode2["THREAD_METADATA_UPDATED"] = 401] = "THREAD_METADATA_UPDATED";
642
- ServerMsgCode2[ServerMsgCode2["COMMENT_CREATED"] = 402] = "COMMENT_CREATED";
643
- ServerMsgCode2[ServerMsgCode2["COMMENT_EDITED"] = 403] = "COMMENT_EDITED";
644
- ServerMsgCode2[ServerMsgCode2["COMMENT_DELETED"] = 404] = "COMMENT_DELETED";
645
627
  return ServerMsgCode2;
646
628
  })(ServerMsgCode || {});
647
629
 
@@ -1170,10 +1152,10 @@ function createConnectionStateMachine(delegates, options) {
1170
1152
  };
1171
1153
  }
1172
1154
  var ManagedSocket = class {
1173
- constructor(delegates, enableDebugLogging = false, waitForActorId = true) {
1155
+ constructor(delegates, enableDebugLogging = false) {
1174
1156
  const { machine, events, cleanups } = createConnectionStateMachine(
1175
1157
  delegates,
1176
- { waitForActorId, enableDebugLogging }
1158
+ { waitForActorId: true, enableDebugLogging }
1177
1159
  );
1178
1160
  this.machine = machine;
1179
1161
  this.events = events;
@@ -1255,9 +1237,6 @@ var ManagedSocket = class {
1255
1237
  function canWriteStorage(scopes) {
1256
1238
  return scopes.includes("room:write" /* Write */);
1257
1239
  }
1258
- function canComment(scopes) {
1259
- return scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:write" /* Write */);
1260
- }
1261
1240
  function isValidAuthTokenPayload(data) {
1262
1241
  return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */ || data.k === "sec-legacy" /* SECRET_LEGACY */);
1263
1242
  }
@@ -1670,149 +1649,6 @@ function errorIf(condition, message) {
1670
1649
  }
1671
1650
  }
1672
1651
 
1673
- // src/comments/index.ts
1674
- function getAuthBearerHeaderFromAuthValue(authValue) {
1675
- if (authValue.type === "public") {
1676
- return authValue.publicApiKey;
1677
- } else {
1678
- return authValue.token.raw;
1679
- }
1680
- }
1681
- function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
1682
- async function fetchJson(endpoint, options) {
1683
- const response = await fetchApi(roomId, endpoint, options);
1684
- if (!response.ok) {
1685
- if (response.status >= 400 && response.status < 600) {
1686
- let errorMessage = "";
1687
- try {
1688
- const errorBody = await response.json();
1689
- errorMessage = errorBody.message;
1690
- } catch (error3) {
1691
- errorMessage = response.statusText;
1692
- }
1693
- throw new Error(
1694
- `Request failed with status ${response.status}: ${errorMessage}`
1695
- );
1696
- }
1697
- }
1698
- let body;
1699
- try {
1700
- body = await response.json();
1701
- } catch (e3) {
1702
- body = {};
1703
- }
1704
- return body;
1705
- }
1706
- async function fetchApi(roomId2, endpoint, options) {
1707
- const authValue = await getAuthValue();
1708
- const url = `${serverEndpoint}/c/rooms/${roomId2}${endpoint}`;
1709
- return await fetch(url, {
1710
- ...options,
1711
- headers: {
1712
- ..._optionalChain([options, 'optionalAccess', _43 => _43.headers]),
1713
- Authorization: `Bearer ${getAuthBearerHeaderFromAuthValue(authValue)}`
1714
- }
1715
- });
1716
- }
1717
- async function getThreads() {
1718
- const response = await fetchApi(roomId, "/threads");
1719
- if (response.ok) {
1720
- const json = await response.json();
1721
- return json.data;
1722
- } else if (response.status === 404) {
1723
- return [];
1724
- } else {
1725
- throw new Error("FAIL");
1726
- }
1727
- }
1728
- function createThread({
1729
- metadata,
1730
- body,
1731
- commentId,
1732
- threadId
1733
- }) {
1734
- return fetchJson("/threads", {
1735
- method: "POST",
1736
- headers: {
1737
- "Content-Type": "application/json"
1738
- },
1739
- body: JSON.stringify({
1740
- id: threadId,
1741
- comment: {
1742
- id: commentId,
1743
- body
1744
- },
1745
- metadata
1746
- })
1747
- });
1748
- }
1749
- function editThreadMetadata({
1750
- metadata,
1751
- threadId
1752
- }) {
1753
- return fetchJson(
1754
- `/threads/${threadId}/metadata`,
1755
- {
1756
- method: "POST",
1757
- headers: {
1758
- "Content-Type": "application/json"
1759
- },
1760
- body: JSON.stringify(metadata)
1761
- }
1762
- );
1763
- }
1764
- function createComment({
1765
- threadId,
1766
- commentId,
1767
- body
1768
- }) {
1769
- return fetchJson(`/threads/${threadId}/comments`, {
1770
- method: "POST",
1771
- headers: {
1772
- "Content-Type": "application/json"
1773
- },
1774
- body: JSON.stringify({
1775
- id: commentId,
1776
- body
1777
- })
1778
- });
1779
- }
1780
- function editComment({
1781
- threadId,
1782
- commentId,
1783
- body
1784
- }) {
1785
- return fetchJson(
1786
- `/threads/${threadId}/comments/${commentId}`,
1787
- {
1788
- method: "POST",
1789
- headers: {
1790
- "Content-Type": "application/json"
1791
- },
1792
- body: JSON.stringify({
1793
- body
1794
- })
1795
- }
1796
- );
1797
- }
1798
- async function deleteComment({
1799
- threadId,
1800
- commentId
1801
- }) {
1802
- await fetchJson(`/threads/${threadId}/comments/${commentId}`, {
1803
- method: "DELETE"
1804
- });
1805
- }
1806
- return {
1807
- getThreads,
1808
- createThread,
1809
- editThreadMetadata,
1810
- createComment,
1811
- editComment,
1812
- deleteComment
1813
- };
1814
- }
1815
-
1816
1652
  // src/lib/position.ts
1817
1653
  var MIN_CODE = 32;
1818
1654
  var MAX_CODE = 126;
@@ -2174,7 +2010,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
2174
2010
  return [
2175
2011
  {
2176
2012
  type: 8 /* CREATE_REGISTER */,
2177
- opId: _optionalChain([pool, 'optionalAccess', _44 => _44.generateOpId, 'call', _45 => _45()]),
2013
+ opId: _optionalChain([pool, 'optionalAccess', _43 => _43.generateOpId, 'call', _44 => _44()]),
2178
2014
  id: this._id,
2179
2015
  parentId,
2180
2016
  parentKey,
@@ -2265,7 +2101,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2265
2101
  const ops = [];
2266
2102
  const op = {
2267
2103
  id: this._id,
2268
- opId: _optionalChain([pool, 'optionalAccess', _46 => _46.generateOpId, 'call', _47 => _47()]),
2104
+ opId: _optionalChain([pool, 'optionalAccess', _45 => _45.generateOpId, 'call', _46 => _46()]),
2269
2105
  type: 2 /* CREATE_LIST */,
2270
2106
  parentId,
2271
2107
  parentKey
@@ -2533,7 +2369,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2533
2369
  _applyInsertUndoRedo(op) {
2534
2370
  const { id, parentKey: key } = op;
2535
2371
  const child = creationOpToLiveNode(op);
2536
- if (_optionalChain([this, 'access', _48 => _48._pool, 'optionalAccess', _49 => _49.getNode, 'call', _50 => _50(id)]) !== void 0) {
2372
+ if (_optionalChain([this, 'access', _47 => _47._pool, 'optionalAccess', _48 => _48.getNode, 'call', _49 => _49(id)]) !== void 0) {
2537
2373
  return { modified: false };
2538
2374
  }
2539
2375
  child._attach(id, nn(this._pool));
@@ -2541,8 +2377,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
2541
2377
  const existingItemIndex = this._indexOfPosition(key);
2542
2378
  let newKey = key;
2543
2379
  if (existingItemIndex !== -1) {
2544
- const before2 = _optionalChain([this, 'access', _51 => _51._items, 'access', _52 => _52[existingItemIndex], 'optionalAccess', _53 => _53._parentPos]);
2545
- const after2 = _optionalChain([this, 'access', _54 => _54._items, 'access', _55 => _55[existingItemIndex + 1], 'optionalAccess', _56 => _56._parentPos]);
2380
+ const before2 = _optionalChain([this, 'access', _50 => _50._items, 'access', _51 => _51[existingItemIndex], 'optionalAccess', _52 => _52._parentPos]);
2381
+ const after2 = _optionalChain([this, 'access', _53 => _53._items, 'access', _54 => _54[existingItemIndex + 1], 'optionalAccess', _55 => _55._parentPos]);
2546
2382
  newKey = makePosition(before2, after2);
2547
2383
  child._setParentLink(this, newKey);
2548
2384
  }
@@ -2557,7 +2393,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2557
2393
  _applySetUndoRedo(op) {
2558
2394
  const { id, parentKey: key } = op;
2559
2395
  const child = creationOpToLiveNode(op);
2560
- if (_optionalChain([this, 'access', _57 => _57._pool, 'optionalAccess', _58 => _58.getNode, 'call', _59 => _59(id)]) !== void 0) {
2396
+ if (_optionalChain([this, 'access', _56 => _56._pool, 'optionalAccess', _57 => _57.getNode, 'call', _58 => _58(id)]) !== void 0) {
2561
2397
  return { modified: false };
2562
2398
  }
2563
2399
  this._unacknowledgedSets.set(key, nn(op.opId));
@@ -2679,7 +2515,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2679
2515
  } else {
2680
2516
  this._items[existingItemIndex]._setParentLink(
2681
2517
  this,
2682
- makePosition(newKey, _optionalChain([this, 'access', _60 => _60._items, 'access', _61 => _61[existingItemIndex + 1], 'optionalAccess', _62 => _62._parentPos]))
2518
+ makePosition(newKey, _optionalChain([this, 'access', _59 => _59._items, 'access', _60 => _60[existingItemIndex + 1], 'optionalAccess', _61 => _61._parentPos]))
2683
2519
  );
2684
2520
  const previousIndex = this._items.indexOf(child);
2685
2521
  child._setParentLink(this, newKey);
@@ -2705,7 +2541,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2705
2541
  if (existingItemIndex !== -1) {
2706
2542
  this._items[existingItemIndex]._setParentLink(
2707
2543
  this,
2708
- makePosition(newKey, _optionalChain([this, 'access', _63 => _63._items, 'access', _64 => _64[existingItemIndex + 1], 'optionalAccess', _65 => _65._parentPos]))
2544
+ makePosition(newKey, _optionalChain([this, 'access', _62 => _62._items, 'access', _63 => _63[existingItemIndex + 1], 'optionalAccess', _64 => _64._parentPos]))
2709
2545
  );
2710
2546
  }
2711
2547
  child._setParentLink(this, newKey);
@@ -2724,7 +2560,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2724
2560
  if (existingItemIndex !== -1) {
2725
2561
  this._items[existingItemIndex]._setParentLink(
2726
2562
  this,
2727
- makePosition(newKey, _optionalChain([this, 'access', _66 => _66._items, 'access', _67 => _67[existingItemIndex + 1], 'optionalAccess', _68 => _68._parentPos]))
2563
+ makePosition(newKey, _optionalChain([this, 'access', _65 => _65._items, 'access', _66 => _66[existingItemIndex + 1], 'optionalAccess', _67 => _67._parentPos]))
2728
2564
  );
2729
2565
  }
2730
2566
  child._setParentLink(this, newKey);
@@ -2752,7 +2588,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2752
2588
  if (existingItemIndex !== -1) {
2753
2589
  this._items[existingItemIndex]._setParentLink(
2754
2590
  this,
2755
- makePosition(newKey, _optionalChain([this, 'access', _69 => _69._items, 'access', _70 => _70[existingItemIndex + 1], 'optionalAccess', _71 => _71._parentPos]))
2591
+ makePosition(newKey, _optionalChain([this, 'access', _68 => _68._items, 'access', _69 => _69[existingItemIndex + 1], 'optionalAccess', _70 => _70._parentPos]))
2756
2592
  );
2757
2593
  }
2758
2594
  child._setParentLink(this, newKey);
@@ -2810,7 +2646,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2810
2646
  * @param element The element to add to the end of the LiveList.
2811
2647
  */
2812
2648
  push(element) {
2813
- _optionalChain([this, 'access', _72 => _72._pool, 'optionalAccess', _73 => _73.assertStorageIsWritable, 'call', _74 => _74()]);
2649
+ _optionalChain([this, 'access', _71 => _71._pool, 'optionalAccess', _72 => _72.assertStorageIsWritable, 'call', _73 => _73()]);
2814
2650
  return this.insert(element, this.length);
2815
2651
  }
2816
2652
  /**
@@ -2819,7 +2655,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2819
2655
  * @param index The index at which you want to insert the element.
2820
2656
  */
2821
2657
  insert(element, index) {
2822
- _optionalChain([this, 'access', _75 => _75._pool, 'optionalAccess', _76 => _76.assertStorageIsWritable, 'call', _77 => _77()]);
2658
+ _optionalChain([this, 'access', _74 => _74._pool, 'optionalAccess', _75 => _75.assertStorageIsWritable, 'call', _76 => _76()]);
2823
2659
  if (index < 0 || index > this._items.length) {
2824
2660
  throw new Error(
2825
2661
  `Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
@@ -2849,7 +2685,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2849
2685
  * @param targetIndex The index where the element should be after moving.
2850
2686
  */
2851
2687
  move(index, targetIndex) {
2852
- _optionalChain([this, 'access', _78 => _78._pool, 'optionalAccess', _79 => _79.assertStorageIsWritable, 'call', _80 => _80()]);
2688
+ _optionalChain([this, 'access', _77 => _77._pool, 'optionalAccess', _78 => _78.assertStorageIsWritable, 'call', _79 => _79()]);
2853
2689
  if (targetIndex < 0) {
2854
2690
  throw new Error("targetIndex cannot be less than 0");
2855
2691
  }
@@ -2907,7 +2743,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2907
2743
  * @param index The index of the element to delete
2908
2744
  */
2909
2745
  delete(index) {
2910
- _optionalChain([this, 'access', _81 => _81._pool, 'optionalAccess', _82 => _82.assertStorageIsWritable, 'call', _83 => _83()]);
2746
+ _optionalChain([this, 'access', _80 => _80._pool, 'optionalAccess', _81 => _81.assertStorageIsWritable, 'call', _82 => _82()]);
2911
2747
  if (index < 0 || index >= this._items.length) {
2912
2748
  throw new Error(
2913
2749
  `Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
@@ -2940,7 +2776,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2940
2776
  }
2941
2777
  }
2942
2778
  clear() {
2943
- _optionalChain([this, 'access', _84 => _84._pool, 'optionalAccess', _85 => _85.assertStorageIsWritable, 'call', _86 => _86()]);
2779
+ _optionalChain([this, 'access', _83 => _83._pool, 'optionalAccess', _84 => _84.assertStorageIsWritable, 'call', _85 => _85()]);
2944
2780
  if (this._pool) {
2945
2781
  const ops = [];
2946
2782
  const reverseOps = [];
@@ -2974,7 +2810,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2974
2810
  }
2975
2811
  }
2976
2812
  set(index, item) {
2977
- _optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.assertStorageIsWritable, 'call', _89 => _89()]);
2813
+ _optionalChain([this, 'access', _86 => _86._pool, 'optionalAccess', _87 => _87.assertStorageIsWritable, 'call', _88 => _88()]);
2978
2814
  if (index < 0 || index >= this._items.length) {
2979
2815
  throw new Error(
2980
2816
  `Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
@@ -3122,7 +2958,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
3122
2958
  _shiftItemPosition(index, key) {
3123
2959
  const shiftedPosition = makePosition(
3124
2960
  key,
3125
- this._items.length > index + 1 ? _optionalChain([this, 'access', _90 => _90._items, 'access', _91 => _91[index + 1], 'optionalAccess', _92 => _92._parentPos]) : void 0
2961
+ this._items.length > index + 1 ? _optionalChain([this, 'access', _89 => _89._items, 'access', _90 => _90[index + 1], 'optionalAccess', _91 => _91._parentPos]) : void 0
3126
2962
  );
3127
2963
  this._items[index]._setParentLink(this, shiftedPosition);
3128
2964
  }
@@ -3248,7 +3084,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
3248
3084
  const ops = [];
3249
3085
  const op = {
3250
3086
  id: this._id,
3251
- opId: _optionalChain([pool, 'optionalAccess', _93 => _93.generateOpId, 'call', _94 => _94()]),
3087
+ opId: _optionalChain([pool, 'optionalAccess', _92 => _92.generateOpId, 'call', _93 => _93()]),
3252
3088
  type: 7 /* CREATE_MAP */,
3253
3089
  parentId,
3254
3090
  parentKey
@@ -3395,7 +3231,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
3395
3231
  * @param value The value of the element to add. Should be serializable to JSON.
3396
3232
  */
3397
3233
  set(key, value) {
3398
- _optionalChain([this, 'access', _95 => _95._pool, 'optionalAccess', _96 => _96.assertStorageIsWritable, 'call', _97 => _97()]);
3234
+ _optionalChain([this, 'access', _94 => _94._pool, 'optionalAccess', _95 => _95.assertStorageIsWritable, 'call', _96 => _96()]);
3399
3235
  const oldValue = this._map.get(key);
3400
3236
  if (oldValue) {
3401
3237
  oldValue._detach();
@@ -3441,7 +3277,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
3441
3277
  * @returns true if an element existed and has been removed, or false if the element does not exist.
3442
3278
  */
3443
3279
  delete(key) {
3444
- _optionalChain([this, 'access', _98 => _98._pool, 'optionalAccess', _99 => _99.assertStorageIsWritable, 'call', _100 => _100()]);
3280
+ _optionalChain([this, 'access', _97 => _97._pool, 'optionalAccess', _98 => _98.assertStorageIsWritable, 'call', _99 => _99()]);
3445
3281
  const item = this._map.get(key);
3446
3282
  if (item === void 0) {
3447
3283
  return false;
@@ -3615,7 +3451,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
3615
3451
  if (this._id === void 0) {
3616
3452
  throw new Error("Cannot serialize item is not attached");
3617
3453
  }
3618
- const opId = _optionalChain([pool, 'optionalAccess', _101 => _101.generateOpId, 'call', _102 => _102()]);
3454
+ const opId = _optionalChain([pool, 'optionalAccess', _100 => _100.generateOpId, 'call', _101 => _101()]);
3619
3455
  const ops = [];
3620
3456
  const op = parentId !== void 0 && parentKey !== void 0 ? {
3621
3457
  type: 4 /* CREATE_OBJECT */,
@@ -3896,7 +3732,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
3896
3732
  * @param value The value of the property to add
3897
3733
  */
3898
3734
  set(key, value) {
3899
- _optionalChain([this, 'access', _103 => _103._pool, 'optionalAccess', _104 => _104.assertStorageIsWritable, 'call', _105 => _105()]);
3735
+ _optionalChain([this, 'access', _102 => _102._pool, 'optionalAccess', _103 => _103.assertStorageIsWritable, 'call', _104 => _104()]);
3900
3736
  this.update({ [key]: value });
3901
3737
  }
3902
3738
  /**
@@ -3911,7 +3747,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
3911
3747
  * @param key The key of the property to delete
3912
3748
  */
3913
3749
  delete(key) {
3914
- _optionalChain([this, 'access', _106 => _106._pool, 'optionalAccess', _107 => _107.assertStorageIsWritable, 'call', _108 => _108()]);
3750
+ _optionalChain([this, 'access', _105 => _105._pool, 'optionalAccess', _106 => _106.assertStorageIsWritable, 'call', _107 => _107()]);
3915
3751
  const keyAsString = key;
3916
3752
  const oldValue = this._map.get(keyAsString);
3917
3753
  if (oldValue === void 0) {
@@ -3964,7 +3800,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
3964
3800
  * @param patch The object used to overrides properties
3965
3801
  */
3966
3802
  update(patch) {
3967
- _optionalChain([this, 'access', _109 => _109._pool, 'optionalAccess', _110 => _110.assertStorageIsWritable, 'call', _111 => _111()]);
3803
+ _optionalChain([this, 'access', _108 => _108._pool, 'optionalAccess', _109 => _109.assertStorageIsWritable, 'call', _110 => _110()]);
3968
3804
  if (this._pool === void 0 || this._id === void 0) {
3969
3805
  for (const key in patch) {
3970
3806
  const newValue = patch[key];
@@ -4415,7 +4251,6 @@ function makeUser(conn, presence) {
4415
4251
  id,
4416
4252
  info,
4417
4253
  canWrite,
4418
- canComment: canComment(conn.scopes),
4419
4254
  isReadOnly: !canWrite,
4420
4255
  // Deprecated, kept for backward-compatibility
4421
4256
  presence
@@ -4776,7 +4611,7 @@ function createRoom(options, config) {
4776
4611
  }
4777
4612
  },
4778
4613
  assertStorageIsWritable: () => {
4779
- const scopes = _optionalChain([context, 'access', _112 => _112.dynamicSessionInfo, 'access', _113 => _113.current, 'optionalAccess', _114 => _114.scopes]);
4614
+ const scopes = _optionalChain([context, 'access', _111 => _111.dynamicSessionInfo, 'access', _112 => _112.current, 'optionalAccess', _113 => _113.scopes]);
4780
4615
  if (scopes === void 0) {
4781
4616
  return;
4782
4617
  }
@@ -4803,20 +4638,19 @@ function createRoom(options, config) {
4803
4638
  history: makeEventSource(),
4804
4639
  storageDidLoad: makeEventSource(),
4805
4640
  storageStatus: makeEventSource(),
4806
- ydoc: makeEventSource(),
4807
- comments: makeEventSource()
4641
+ ydoc: makeEventSource()
4808
4642
  };
4809
4643
  function sendMessages(messageOrMessages) {
4810
4644
  const message = JSON.stringify(messageOrMessages);
4811
4645
  if (config.unstable_fallbackToHTTP) {
4812
4646
  const size = new TextEncoder().encode(message).length;
4813
4647
  if (size > MAX_MESSAGE_SIZE && // TODO: support public api key auth in REST API
4814
- _optionalChain([managedSocket, 'access', _115 => _115.authValue, 'optionalAccess', _116 => _116.type]) === "secret" && config.httpSendEndpoint) {
4648
+ _optionalChain([managedSocket, 'access', _114 => _114.authValue, 'optionalAccess', _115 => _115.type]) === "secret" && config.httpSendEndpoint) {
4815
4649
  void httpSend(
4816
4650
  message,
4817
4651
  managedSocket.authValue.token.raw,
4818
4652
  config.httpSendEndpoint,
4819
- _optionalChain([config, 'access', _117 => _117.polyfills, 'optionalAccess', _118 => _118.fetch])
4653
+ _optionalChain([config, 'access', _116 => _116.polyfills, 'optionalAccess', _117 => _117.fetch])
4820
4654
  ).then((resp) => {
4821
4655
  if (!resp.ok && resp.status === 403) {
4822
4656
  managedSocket.reconnect();
@@ -4845,7 +4679,6 @@ function createRoom(options, config) {
4845
4679
  info: staticSession.userInfo,
4846
4680
  presence: myPresence,
4847
4681
  canWrite,
4848
- canComment: canComment(dynamicSession.scopes),
4849
4682
  isReadOnly: !canWrite
4850
4683
  // Deprecated, kept for backward-compatibility
4851
4684
  };
@@ -5073,7 +4906,7 @@ function createRoom(options, config) {
5073
4906
  }
5074
4907
  context.myPresence.patch(patch);
5075
4908
  if (context.activeBatch) {
5076
- if (_optionalChain([options2, 'optionalAccess', _119 => _119.addToHistory])) {
4909
+ if (_optionalChain([options2, 'optionalAccess', _118 => _118.addToHistory])) {
5077
4910
  context.activeBatch.reverseOps.unshift({
5078
4911
  type: "presence",
5079
4912
  data: oldValues
@@ -5083,7 +4916,7 @@ function createRoom(options, config) {
5083
4916
  } else {
5084
4917
  flushNowOrSoon();
5085
4918
  batchUpdates(() => {
5086
- if (_optionalChain([options2, 'optionalAccess', _120 => _120.addToHistory])) {
4919
+ if (_optionalChain([options2, 'optionalAccess', _119 => _119.addToHistory])) {
5087
4920
  addToUndoStack(
5088
4921
  [{ type: "presence", data: oldValues }],
5089
4922
  doNotBatchUpdates
@@ -5260,7 +5093,7 @@ function createRoom(options, config) {
5260
5093
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
5261
5094
  createOrUpdateRootFromMessage(message, doNotBatchUpdates);
5262
5095
  applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
5263
- _optionalChain([_resolveStoragePromise, 'optionalCall', _121 => _121()]);
5096
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _120 => _120()]);
5264
5097
  notifyStorageStatus();
5265
5098
  eventHub.storageDidLoad.notify();
5266
5099
  break;
@@ -5283,7 +5116,7 @@ function createRoom(options, config) {
5283
5116
  if (process.env.NODE_ENV !== "production") {
5284
5117
  const traces = /* @__PURE__ */ new Set();
5285
5118
  for (const opId of message.opIds) {
5286
- const trace = _optionalChain([context, 'access', _122 => _122.opStackTraces, 'optionalAccess', _123 => _123.get, 'call', _124 => _124(opId)]);
5119
+ const trace = _optionalChain([context, 'access', _121 => _121.opStackTraces, 'optionalAccess', _122 => _122.get, 'call', _123 => _123(opId)]);
5287
5120
  if (trace) {
5288
5121
  traces.add(trace);
5289
5122
  }
@@ -5302,14 +5135,6 @@ ${Array.from(traces).join("\n\n")}`
5302
5135
  }
5303
5136
  break;
5304
5137
  }
5305
- case 400 /* THREAD_CREATED */:
5306
- case 401 /* THREAD_METADATA_UPDATED */:
5307
- case 402 /* COMMENT_CREATED */:
5308
- case 403 /* COMMENT_EDITED */:
5309
- case 404 /* COMMENT_DELETED */: {
5310
- eventHub.comments.notify(message);
5311
- break;
5312
- }
5313
5138
  }
5314
5139
  }
5315
5140
  notify(updates, doNotBatchUpdates);
@@ -5576,18 +5401,14 @@ ${Array.from(traces).join("\n\n")}`
5576
5401
  history: eventHub.history.observable,
5577
5402
  storageDidLoad: eventHub.storageDidLoad.observable,
5578
5403
  storageStatus: eventHub.storageStatus.observable,
5579
- ydoc: eventHub.ydoc.observable,
5580
- comments: eventHub.comments.observable
5404
+ ydoc: eventHub.ydoc.observable
5581
5405
  };
5582
- const commentsApi = createCommentsApi(config.roomId, delegates.authenticate, {
5583
- serverEndpoint: "https://api.liveblocks.io/v2"
5584
- });
5585
5406
  return Object.defineProperty(
5586
5407
  {
5587
5408
  /* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
5588
5409
  __internal: {
5589
5410
  get presenceBuffer() {
5590
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _125 => _125.buffer, 'access', _126 => _126.presenceUpdates, 'optionalAccess', _127 => _127.data]), () => ( null)));
5411
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _124 => _124.buffer, 'access', _125 => _125.presenceUpdates, 'optionalAccess', _126 => _126.data]), () => ( null)));
5591
5412
  },
5592
5413
  // prettier-ignore
5593
5414
  get undoStack() {
@@ -5639,8 +5460,7 @@ ${Array.from(traces).join("\n\n")}`
5639
5460
  getSelf: () => self.current,
5640
5461
  // Presence
5641
5462
  getPresence: () => context.myPresence.current,
5642
- getOthers: () => context.others.current,
5643
- ...commentsApi
5463
+ getOthers: () => context.others.current
5644
5464
  },
5645
5465
  // Explictly make the __internal field non-enumerable, to avoid aggressive
5646
5466
  // freezing when used with Immer
@@ -5719,7 +5539,7 @@ function makeClassicSubscribeFn(events) {
5719
5539
  }
5720
5540
  if (isLiveNode(first)) {
5721
5541
  const node = first;
5722
- if (_optionalChain([options, 'optionalAccess', _128 => _128.isDeep])) {
5542
+ if (_optionalChain([options, 'optionalAccess', _127 => _127.isDeep])) {
5723
5543
  const storageCallback = second;
5724
5544
  return subscribeToLiveStructureDeeply(node, storageCallback);
5725
5545
  } else {
@@ -5820,12 +5640,12 @@ function createClient(options) {
5820
5640
  createSocket: makeCreateSocketDelegateForRoom(
5821
5641
  roomId,
5822
5642
  getServerFromClientOptions(clientOptions),
5823
- _optionalChain([clientOptions, 'access', _129 => _129.polyfills, 'optionalAccess', _130 => _130.WebSocket])
5643
+ _optionalChain([clientOptions, 'access', _128 => _128.polyfills, 'optionalAccess', _129 => _129.WebSocket])
5824
5644
  ),
5825
5645
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
5826
5646
  })),
5827
5647
  enableDebugLogging: clientOptions.enableDebugLogging,
5828
- unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _131 => _131.unstable_batchedUpdates]),
5648
+ unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _130 => _130.unstable_batchedUpdates]),
5829
5649
  liveblocksServer: getServerFromClientOptions(clientOptions),
5830
5650
  httpSendEndpoint: buildLiveblocksHttpSendEndpoint(
5831
5651
  clientOptions,
@@ -5840,7 +5660,7 @@ function createClient(options) {
5840
5660
  const shouldConnect = _nullishCoalesce(options2.shouldInitiallyConnect, () => ( true));
5841
5661
  if (shouldConnect) {
5842
5662
  if (typeof atob === "undefined") {
5843
- if (_optionalChain([clientOptions, 'access', _132 => _132.polyfills, 'optionalAccess', _133 => _133.atob]) === void 0) {
5663
+ if (_optionalChain([clientOptions, 'access', _131 => _131.polyfills, 'optionalAccess', _132 => _132.atob]) === void 0) {
5844
5664
  throw new Error(
5845
5665
  "You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
5846
5666
  );
@@ -6123,12 +5943,12 @@ function legacy_patchImmutableNode(state, path, update) {
6123
5943
  }
6124
5944
  const newState = Object.assign({}, state);
6125
5945
  for (const key in update.updates) {
6126
- if (_optionalChain([update, 'access', _134 => _134.updates, 'access', _135 => _135[key], 'optionalAccess', _136 => _136.type]) === "update") {
5946
+ if (_optionalChain([update, 'access', _133 => _133.updates, 'access', _134 => _134[key], 'optionalAccess', _135 => _135.type]) === "update") {
6127
5947
  const val = update.node.get(key);
6128
5948
  if (val !== void 0) {
6129
5949
  newState[key] = lsonToJson(val);
6130
5950
  }
6131
- } else if (_optionalChain([update, 'access', _137 => _137.updates, 'access', _138 => _138[key], 'optionalAccess', _139 => _139.type]) === "delete") {
5951
+ } else if (_optionalChain([update, 'access', _136 => _136.updates, 'access', _137 => _137[key], 'optionalAccess', _138 => _138.type]) === "delete") {
6132
5952
  delete newState[key];
6133
5953
  }
6134
5954
  }
@@ -6189,12 +6009,12 @@ function legacy_patchImmutableNode(state, path, update) {
6189
6009
  }
6190
6010
  const newState = Object.assign({}, state);
6191
6011
  for (const key in update.updates) {
6192
- if (_optionalChain([update, 'access', _140 => _140.updates, 'access', _141 => _141[key], 'optionalAccess', _142 => _142.type]) === "update") {
6012
+ if (_optionalChain([update, 'access', _139 => _139.updates, 'access', _140 => _140[key], 'optionalAccess', _141 => _141.type]) === "update") {
6193
6013
  const value = update.node.get(key);
6194
6014
  if (value !== void 0) {
6195
6015
  newState[key] = lsonToJson(value);
6196
6016
  }
6197
- } else if (_optionalChain([update, 'access', _143 => _143.updates, 'access', _144 => _144[key], 'optionalAccess', _145 => _145.type]) === "delete") {
6017
+ } else if (_optionalChain([update, 'access', _142 => _142.updates, 'access', _143 => _143[key], 'optionalAccess', _144 => _144.type]) === "delete") {
6198
6018
  delete newState[key];
6199
6019
  }
6200
6020
  }
@@ -6265,222 +6085,6 @@ function shallow(a, b) {
6265
6085
  return shallowObj(a, b);
6266
6086
  }
6267
6087
 
6268
- // src/lib/AsyncCache.ts
6269
- var noop = () => {
6270
- };
6271
- function isShallowEqual(a, b) {
6272
- if (a.isLoading !== b.isLoading || a.data === void 0 !== (b.data === void 0) || a.error === void 0 !== (b.error === void 0)) {
6273
- return false;
6274
- } else {
6275
- return shallow(a.data, b.data) && shallow(a.error, b.error);
6276
- }
6277
- }
6278
- function createCacheItem(key, defaultAsyncFunction, options) {
6279
- let asyncFunction = defaultAsyncFunction;
6280
- const context = {
6281
- isInvalid: true
6282
- };
6283
- let state = { isLoading: false };
6284
- let previousState = { isLoading: false };
6285
- const eventSource2 = makeEventSource();
6286
- function notify() {
6287
- const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _146 => _146.isStateEqual]), () => ( isShallowEqual));
6288
- if (!isEqual(previousState, state)) {
6289
- previousState = state;
6290
- eventSource2.notify(state);
6291
- }
6292
- }
6293
- async function resolve() {
6294
- if (!context.promise) {
6295
- return;
6296
- }
6297
- try {
6298
- const data = await context.promise;
6299
- context.isInvalid = false;
6300
- state = {
6301
- isLoading: false,
6302
- data
6303
- };
6304
- } catch (error3) {
6305
- state = {
6306
- isLoading: false,
6307
- data: state.data,
6308
- error: error3
6309
- };
6310
- }
6311
- context.promise = void 0;
6312
- notify();
6313
- }
6314
- async function revalidate() {
6315
- context.isInvalid = true;
6316
- return get();
6317
- }
6318
- async function get() {
6319
- if (context.isInvalid) {
6320
- if (!context.promise) {
6321
- context.isInvalid = true;
6322
- context.promise = asyncFunction(key);
6323
- state = { isLoading: true, data: state.data };
6324
- notify();
6325
- }
6326
- await resolve();
6327
- }
6328
- return getState();
6329
- }
6330
- function getState() {
6331
- return state;
6332
- }
6333
- function setAsyncFunction(overrideAsyncFunction) {
6334
- asyncFunction = overrideAsyncFunction;
6335
- }
6336
- return {
6337
- ...eventSource2.observable,
6338
- setAsyncFunction,
6339
- get,
6340
- getState,
6341
- revalidate
6342
- };
6343
- }
6344
- function createAsyncCache(asyncFunction, options) {
6345
- const cache = /* @__PURE__ */ new Map();
6346
- function create(key, overrideAsyncFunction) {
6347
- let cacheItem = cache.get(key);
6348
- if (cacheItem) {
6349
- if (overrideAsyncFunction) {
6350
- cacheItem.setAsyncFunction(overrideAsyncFunction);
6351
- }
6352
- return cacheItem;
6353
- }
6354
- cacheItem = createCacheItem(
6355
- key,
6356
- _nullishCoalesce(overrideAsyncFunction, () => ( asyncFunction)),
6357
- options
6358
- );
6359
- cache.set(key, cacheItem);
6360
- return cacheItem;
6361
- }
6362
- function get(key) {
6363
- return create(key).get();
6364
- }
6365
- function getState(key) {
6366
- return _optionalChain([cache, 'access', _147 => _147.get, 'call', _148 => _148(key), 'optionalAccess', _149 => _149.getState, 'call', _150 => _150()]);
6367
- }
6368
- function revalidate(key) {
6369
- return create(key).revalidate();
6370
- }
6371
- function subscribe(key, callback) {
6372
- return _nullishCoalesce(create(key).subscribe(callback), () => ( noop));
6373
- }
6374
- function subscribeOnce(key, callback) {
6375
- return _nullishCoalesce(create(key).subscribeOnce(callback), () => ( noop));
6376
- }
6377
- function has(key) {
6378
- return cache.has(key);
6379
- }
6380
- function clear() {
6381
- cache.clear();
6382
- }
6383
- return {
6384
- create,
6385
- get,
6386
- getState,
6387
- revalidate,
6388
- subscribe,
6389
- subscribeOnce,
6390
- has,
6391
- clear
6392
- };
6393
- }
6394
-
6395
- // src/lib/Poller.ts
6396
- function makePoller(callback) {
6397
- let context = {
6398
- state: "stopped",
6399
- timeoutHandle: null,
6400
- interval: null,
6401
- lastScheduledAt: null,
6402
- remainingInterval: null
6403
- };
6404
- function poll() {
6405
- if (context.state === "running") {
6406
- schedule(context.interval);
6407
- }
6408
- callback();
6409
- }
6410
- function schedule(interval) {
6411
- context = {
6412
- state: "running",
6413
- interval: context.state !== "stopped" ? context.interval : interval,
6414
- lastScheduledAt: performance.now(),
6415
- timeoutHandle: setTimeout(poll, interval),
6416
- remainingInterval: null
6417
- };
6418
- }
6419
- function scheduleRemaining(remaining) {
6420
- if (context.state !== "paused") {
6421
- return;
6422
- }
6423
- context = {
6424
- state: "running",
6425
- interval: context.interval,
6426
- lastScheduledAt: context.lastScheduledAt,
6427
- timeoutHandle: setTimeout(poll, remaining),
6428
- remainingInterval: null
6429
- };
6430
- }
6431
- function start(interval) {
6432
- if (context.state === "running") {
6433
- return;
6434
- }
6435
- schedule(interval);
6436
- }
6437
- function restart(interval) {
6438
- stop();
6439
- start(interval);
6440
- }
6441
- function pause() {
6442
- if (context.state !== "running") {
6443
- return;
6444
- }
6445
- clearTimeout(context.timeoutHandle);
6446
- context = {
6447
- state: "paused",
6448
- interval: context.interval,
6449
- lastScheduledAt: context.lastScheduledAt,
6450
- timeoutHandle: null,
6451
- remainingInterval: context.interval - (performance.now() - context.lastScheduledAt)
6452
- };
6453
- }
6454
- function resume() {
6455
- if (context.state !== "paused") {
6456
- return;
6457
- }
6458
- scheduleRemaining(context.remainingInterval);
6459
- }
6460
- function stop() {
6461
- if (context.state === "stopped") {
6462
- return;
6463
- }
6464
- if (context.timeoutHandle) {
6465
- clearTimeout(context.timeoutHandle);
6466
- }
6467
- context = {
6468
- state: "stopped",
6469
- interval: null,
6470
- lastScheduledAt: null,
6471
- timeoutHandle: null,
6472
- remainingInterval: null
6473
- };
6474
- }
6475
- return {
6476
- start,
6477
- restart,
6478
- pause,
6479
- resume,
6480
- stop
6481
- };
6482
- }
6483
-
6484
6088
  // src/index.ts
6485
6089
  detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
6486
6090
 
@@ -6519,10 +6123,5 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
6519
6123
 
6520
6124
 
6521
6125
 
6522
-
6523
-
6524
-
6525
-
6526
-
6527
- exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asArrayWithLegacyMethods = asArrayWithLegacyMethods; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.console = fancy_console_exports; exports.createAsyncCache = createAsyncCache; exports.createClient = createClient; exports.createCommentsApi = createCommentsApi; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.shallow = shallow; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
6126
+ exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asArrayWithLegacyMethods = asArrayWithLegacyMethods; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.createClient = createClient; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.shallow = shallow; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
6528
6127
  //# sourceMappingURL=index.js.map