@liveblocks/core 1.2.1 → 1.2.2-comments2
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.d.mts +369 -11
- package/dist/index.d.ts +369 -11
- package/dist/index.js +457 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +415 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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; }
|
|
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
|
|
2
8
|
var PKG_NAME = "@liveblocks/core";
|
|
3
|
-
var PKG_VERSION = "1.2.
|
|
9
|
+
var PKG_VERSION = "1.2.2-comments2";
|
|
4
10
|
var PKG_FORMAT = "cjs";
|
|
5
11
|
|
|
6
12
|
// src/dupe-detection.ts
|
|
@@ -150,6 +156,13 @@ function makeEventSource() {
|
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
// 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
|
+
});
|
|
153
166
|
var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
|
|
154
167
|
var bold = "font-weight:600";
|
|
155
168
|
function wrap(method) {
|
|
@@ -624,6 +637,11 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
|
|
|
624
637
|
ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
|
|
625
638
|
ServerMsgCode2[ServerMsgCode2["REJECT_STORAGE_OP"] = 299] = "REJECT_STORAGE_OP";
|
|
626
639
|
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";
|
|
627
645
|
return ServerMsgCode2;
|
|
628
646
|
})(ServerMsgCode || {});
|
|
629
647
|
|
|
@@ -1152,10 +1170,10 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
1152
1170
|
};
|
|
1153
1171
|
}
|
|
1154
1172
|
var ManagedSocket = class {
|
|
1155
|
-
constructor(delegates, enableDebugLogging = false) {
|
|
1173
|
+
constructor(delegates, enableDebugLogging = false, waitForActorId = true) {
|
|
1156
1174
|
const { machine, events, cleanups } = createConnectionStateMachine(
|
|
1157
1175
|
delegates,
|
|
1158
|
-
{ waitForActorId
|
|
1176
|
+
{ waitForActorId, enableDebugLogging }
|
|
1159
1177
|
);
|
|
1160
1178
|
this.machine = machine;
|
|
1161
1179
|
this.events = events;
|
|
@@ -1237,6 +1255,9 @@ var ManagedSocket = class {
|
|
|
1237
1255
|
function canWriteStorage(scopes) {
|
|
1238
1256
|
return scopes.includes("room:write" /* Write */);
|
|
1239
1257
|
}
|
|
1258
|
+
function canComment(scopes) {
|
|
1259
|
+
return scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:write" /* Write */);
|
|
1260
|
+
}
|
|
1240
1261
|
function isValidAuthTokenPayload(data) {
|
|
1241
1262
|
return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */ || data.k === "sec-legacy" /* SECRET_LEGACY */);
|
|
1242
1263
|
}
|
|
@@ -1649,6 +1670,149 @@ function errorIf(condition, message) {
|
|
|
1649
1670
|
}
|
|
1650
1671
|
}
|
|
1651
1672
|
|
|
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
|
+
|
|
1652
1816
|
// src/lib/position.ts
|
|
1653
1817
|
var MIN_CODE = 32;
|
|
1654
1818
|
var MAX_CODE = 126;
|
|
@@ -2010,7 +2174,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
2010
2174
|
return [
|
|
2011
2175
|
{
|
|
2012
2176
|
type: 8 /* CREATE_REGISTER */,
|
|
2013
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2177
|
+
opId: _optionalChain([pool, 'optionalAccess', _44 => _44.generateOpId, 'call', _45 => _45()]),
|
|
2014
2178
|
id: this._id,
|
|
2015
2179
|
parentId,
|
|
2016
2180
|
parentKey,
|
|
@@ -2101,7 +2265,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2101
2265
|
const ops = [];
|
|
2102
2266
|
const op = {
|
|
2103
2267
|
id: this._id,
|
|
2104
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2268
|
+
opId: _optionalChain([pool, 'optionalAccess', _46 => _46.generateOpId, 'call', _47 => _47()]),
|
|
2105
2269
|
type: 2 /* CREATE_LIST */,
|
|
2106
2270
|
parentId,
|
|
2107
2271
|
parentKey
|
|
@@ -2369,7 +2533,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2369
2533
|
_applyInsertUndoRedo(op) {
|
|
2370
2534
|
const { id, parentKey: key } = op;
|
|
2371
2535
|
const child = creationOpToLiveNode(op);
|
|
2372
|
-
if (_optionalChain([this, 'access',
|
|
2536
|
+
if (_optionalChain([this, 'access', _48 => _48._pool, 'optionalAccess', _49 => _49.getNode, 'call', _50 => _50(id)]) !== void 0) {
|
|
2373
2537
|
return { modified: false };
|
|
2374
2538
|
}
|
|
2375
2539
|
child._attach(id, nn(this._pool));
|
|
@@ -2377,8 +2541,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2377
2541
|
const existingItemIndex = this._indexOfPosition(key);
|
|
2378
2542
|
let newKey = key;
|
|
2379
2543
|
if (existingItemIndex !== -1) {
|
|
2380
|
-
const before2 = _optionalChain([this, 'access',
|
|
2381
|
-
const after2 = _optionalChain([this, 'access',
|
|
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]);
|
|
2382
2546
|
newKey = makePosition(before2, after2);
|
|
2383
2547
|
child._setParentLink(this, newKey);
|
|
2384
2548
|
}
|
|
@@ -2393,7 +2557,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2393
2557
|
_applySetUndoRedo(op) {
|
|
2394
2558
|
const { id, parentKey: key } = op;
|
|
2395
2559
|
const child = creationOpToLiveNode(op);
|
|
2396
|
-
if (_optionalChain([this, 'access',
|
|
2560
|
+
if (_optionalChain([this, 'access', _57 => _57._pool, 'optionalAccess', _58 => _58.getNode, 'call', _59 => _59(id)]) !== void 0) {
|
|
2397
2561
|
return { modified: false };
|
|
2398
2562
|
}
|
|
2399
2563
|
this._unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -2515,7 +2679,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2515
2679
|
} else {
|
|
2516
2680
|
this._items[existingItemIndex]._setParentLink(
|
|
2517
2681
|
this,
|
|
2518
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2682
|
+
makePosition(newKey, _optionalChain([this, 'access', _60 => _60._items, 'access', _61 => _61[existingItemIndex + 1], 'optionalAccess', _62 => _62._parentPos]))
|
|
2519
2683
|
);
|
|
2520
2684
|
const previousIndex = this._items.indexOf(child);
|
|
2521
2685
|
child._setParentLink(this, newKey);
|
|
@@ -2541,7 +2705,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2541
2705
|
if (existingItemIndex !== -1) {
|
|
2542
2706
|
this._items[existingItemIndex]._setParentLink(
|
|
2543
2707
|
this,
|
|
2544
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2708
|
+
makePosition(newKey, _optionalChain([this, 'access', _63 => _63._items, 'access', _64 => _64[existingItemIndex + 1], 'optionalAccess', _65 => _65._parentPos]))
|
|
2545
2709
|
);
|
|
2546
2710
|
}
|
|
2547
2711
|
child._setParentLink(this, newKey);
|
|
@@ -2560,7 +2724,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2560
2724
|
if (existingItemIndex !== -1) {
|
|
2561
2725
|
this._items[existingItemIndex]._setParentLink(
|
|
2562
2726
|
this,
|
|
2563
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2727
|
+
makePosition(newKey, _optionalChain([this, 'access', _66 => _66._items, 'access', _67 => _67[existingItemIndex + 1], 'optionalAccess', _68 => _68._parentPos]))
|
|
2564
2728
|
);
|
|
2565
2729
|
}
|
|
2566
2730
|
child._setParentLink(this, newKey);
|
|
@@ -2588,7 +2752,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2588
2752
|
if (existingItemIndex !== -1) {
|
|
2589
2753
|
this._items[existingItemIndex]._setParentLink(
|
|
2590
2754
|
this,
|
|
2591
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2755
|
+
makePosition(newKey, _optionalChain([this, 'access', _69 => _69._items, 'access', _70 => _70[existingItemIndex + 1], 'optionalAccess', _71 => _71._parentPos]))
|
|
2592
2756
|
);
|
|
2593
2757
|
}
|
|
2594
2758
|
child._setParentLink(this, newKey);
|
|
@@ -2646,7 +2810,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2646
2810
|
* @param element The element to add to the end of the LiveList.
|
|
2647
2811
|
*/
|
|
2648
2812
|
push(element) {
|
|
2649
|
-
_optionalChain([this, 'access',
|
|
2813
|
+
_optionalChain([this, 'access', _72 => _72._pool, 'optionalAccess', _73 => _73.assertStorageIsWritable, 'call', _74 => _74()]);
|
|
2650
2814
|
return this.insert(element, this.length);
|
|
2651
2815
|
}
|
|
2652
2816
|
/**
|
|
@@ -2655,7 +2819,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2655
2819
|
* @param index The index at which you want to insert the element.
|
|
2656
2820
|
*/
|
|
2657
2821
|
insert(element, index) {
|
|
2658
|
-
_optionalChain([this, 'access',
|
|
2822
|
+
_optionalChain([this, 'access', _75 => _75._pool, 'optionalAccess', _76 => _76.assertStorageIsWritable, 'call', _77 => _77()]);
|
|
2659
2823
|
if (index < 0 || index > this._items.length) {
|
|
2660
2824
|
throw new Error(
|
|
2661
2825
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
|
|
@@ -2685,7 +2849,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2685
2849
|
* @param targetIndex The index where the element should be after moving.
|
|
2686
2850
|
*/
|
|
2687
2851
|
move(index, targetIndex) {
|
|
2688
|
-
_optionalChain([this, 'access',
|
|
2852
|
+
_optionalChain([this, 'access', _78 => _78._pool, 'optionalAccess', _79 => _79.assertStorageIsWritable, 'call', _80 => _80()]);
|
|
2689
2853
|
if (targetIndex < 0) {
|
|
2690
2854
|
throw new Error("targetIndex cannot be less than 0");
|
|
2691
2855
|
}
|
|
@@ -2743,7 +2907,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2743
2907
|
* @param index The index of the element to delete
|
|
2744
2908
|
*/
|
|
2745
2909
|
delete(index) {
|
|
2746
|
-
_optionalChain([this, 'access',
|
|
2910
|
+
_optionalChain([this, 'access', _81 => _81._pool, 'optionalAccess', _82 => _82.assertStorageIsWritable, 'call', _83 => _83()]);
|
|
2747
2911
|
if (index < 0 || index >= this._items.length) {
|
|
2748
2912
|
throw new Error(
|
|
2749
2913
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -2776,7 +2940,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2776
2940
|
}
|
|
2777
2941
|
}
|
|
2778
2942
|
clear() {
|
|
2779
|
-
_optionalChain([this, 'access',
|
|
2943
|
+
_optionalChain([this, 'access', _84 => _84._pool, 'optionalAccess', _85 => _85.assertStorageIsWritable, 'call', _86 => _86()]);
|
|
2780
2944
|
if (this._pool) {
|
|
2781
2945
|
const ops = [];
|
|
2782
2946
|
const reverseOps = [];
|
|
@@ -2810,7 +2974,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2810
2974
|
}
|
|
2811
2975
|
}
|
|
2812
2976
|
set(index, item) {
|
|
2813
|
-
_optionalChain([this, 'access',
|
|
2977
|
+
_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.assertStorageIsWritable, 'call', _89 => _89()]);
|
|
2814
2978
|
if (index < 0 || index >= this._items.length) {
|
|
2815
2979
|
throw new Error(
|
|
2816
2980
|
`Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -2958,7 +3122,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2958
3122
|
_shiftItemPosition(index, key) {
|
|
2959
3123
|
const shiftedPosition = makePosition(
|
|
2960
3124
|
key,
|
|
2961
|
-
this._items.length > index + 1 ? _optionalChain([this, 'access',
|
|
3125
|
+
this._items.length > index + 1 ? _optionalChain([this, 'access', _90 => _90._items, 'access', _91 => _91[index + 1], 'optionalAccess', _92 => _92._parentPos]) : void 0
|
|
2962
3126
|
);
|
|
2963
3127
|
this._items[index]._setParentLink(this, shiftedPosition);
|
|
2964
3128
|
}
|
|
@@ -3084,7 +3248,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3084
3248
|
const ops = [];
|
|
3085
3249
|
const op = {
|
|
3086
3250
|
id: this._id,
|
|
3087
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
3251
|
+
opId: _optionalChain([pool, 'optionalAccess', _93 => _93.generateOpId, 'call', _94 => _94()]),
|
|
3088
3252
|
type: 7 /* CREATE_MAP */,
|
|
3089
3253
|
parentId,
|
|
3090
3254
|
parentKey
|
|
@@ -3231,7 +3395,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3231
3395
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
3232
3396
|
*/
|
|
3233
3397
|
set(key, value) {
|
|
3234
|
-
_optionalChain([this, 'access',
|
|
3398
|
+
_optionalChain([this, 'access', _95 => _95._pool, 'optionalAccess', _96 => _96.assertStorageIsWritable, 'call', _97 => _97()]);
|
|
3235
3399
|
const oldValue = this._map.get(key);
|
|
3236
3400
|
if (oldValue) {
|
|
3237
3401
|
oldValue._detach();
|
|
@@ -3277,7 +3441,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3277
3441
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
3278
3442
|
*/
|
|
3279
3443
|
delete(key) {
|
|
3280
|
-
_optionalChain([this, 'access',
|
|
3444
|
+
_optionalChain([this, 'access', _98 => _98._pool, 'optionalAccess', _99 => _99.assertStorageIsWritable, 'call', _100 => _100()]);
|
|
3281
3445
|
const item = this._map.get(key);
|
|
3282
3446
|
if (item === void 0) {
|
|
3283
3447
|
return false;
|
|
@@ -3451,7 +3615,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3451
3615
|
if (this._id === void 0) {
|
|
3452
3616
|
throw new Error("Cannot serialize item is not attached");
|
|
3453
3617
|
}
|
|
3454
|
-
const opId = _optionalChain([pool, 'optionalAccess',
|
|
3618
|
+
const opId = _optionalChain([pool, 'optionalAccess', _101 => _101.generateOpId, 'call', _102 => _102()]);
|
|
3455
3619
|
const ops = [];
|
|
3456
3620
|
const op = parentId !== void 0 && parentKey !== void 0 ? {
|
|
3457
3621
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -3732,7 +3896,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3732
3896
|
* @param value The value of the property to add
|
|
3733
3897
|
*/
|
|
3734
3898
|
set(key, value) {
|
|
3735
|
-
_optionalChain([this, 'access',
|
|
3899
|
+
_optionalChain([this, 'access', _103 => _103._pool, 'optionalAccess', _104 => _104.assertStorageIsWritable, 'call', _105 => _105()]);
|
|
3736
3900
|
this.update({ [key]: value });
|
|
3737
3901
|
}
|
|
3738
3902
|
/**
|
|
@@ -3747,7 +3911,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3747
3911
|
* @param key The key of the property to delete
|
|
3748
3912
|
*/
|
|
3749
3913
|
delete(key) {
|
|
3750
|
-
_optionalChain([this, 'access',
|
|
3914
|
+
_optionalChain([this, 'access', _106 => _106._pool, 'optionalAccess', _107 => _107.assertStorageIsWritable, 'call', _108 => _108()]);
|
|
3751
3915
|
const keyAsString = key;
|
|
3752
3916
|
const oldValue = this._map.get(keyAsString);
|
|
3753
3917
|
if (oldValue === void 0) {
|
|
@@ -3800,7 +3964,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3800
3964
|
* @param patch The object used to overrides properties
|
|
3801
3965
|
*/
|
|
3802
3966
|
update(patch) {
|
|
3803
|
-
_optionalChain([this, 'access',
|
|
3967
|
+
_optionalChain([this, 'access', _109 => _109._pool, 'optionalAccess', _110 => _110.assertStorageIsWritable, 'call', _111 => _111()]);
|
|
3804
3968
|
if (this._pool === void 0 || this._id === void 0) {
|
|
3805
3969
|
for (const key in patch) {
|
|
3806
3970
|
const newValue = patch[key];
|
|
@@ -4251,6 +4415,7 @@ function makeUser(conn, presence) {
|
|
|
4251
4415
|
id,
|
|
4252
4416
|
info,
|
|
4253
4417
|
canWrite,
|
|
4418
|
+
canComment: canComment(conn.scopes),
|
|
4254
4419
|
isReadOnly: !canWrite,
|
|
4255
4420
|
// Deprecated, kept for backward-compatibility
|
|
4256
4421
|
presence
|
|
@@ -4611,7 +4776,7 @@ function createRoom(options, config) {
|
|
|
4611
4776
|
}
|
|
4612
4777
|
},
|
|
4613
4778
|
assertStorageIsWritable: () => {
|
|
4614
|
-
const scopes = _optionalChain([context, 'access',
|
|
4779
|
+
const scopes = _optionalChain([context, 'access', _112 => _112.dynamicSessionInfo, 'access', _113 => _113.current, 'optionalAccess', _114 => _114.scopes]);
|
|
4615
4780
|
if (scopes === void 0) {
|
|
4616
4781
|
return;
|
|
4617
4782
|
}
|
|
@@ -4638,19 +4803,20 @@ function createRoom(options, config) {
|
|
|
4638
4803
|
history: makeEventSource(),
|
|
4639
4804
|
storageDidLoad: makeEventSource(),
|
|
4640
4805
|
storageStatus: makeEventSource(),
|
|
4641
|
-
ydoc: makeEventSource()
|
|
4806
|
+
ydoc: makeEventSource(),
|
|
4807
|
+
comments: makeEventSource()
|
|
4642
4808
|
};
|
|
4643
4809
|
function sendMessages(messageOrMessages) {
|
|
4644
4810
|
const message = JSON.stringify(messageOrMessages);
|
|
4645
4811
|
if (config.unstable_fallbackToHTTP) {
|
|
4646
4812
|
const size = new TextEncoder().encode(message).length;
|
|
4647
4813
|
if (size > MAX_MESSAGE_SIZE && // TODO: support public api key auth in REST API
|
|
4648
|
-
_optionalChain([managedSocket, 'access',
|
|
4814
|
+
_optionalChain([managedSocket, 'access', _115 => _115.authValue, 'optionalAccess', _116 => _116.type]) === "secret" && config.httpSendEndpoint) {
|
|
4649
4815
|
void httpSend(
|
|
4650
4816
|
message,
|
|
4651
4817
|
managedSocket.authValue.token.raw,
|
|
4652
4818
|
config.httpSendEndpoint,
|
|
4653
|
-
_optionalChain([config, 'access',
|
|
4819
|
+
_optionalChain([config, 'access', _117 => _117.polyfills, 'optionalAccess', _118 => _118.fetch])
|
|
4654
4820
|
).then((resp) => {
|
|
4655
4821
|
if (!resp.ok && resp.status === 403) {
|
|
4656
4822
|
managedSocket.reconnect();
|
|
@@ -4679,6 +4845,7 @@ function createRoom(options, config) {
|
|
|
4679
4845
|
info: staticSession.userInfo,
|
|
4680
4846
|
presence: myPresence,
|
|
4681
4847
|
canWrite,
|
|
4848
|
+
canComment: canComment(dynamicSession.scopes),
|
|
4682
4849
|
isReadOnly: !canWrite
|
|
4683
4850
|
// Deprecated, kept for backward-compatibility
|
|
4684
4851
|
};
|
|
@@ -4906,7 +5073,7 @@ function createRoom(options, config) {
|
|
|
4906
5073
|
}
|
|
4907
5074
|
context.myPresence.patch(patch);
|
|
4908
5075
|
if (context.activeBatch) {
|
|
4909
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5076
|
+
if (_optionalChain([options2, 'optionalAccess', _119 => _119.addToHistory])) {
|
|
4910
5077
|
context.activeBatch.reverseOps.unshift({
|
|
4911
5078
|
type: "presence",
|
|
4912
5079
|
data: oldValues
|
|
@@ -4916,7 +5083,7 @@ function createRoom(options, config) {
|
|
|
4916
5083
|
} else {
|
|
4917
5084
|
flushNowOrSoon();
|
|
4918
5085
|
batchUpdates(() => {
|
|
4919
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5086
|
+
if (_optionalChain([options2, 'optionalAccess', _120 => _120.addToHistory])) {
|
|
4920
5087
|
addToUndoStack(
|
|
4921
5088
|
[{ type: "presence", data: oldValues }],
|
|
4922
5089
|
doNotBatchUpdates
|
|
@@ -5093,7 +5260,7 @@ function createRoom(options, config) {
|
|
|
5093
5260
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
5094
5261
|
createOrUpdateRootFromMessage(message, doNotBatchUpdates);
|
|
5095
5262
|
applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
|
|
5096
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
5263
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _121 => _121()]);
|
|
5097
5264
|
notifyStorageStatus();
|
|
5098
5265
|
eventHub.storageDidLoad.notify();
|
|
5099
5266
|
break;
|
|
@@ -5116,7 +5283,7 @@ function createRoom(options, config) {
|
|
|
5116
5283
|
if (process.env.NODE_ENV !== "production") {
|
|
5117
5284
|
const traces = /* @__PURE__ */ new Set();
|
|
5118
5285
|
for (const opId of message.opIds) {
|
|
5119
|
-
const trace = _optionalChain([context, 'access',
|
|
5286
|
+
const trace = _optionalChain([context, 'access', _122 => _122.opStackTraces, 'optionalAccess', _123 => _123.get, 'call', _124 => _124(opId)]);
|
|
5120
5287
|
if (trace) {
|
|
5121
5288
|
traces.add(trace);
|
|
5122
5289
|
}
|
|
@@ -5135,6 +5302,14 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5135
5302
|
}
|
|
5136
5303
|
break;
|
|
5137
5304
|
}
|
|
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
|
+
}
|
|
5138
5313
|
}
|
|
5139
5314
|
}
|
|
5140
5315
|
notify(updates, doNotBatchUpdates);
|
|
@@ -5268,10 +5443,14 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5268
5443
|
};
|
|
5269
5444
|
}
|
|
5270
5445
|
function fetchYDoc(vector) {
|
|
5271
|
-
context.buffer.messages.
|
|
5272
|
-
type
|
|
5273
|
-
|
|
5274
|
-
|
|
5446
|
+
if (!context.buffer.messages.find((m) => {
|
|
5447
|
+
return m.type === 300 /* FETCH_YDOC */ && m.vector === vector;
|
|
5448
|
+
})) {
|
|
5449
|
+
context.buffer.messages.push({
|
|
5450
|
+
type: 300 /* FETCH_YDOC */,
|
|
5451
|
+
vector
|
|
5452
|
+
});
|
|
5453
|
+
}
|
|
5275
5454
|
flushNowOrSoon();
|
|
5276
5455
|
}
|
|
5277
5456
|
function undo() {
|
|
@@ -5397,14 +5576,18 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5397
5576
|
history: eventHub.history.observable,
|
|
5398
5577
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
5399
5578
|
storageStatus: eventHub.storageStatus.observable,
|
|
5400
|
-
ydoc: eventHub.ydoc.observable
|
|
5579
|
+
ydoc: eventHub.ydoc.observable,
|
|
5580
|
+
comments: eventHub.comments.observable
|
|
5401
5581
|
};
|
|
5582
|
+
const commentsApi = createCommentsApi(config.roomId, delegates.authenticate, {
|
|
5583
|
+
serverEndpoint: "https://api.liveblocks.io/v2"
|
|
5584
|
+
});
|
|
5402
5585
|
return Object.defineProperty(
|
|
5403
5586
|
{
|
|
5404
5587
|
/* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
|
|
5405
5588
|
__internal: {
|
|
5406
5589
|
get presenceBuffer() {
|
|
5407
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
5590
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _125 => _125.buffer, 'access', _126 => _126.presenceUpdates, 'optionalAccess', _127 => _127.data]), () => ( null)));
|
|
5408
5591
|
},
|
|
5409
5592
|
// prettier-ignore
|
|
5410
5593
|
get undoStack() {
|
|
@@ -5456,7 +5639,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5456
5639
|
getSelf: () => self.current,
|
|
5457
5640
|
// Presence
|
|
5458
5641
|
getPresence: () => context.myPresence.current,
|
|
5459
|
-
getOthers: () => context.others.current
|
|
5642
|
+
getOthers: () => context.others.current,
|
|
5643
|
+
...commentsApi
|
|
5460
5644
|
},
|
|
5461
5645
|
// Explictly make the __internal field non-enumerable, to avoid aggressive
|
|
5462
5646
|
// freezing when used with Immer
|
|
@@ -5535,7 +5719,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
5535
5719
|
}
|
|
5536
5720
|
if (isLiveNode(first)) {
|
|
5537
5721
|
const node = first;
|
|
5538
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5722
|
+
if (_optionalChain([options, 'optionalAccess', _128 => _128.isDeep])) {
|
|
5539
5723
|
const storageCallback = second;
|
|
5540
5724
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
5541
5725
|
} else {
|
|
@@ -5636,12 +5820,12 @@ function createClient(options) {
|
|
|
5636
5820
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
5637
5821
|
roomId,
|
|
5638
5822
|
getServerFromClientOptions(clientOptions),
|
|
5639
|
-
_optionalChain([clientOptions, 'access',
|
|
5823
|
+
_optionalChain([clientOptions, 'access', _129 => _129.polyfills, 'optionalAccess', _130 => _130.WebSocket])
|
|
5640
5824
|
),
|
|
5641
5825
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
5642
5826
|
})),
|
|
5643
5827
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
5644
|
-
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess',
|
|
5828
|
+
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _131 => _131.unstable_batchedUpdates]),
|
|
5645
5829
|
liveblocksServer: getServerFromClientOptions(clientOptions),
|
|
5646
5830
|
httpSendEndpoint: buildLiveblocksHttpSendEndpoint(
|
|
5647
5831
|
clientOptions,
|
|
@@ -5656,7 +5840,7 @@ function createClient(options) {
|
|
|
5656
5840
|
const shouldConnect = _nullishCoalesce(options2.shouldInitiallyConnect, () => ( true));
|
|
5657
5841
|
if (shouldConnect) {
|
|
5658
5842
|
if (typeof atob === "undefined") {
|
|
5659
|
-
if (_optionalChain([clientOptions, 'access',
|
|
5843
|
+
if (_optionalChain([clientOptions, 'access', _132 => _132.polyfills, 'optionalAccess', _133 => _133.atob]) === void 0) {
|
|
5660
5844
|
throw new Error(
|
|
5661
5845
|
"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"
|
|
5662
5846
|
);
|
|
@@ -5939,12 +6123,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
5939
6123
|
}
|
|
5940
6124
|
const newState = Object.assign({}, state);
|
|
5941
6125
|
for (const key in update.updates) {
|
|
5942
|
-
if (_optionalChain([update, 'access',
|
|
6126
|
+
if (_optionalChain([update, 'access', _134 => _134.updates, 'access', _135 => _135[key], 'optionalAccess', _136 => _136.type]) === "update") {
|
|
5943
6127
|
const val = update.node.get(key);
|
|
5944
6128
|
if (val !== void 0) {
|
|
5945
6129
|
newState[key] = lsonToJson(val);
|
|
5946
6130
|
}
|
|
5947
|
-
} else if (_optionalChain([update, 'access',
|
|
6131
|
+
} else if (_optionalChain([update, 'access', _137 => _137.updates, 'access', _138 => _138[key], 'optionalAccess', _139 => _139.type]) === "delete") {
|
|
5948
6132
|
delete newState[key];
|
|
5949
6133
|
}
|
|
5950
6134
|
}
|
|
@@ -6005,12 +6189,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
6005
6189
|
}
|
|
6006
6190
|
const newState = Object.assign({}, state);
|
|
6007
6191
|
for (const key in update.updates) {
|
|
6008
|
-
if (_optionalChain([update, 'access',
|
|
6192
|
+
if (_optionalChain([update, 'access', _140 => _140.updates, 'access', _141 => _141[key], 'optionalAccess', _142 => _142.type]) === "update") {
|
|
6009
6193
|
const value = update.node.get(key);
|
|
6010
6194
|
if (value !== void 0) {
|
|
6011
6195
|
newState[key] = lsonToJson(value);
|
|
6012
6196
|
}
|
|
6013
|
-
} else if (_optionalChain([update, 'access',
|
|
6197
|
+
} else if (_optionalChain([update, 'access', _143 => _143.updates, 'access', _144 => _144[key], 'optionalAccess', _145 => _145.type]) === "delete") {
|
|
6014
6198
|
delete newState[key];
|
|
6015
6199
|
}
|
|
6016
6200
|
}
|
|
@@ -6081,6 +6265,222 @@ function shallow(a, b) {
|
|
|
6081
6265
|
return shallowObj(a, b);
|
|
6082
6266
|
}
|
|
6083
6267
|
|
|
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
|
+
|
|
6084
6484
|
// src/index.ts
|
|
6085
6485
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
6086
6486
|
|
|
@@ -6119,5 +6519,10 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
6119
6519
|
|
|
6120
6520
|
|
|
6121
6521
|
|
|
6122
|
-
|
|
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;
|
|
6123
6528
|
//# sourceMappingURL=index.js.map
|