@liveblocks/core 1.2.3 → 1.3.0
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 +373 -28
- package/dist/index.d.ts +373 -28
- package/dist/index.js +449 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +408 -21
- 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.
|
|
9
|
+
var PKG_VERSION = "1.3.0";
|
|
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
|
}
|
|
@@ -1647,6 +1668,149 @@ function errorIf(condition, message) {
|
|
|
1647
1668
|
}
|
|
1648
1669
|
}
|
|
1649
1670
|
|
|
1671
|
+
// src/comments/index.ts
|
|
1672
|
+
function getAuthBearerHeaderFromAuthValue(authValue) {
|
|
1673
|
+
if (authValue.type === "public") {
|
|
1674
|
+
return authValue.publicApiKey;
|
|
1675
|
+
} else {
|
|
1676
|
+
return authValue.token.raw;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
1680
|
+
async function fetchJson(endpoint, options) {
|
|
1681
|
+
const response = await fetchApi(roomId, endpoint, options);
|
|
1682
|
+
if (!response.ok) {
|
|
1683
|
+
if (response.status >= 400 && response.status < 600) {
|
|
1684
|
+
let errorMessage = "";
|
|
1685
|
+
try {
|
|
1686
|
+
const errorBody = await response.json();
|
|
1687
|
+
errorMessage = errorBody.message;
|
|
1688
|
+
} catch (error3) {
|
|
1689
|
+
errorMessage = response.statusText;
|
|
1690
|
+
}
|
|
1691
|
+
throw new Error(
|
|
1692
|
+
`Request failed with status ${response.status}: ${errorMessage}`
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
let body;
|
|
1697
|
+
try {
|
|
1698
|
+
body = await response.json();
|
|
1699
|
+
} catch (e3) {
|
|
1700
|
+
body = {};
|
|
1701
|
+
}
|
|
1702
|
+
return body;
|
|
1703
|
+
}
|
|
1704
|
+
async function fetchApi(roomId2, endpoint, options) {
|
|
1705
|
+
const authValue = await getAuthValue();
|
|
1706
|
+
const url = `${serverEndpoint}/c/rooms/${roomId2}${endpoint}`;
|
|
1707
|
+
return await fetch(url, {
|
|
1708
|
+
...options,
|
|
1709
|
+
headers: {
|
|
1710
|
+
..._optionalChain([options, 'optionalAccess', _43 => _43.headers]),
|
|
1711
|
+
Authorization: `Bearer ${getAuthBearerHeaderFromAuthValue(authValue)}`
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
async function getThreads() {
|
|
1716
|
+
const response = await fetchApi(roomId, "/threads");
|
|
1717
|
+
if (response.ok) {
|
|
1718
|
+
const json = await response.json();
|
|
1719
|
+
return json.data;
|
|
1720
|
+
} else if (response.status === 404) {
|
|
1721
|
+
return [];
|
|
1722
|
+
} else {
|
|
1723
|
+
throw new Error("There was an error while getting threads.");
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
function createThread({
|
|
1727
|
+
metadata,
|
|
1728
|
+
body,
|
|
1729
|
+
commentId,
|
|
1730
|
+
threadId
|
|
1731
|
+
}) {
|
|
1732
|
+
return fetchJson("/threads", {
|
|
1733
|
+
method: "POST",
|
|
1734
|
+
headers: {
|
|
1735
|
+
"Content-Type": "application/json"
|
|
1736
|
+
},
|
|
1737
|
+
body: JSON.stringify({
|
|
1738
|
+
id: threadId,
|
|
1739
|
+
comment: {
|
|
1740
|
+
id: commentId,
|
|
1741
|
+
body
|
|
1742
|
+
},
|
|
1743
|
+
metadata
|
|
1744
|
+
})
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
function editThreadMetadata({
|
|
1748
|
+
metadata,
|
|
1749
|
+
threadId
|
|
1750
|
+
}) {
|
|
1751
|
+
return fetchJson(
|
|
1752
|
+
`/threads/${threadId}/metadata`,
|
|
1753
|
+
{
|
|
1754
|
+
method: "POST",
|
|
1755
|
+
headers: {
|
|
1756
|
+
"Content-Type": "application/json"
|
|
1757
|
+
},
|
|
1758
|
+
body: JSON.stringify(metadata)
|
|
1759
|
+
}
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
function createComment({
|
|
1763
|
+
threadId,
|
|
1764
|
+
commentId,
|
|
1765
|
+
body
|
|
1766
|
+
}) {
|
|
1767
|
+
return fetchJson(`/threads/${threadId}/comments`, {
|
|
1768
|
+
method: "POST",
|
|
1769
|
+
headers: {
|
|
1770
|
+
"Content-Type": "application/json"
|
|
1771
|
+
},
|
|
1772
|
+
body: JSON.stringify({
|
|
1773
|
+
id: commentId,
|
|
1774
|
+
body
|
|
1775
|
+
})
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
function editComment({
|
|
1779
|
+
threadId,
|
|
1780
|
+
commentId,
|
|
1781
|
+
body
|
|
1782
|
+
}) {
|
|
1783
|
+
return fetchJson(
|
|
1784
|
+
`/threads/${threadId}/comments/${commentId}`,
|
|
1785
|
+
{
|
|
1786
|
+
method: "POST",
|
|
1787
|
+
headers: {
|
|
1788
|
+
"Content-Type": "application/json"
|
|
1789
|
+
},
|
|
1790
|
+
body: JSON.stringify({
|
|
1791
|
+
body
|
|
1792
|
+
})
|
|
1793
|
+
}
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
async function deleteComment({
|
|
1797
|
+
threadId,
|
|
1798
|
+
commentId
|
|
1799
|
+
}) {
|
|
1800
|
+
await fetchJson(`/threads/${threadId}/comments/${commentId}`, {
|
|
1801
|
+
method: "DELETE"
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
return {
|
|
1805
|
+
getThreads,
|
|
1806
|
+
createThread,
|
|
1807
|
+
editThreadMetadata,
|
|
1808
|
+
createComment,
|
|
1809
|
+
editComment,
|
|
1810
|
+
deleteComment
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1650
1814
|
// src/lib/position.ts
|
|
1651
1815
|
var MIN_CODE = 32;
|
|
1652
1816
|
var MAX_CODE = 126;
|
|
@@ -2008,7 +2172,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
2008
2172
|
return [
|
|
2009
2173
|
{
|
|
2010
2174
|
type: 8 /* CREATE_REGISTER */,
|
|
2011
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2175
|
+
opId: _optionalChain([pool, 'optionalAccess', _44 => _44.generateOpId, 'call', _45 => _45()]),
|
|
2012
2176
|
id: this._id,
|
|
2013
2177
|
parentId,
|
|
2014
2178
|
parentKey,
|
|
@@ -2099,7 +2263,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2099
2263
|
const ops = [];
|
|
2100
2264
|
const op = {
|
|
2101
2265
|
id: this._id,
|
|
2102
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2266
|
+
opId: _optionalChain([pool, 'optionalAccess', _46 => _46.generateOpId, 'call', _47 => _47()]),
|
|
2103
2267
|
type: 2 /* CREATE_LIST */,
|
|
2104
2268
|
parentId,
|
|
2105
2269
|
parentKey
|
|
@@ -2367,7 +2531,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2367
2531
|
_applyInsertUndoRedo(op) {
|
|
2368
2532
|
const { id, parentKey: key } = op;
|
|
2369
2533
|
const child = creationOpToLiveNode(op);
|
|
2370
|
-
if (_optionalChain([this, 'access',
|
|
2534
|
+
if (_optionalChain([this, 'access', _48 => _48._pool, 'optionalAccess', _49 => _49.getNode, 'call', _50 => _50(id)]) !== void 0) {
|
|
2371
2535
|
return { modified: false };
|
|
2372
2536
|
}
|
|
2373
2537
|
child._attach(id, nn(this._pool));
|
|
@@ -2375,8 +2539,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2375
2539
|
const existingItemIndex = this._indexOfPosition(key);
|
|
2376
2540
|
let newKey = key;
|
|
2377
2541
|
if (existingItemIndex !== -1) {
|
|
2378
|
-
const before2 = _optionalChain([this, 'access',
|
|
2379
|
-
const after2 = _optionalChain([this, 'access',
|
|
2542
|
+
const before2 = _optionalChain([this, 'access', _51 => _51._items, 'access', _52 => _52[existingItemIndex], 'optionalAccess', _53 => _53._parentPos]);
|
|
2543
|
+
const after2 = _optionalChain([this, 'access', _54 => _54._items, 'access', _55 => _55[existingItemIndex + 1], 'optionalAccess', _56 => _56._parentPos]);
|
|
2380
2544
|
newKey = makePosition(before2, after2);
|
|
2381
2545
|
child._setParentLink(this, newKey);
|
|
2382
2546
|
}
|
|
@@ -2391,7 +2555,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2391
2555
|
_applySetUndoRedo(op) {
|
|
2392
2556
|
const { id, parentKey: key } = op;
|
|
2393
2557
|
const child = creationOpToLiveNode(op);
|
|
2394
|
-
if (_optionalChain([this, 'access',
|
|
2558
|
+
if (_optionalChain([this, 'access', _57 => _57._pool, 'optionalAccess', _58 => _58.getNode, 'call', _59 => _59(id)]) !== void 0) {
|
|
2395
2559
|
return { modified: false };
|
|
2396
2560
|
}
|
|
2397
2561
|
this._unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -2513,7 +2677,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2513
2677
|
} else {
|
|
2514
2678
|
this._items[existingItemIndex]._setParentLink(
|
|
2515
2679
|
this,
|
|
2516
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2680
|
+
makePosition(newKey, _optionalChain([this, 'access', _60 => _60._items, 'access', _61 => _61[existingItemIndex + 1], 'optionalAccess', _62 => _62._parentPos]))
|
|
2517
2681
|
);
|
|
2518
2682
|
const previousIndex = this._items.indexOf(child);
|
|
2519
2683
|
child._setParentLink(this, newKey);
|
|
@@ -2539,7 +2703,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2539
2703
|
if (existingItemIndex !== -1) {
|
|
2540
2704
|
this._items[existingItemIndex]._setParentLink(
|
|
2541
2705
|
this,
|
|
2542
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2706
|
+
makePosition(newKey, _optionalChain([this, 'access', _63 => _63._items, 'access', _64 => _64[existingItemIndex + 1], 'optionalAccess', _65 => _65._parentPos]))
|
|
2543
2707
|
);
|
|
2544
2708
|
}
|
|
2545
2709
|
child._setParentLink(this, newKey);
|
|
@@ -2558,7 +2722,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2558
2722
|
if (existingItemIndex !== -1) {
|
|
2559
2723
|
this._items[existingItemIndex]._setParentLink(
|
|
2560
2724
|
this,
|
|
2561
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2725
|
+
makePosition(newKey, _optionalChain([this, 'access', _66 => _66._items, 'access', _67 => _67[existingItemIndex + 1], 'optionalAccess', _68 => _68._parentPos]))
|
|
2562
2726
|
);
|
|
2563
2727
|
}
|
|
2564
2728
|
child._setParentLink(this, newKey);
|
|
@@ -2586,7 +2750,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2586
2750
|
if (existingItemIndex !== -1) {
|
|
2587
2751
|
this._items[existingItemIndex]._setParentLink(
|
|
2588
2752
|
this,
|
|
2589
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2753
|
+
makePosition(newKey, _optionalChain([this, 'access', _69 => _69._items, 'access', _70 => _70[existingItemIndex + 1], 'optionalAccess', _71 => _71._parentPos]))
|
|
2590
2754
|
);
|
|
2591
2755
|
}
|
|
2592
2756
|
child._setParentLink(this, newKey);
|
|
@@ -2644,7 +2808,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2644
2808
|
* @param element The element to add to the end of the LiveList.
|
|
2645
2809
|
*/
|
|
2646
2810
|
push(element) {
|
|
2647
|
-
_optionalChain([this, 'access',
|
|
2811
|
+
_optionalChain([this, 'access', _72 => _72._pool, 'optionalAccess', _73 => _73.assertStorageIsWritable, 'call', _74 => _74()]);
|
|
2648
2812
|
return this.insert(element, this.length);
|
|
2649
2813
|
}
|
|
2650
2814
|
/**
|
|
@@ -2653,7 +2817,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2653
2817
|
* @param index The index at which you want to insert the element.
|
|
2654
2818
|
*/
|
|
2655
2819
|
insert(element, index) {
|
|
2656
|
-
_optionalChain([this, 'access',
|
|
2820
|
+
_optionalChain([this, 'access', _75 => _75._pool, 'optionalAccess', _76 => _76.assertStorageIsWritable, 'call', _77 => _77()]);
|
|
2657
2821
|
if (index < 0 || index > this._items.length) {
|
|
2658
2822
|
throw new Error(
|
|
2659
2823
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
|
|
@@ -2683,7 +2847,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2683
2847
|
* @param targetIndex The index where the element should be after moving.
|
|
2684
2848
|
*/
|
|
2685
2849
|
move(index, targetIndex) {
|
|
2686
|
-
_optionalChain([this, 'access',
|
|
2850
|
+
_optionalChain([this, 'access', _78 => _78._pool, 'optionalAccess', _79 => _79.assertStorageIsWritable, 'call', _80 => _80()]);
|
|
2687
2851
|
if (targetIndex < 0) {
|
|
2688
2852
|
throw new Error("targetIndex cannot be less than 0");
|
|
2689
2853
|
}
|
|
@@ -2741,7 +2905,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2741
2905
|
* @param index The index of the element to delete
|
|
2742
2906
|
*/
|
|
2743
2907
|
delete(index) {
|
|
2744
|
-
_optionalChain([this, 'access',
|
|
2908
|
+
_optionalChain([this, 'access', _81 => _81._pool, 'optionalAccess', _82 => _82.assertStorageIsWritable, 'call', _83 => _83()]);
|
|
2745
2909
|
if (index < 0 || index >= this._items.length) {
|
|
2746
2910
|
throw new Error(
|
|
2747
2911
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -2774,7 +2938,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2774
2938
|
}
|
|
2775
2939
|
}
|
|
2776
2940
|
clear() {
|
|
2777
|
-
_optionalChain([this, 'access',
|
|
2941
|
+
_optionalChain([this, 'access', _84 => _84._pool, 'optionalAccess', _85 => _85.assertStorageIsWritable, 'call', _86 => _86()]);
|
|
2778
2942
|
if (this._pool) {
|
|
2779
2943
|
const ops = [];
|
|
2780
2944
|
const reverseOps = [];
|
|
@@ -2808,7 +2972,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2808
2972
|
}
|
|
2809
2973
|
}
|
|
2810
2974
|
set(index, item) {
|
|
2811
|
-
_optionalChain([this, 'access',
|
|
2975
|
+
_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.assertStorageIsWritable, 'call', _89 => _89()]);
|
|
2812
2976
|
if (index < 0 || index >= this._items.length) {
|
|
2813
2977
|
throw new Error(
|
|
2814
2978
|
`Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -2956,7 +3120,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2956
3120
|
_shiftItemPosition(index, key) {
|
|
2957
3121
|
const shiftedPosition = makePosition(
|
|
2958
3122
|
key,
|
|
2959
|
-
this._items.length > index + 1 ? _optionalChain([this, 'access',
|
|
3123
|
+
this._items.length > index + 1 ? _optionalChain([this, 'access', _90 => _90._items, 'access', _91 => _91[index + 1], 'optionalAccess', _92 => _92._parentPos]) : void 0
|
|
2960
3124
|
);
|
|
2961
3125
|
this._items[index]._setParentLink(this, shiftedPosition);
|
|
2962
3126
|
}
|
|
@@ -3082,7 +3246,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3082
3246
|
const ops = [];
|
|
3083
3247
|
const op = {
|
|
3084
3248
|
id: this._id,
|
|
3085
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
3249
|
+
opId: _optionalChain([pool, 'optionalAccess', _93 => _93.generateOpId, 'call', _94 => _94()]),
|
|
3086
3250
|
type: 7 /* CREATE_MAP */,
|
|
3087
3251
|
parentId,
|
|
3088
3252
|
parentKey
|
|
@@ -3229,7 +3393,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3229
3393
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
3230
3394
|
*/
|
|
3231
3395
|
set(key, value) {
|
|
3232
|
-
_optionalChain([this, 'access',
|
|
3396
|
+
_optionalChain([this, 'access', _95 => _95._pool, 'optionalAccess', _96 => _96.assertStorageIsWritable, 'call', _97 => _97()]);
|
|
3233
3397
|
const oldValue = this._map.get(key);
|
|
3234
3398
|
if (oldValue) {
|
|
3235
3399
|
oldValue._detach();
|
|
@@ -3275,7 +3439,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3275
3439
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
3276
3440
|
*/
|
|
3277
3441
|
delete(key) {
|
|
3278
|
-
_optionalChain([this, 'access',
|
|
3442
|
+
_optionalChain([this, 'access', _98 => _98._pool, 'optionalAccess', _99 => _99.assertStorageIsWritable, 'call', _100 => _100()]);
|
|
3279
3443
|
const item = this._map.get(key);
|
|
3280
3444
|
if (item === void 0) {
|
|
3281
3445
|
return false;
|
|
@@ -3449,7 +3613,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3449
3613
|
if (this._id === void 0) {
|
|
3450
3614
|
throw new Error("Cannot serialize item is not attached");
|
|
3451
3615
|
}
|
|
3452
|
-
const opId = _optionalChain([pool, 'optionalAccess',
|
|
3616
|
+
const opId = _optionalChain([pool, 'optionalAccess', _101 => _101.generateOpId, 'call', _102 => _102()]);
|
|
3453
3617
|
const ops = [];
|
|
3454
3618
|
const op = parentId !== void 0 && parentKey !== void 0 ? {
|
|
3455
3619
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -3730,7 +3894,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3730
3894
|
* @param value The value of the property to add
|
|
3731
3895
|
*/
|
|
3732
3896
|
set(key, value) {
|
|
3733
|
-
_optionalChain([this, 'access',
|
|
3897
|
+
_optionalChain([this, 'access', _103 => _103._pool, 'optionalAccess', _104 => _104.assertStorageIsWritable, 'call', _105 => _105()]);
|
|
3734
3898
|
this.update({ [key]: value });
|
|
3735
3899
|
}
|
|
3736
3900
|
/**
|
|
@@ -3745,7 +3909,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3745
3909
|
* @param key The key of the property to delete
|
|
3746
3910
|
*/
|
|
3747
3911
|
delete(key) {
|
|
3748
|
-
_optionalChain([this, 'access',
|
|
3912
|
+
_optionalChain([this, 'access', _106 => _106._pool, 'optionalAccess', _107 => _107.assertStorageIsWritable, 'call', _108 => _108()]);
|
|
3749
3913
|
const keyAsString = key;
|
|
3750
3914
|
const oldValue = this._map.get(keyAsString);
|
|
3751
3915
|
if (oldValue === void 0) {
|
|
@@ -3798,7 +3962,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3798
3962
|
* @param patch The object used to overrides properties
|
|
3799
3963
|
*/
|
|
3800
3964
|
update(patch) {
|
|
3801
|
-
_optionalChain([this, 'access',
|
|
3965
|
+
_optionalChain([this, 'access', _109 => _109._pool, 'optionalAccess', _110 => _110.assertStorageIsWritable, 'call', _111 => _111()]);
|
|
3802
3966
|
if (this._pool === void 0 || this._id === void 0) {
|
|
3803
3967
|
for (const key in patch) {
|
|
3804
3968
|
const newValue = patch[key];
|
|
@@ -4190,19 +4354,6 @@ var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
|
|
|
4190
4354
|
return ClientMsgCode2;
|
|
4191
4355
|
})(ClientMsgCode || {});
|
|
4192
4356
|
|
|
4193
|
-
// src/lib/LegacyArray.ts
|
|
4194
|
-
function asArrayWithLegacyMethods(arr) {
|
|
4195
|
-
Object.defineProperty(arr, "count", {
|
|
4196
|
-
value: arr.length,
|
|
4197
|
-
enumerable: false
|
|
4198
|
-
});
|
|
4199
|
-
Object.defineProperty(arr, "toArray", {
|
|
4200
|
-
value: () => arr,
|
|
4201
|
-
enumerable: false
|
|
4202
|
-
});
|
|
4203
|
-
return freeze(arr);
|
|
4204
|
-
}
|
|
4205
|
-
|
|
4206
4357
|
// src/refs/ImmutableRef.ts
|
|
4207
4358
|
function merge(target, patch) {
|
|
4208
4359
|
let updated = false;
|
|
@@ -4249,6 +4400,7 @@ function makeUser(conn, presence) {
|
|
|
4249
4400
|
id,
|
|
4250
4401
|
info,
|
|
4251
4402
|
canWrite,
|
|
4403
|
+
canComment: canComment(conn.scopes),
|
|
4252
4404
|
isReadOnly: !canWrite,
|
|
4253
4405
|
// Deprecated, kept for backward-compatibility
|
|
4254
4406
|
presence
|
|
@@ -4275,7 +4427,7 @@ var OthersRef = class extends ImmutableRef {
|
|
|
4275
4427
|
(connectionId) => this.getUser(Number(connectionId))
|
|
4276
4428
|
)
|
|
4277
4429
|
);
|
|
4278
|
-
return
|
|
4430
|
+
return users;
|
|
4279
4431
|
}
|
|
4280
4432
|
clearOthers() {
|
|
4281
4433
|
this._connections = /* @__PURE__ */ new Map();
|
|
@@ -4609,7 +4761,7 @@ function createRoom(options, config) {
|
|
|
4609
4761
|
}
|
|
4610
4762
|
},
|
|
4611
4763
|
assertStorageIsWritable: () => {
|
|
4612
|
-
const scopes = _optionalChain([context, 'access',
|
|
4764
|
+
const scopes = _optionalChain([context, 'access', _112 => _112.dynamicSessionInfo, 'access', _113 => _113.current, 'optionalAccess', _114 => _114.scopes]);
|
|
4613
4765
|
if (scopes === void 0) {
|
|
4614
4766
|
return;
|
|
4615
4767
|
}
|
|
@@ -4636,19 +4788,20 @@ function createRoom(options, config) {
|
|
|
4636
4788
|
history: makeEventSource(),
|
|
4637
4789
|
storageDidLoad: makeEventSource(),
|
|
4638
4790
|
storageStatus: makeEventSource(),
|
|
4639
|
-
ydoc: makeEventSource()
|
|
4791
|
+
ydoc: makeEventSource(),
|
|
4792
|
+
comments: makeEventSource()
|
|
4640
4793
|
};
|
|
4641
4794
|
function sendMessages(messageOrMessages) {
|
|
4642
4795
|
const message = JSON.stringify(messageOrMessages);
|
|
4643
4796
|
if (config.unstable_fallbackToHTTP) {
|
|
4644
4797
|
const size = new TextEncoder().encode(message).length;
|
|
4645
4798
|
if (size > MAX_MESSAGE_SIZE && // TODO: support public api key auth in REST API
|
|
4646
|
-
_optionalChain([managedSocket, 'access',
|
|
4799
|
+
_optionalChain([managedSocket, 'access', _115 => _115.authValue, 'optionalAccess', _116 => _116.type]) === "secret" && config.httpSendEndpoint) {
|
|
4647
4800
|
void httpSend(
|
|
4648
4801
|
message,
|
|
4649
4802
|
managedSocket.authValue.token.raw,
|
|
4650
4803
|
config.httpSendEndpoint,
|
|
4651
|
-
_optionalChain([config, 'access',
|
|
4804
|
+
_optionalChain([config, 'access', _117 => _117.polyfills, 'optionalAccess', _118 => _118.fetch])
|
|
4652
4805
|
).then((resp) => {
|
|
4653
4806
|
if (!resp.ok && resp.status === 403) {
|
|
4654
4807
|
managedSocket.reconnect();
|
|
@@ -4677,6 +4830,7 @@ function createRoom(options, config) {
|
|
|
4677
4830
|
info: staticSession.userInfo,
|
|
4678
4831
|
presence: myPresence,
|
|
4679
4832
|
canWrite,
|
|
4833
|
+
canComment: canComment(dynamicSession.scopes),
|
|
4680
4834
|
isReadOnly: !canWrite
|
|
4681
4835
|
// Deprecated, kept for backward-compatibility
|
|
4682
4836
|
};
|
|
@@ -4906,7 +5060,7 @@ function createRoom(options, config) {
|
|
|
4906
5060
|
}
|
|
4907
5061
|
context.myPresence.patch(patch);
|
|
4908
5062
|
if (context.activeBatch) {
|
|
4909
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5063
|
+
if (_optionalChain([options2, 'optionalAccess', _119 => _119.addToHistory])) {
|
|
4910
5064
|
context.activeBatch.reverseOps.unshift({
|
|
4911
5065
|
type: "presence",
|
|
4912
5066
|
data: oldValues
|
|
@@ -4916,7 +5070,7 @@ function createRoom(options, config) {
|
|
|
4916
5070
|
} else {
|
|
4917
5071
|
flushNowOrSoon();
|
|
4918
5072
|
batchUpdates(() => {
|
|
4919
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5073
|
+
if (_optionalChain([options2, 'optionalAccess', _120 => _120.addToHistory])) {
|
|
4920
5074
|
addToUndoStack(
|
|
4921
5075
|
[{ type: "presence", data: oldValues }],
|
|
4922
5076
|
doNotBatchUpdates
|
|
@@ -5093,7 +5247,7 @@ function createRoom(options, config) {
|
|
|
5093
5247
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
5094
5248
|
createOrUpdateRootFromMessage(message, doNotBatchUpdates);
|
|
5095
5249
|
applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
|
|
5096
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
5250
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _121 => _121()]);
|
|
5097
5251
|
notifyStorageStatus();
|
|
5098
5252
|
eventHub.storageDidLoad.notify();
|
|
5099
5253
|
break;
|
|
@@ -5116,7 +5270,7 @@ function createRoom(options, config) {
|
|
|
5116
5270
|
if (process.env.NODE_ENV !== "production") {
|
|
5117
5271
|
const traces = /* @__PURE__ */ new Set();
|
|
5118
5272
|
for (const opId of message.opIds) {
|
|
5119
|
-
const trace = _optionalChain([context, 'access',
|
|
5273
|
+
const trace = _optionalChain([context, 'access', _122 => _122.opStackTraces, 'optionalAccess', _123 => _123.get, 'call', _124 => _124(opId)]);
|
|
5120
5274
|
if (trace) {
|
|
5121
5275
|
traces.add(trace);
|
|
5122
5276
|
}
|
|
@@ -5135,6 +5289,14 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5135
5289
|
}
|
|
5136
5290
|
break;
|
|
5137
5291
|
}
|
|
5292
|
+
case 400 /* THREAD_CREATED */:
|
|
5293
|
+
case 401 /* THREAD_METADATA_UPDATED */:
|
|
5294
|
+
case 402 /* COMMENT_CREATED */:
|
|
5295
|
+
case 403 /* COMMENT_EDITED */:
|
|
5296
|
+
case 404 /* COMMENT_DELETED */: {
|
|
5297
|
+
eventHub.comments.notify(message);
|
|
5298
|
+
break;
|
|
5299
|
+
}
|
|
5138
5300
|
}
|
|
5139
5301
|
}
|
|
5140
5302
|
notify(updates, doNotBatchUpdates);
|
|
@@ -5401,14 +5563,18 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5401
5563
|
history: eventHub.history.observable,
|
|
5402
5564
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
5403
5565
|
storageStatus: eventHub.storageStatus.observable,
|
|
5404
|
-
ydoc: eventHub.ydoc.observable
|
|
5566
|
+
ydoc: eventHub.ydoc.observable,
|
|
5567
|
+
comments: eventHub.comments.observable
|
|
5405
5568
|
};
|
|
5569
|
+
const commentsApi = createCommentsApi(config.roomId, delegates.authenticate, {
|
|
5570
|
+
serverEndpoint: "https://api.liveblocks.io/v2"
|
|
5571
|
+
});
|
|
5406
5572
|
return Object.defineProperty(
|
|
5407
5573
|
{
|
|
5408
5574
|
/* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
|
|
5409
5575
|
__internal: {
|
|
5410
5576
|
get presenceBuffer() {
|
|
5411
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
5577
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _125 => _125.buffer, 'access', _126 => _126.presenceUpdates, 'optionalAccess', _127 => _127.data]), () => ( null)));
|
|
5412
5578
|
},
|
|
5413
5579
|
// prettier-ignore
|
|
5414
5580
|
get undoStack() {
|
|
@@ -5460,7 +5626,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5460
5626
|
getSelf: () => self.current,
|
|
5461
5627
|
// Presence
|
|
5462
5628
|
getPresence: () => context.myPresence.current,
|
|
5463
|
-
getOthers: () => context.others.current
|
|
5629
|
+
getOthers: () => context.others.current,
|
|
5630
|
+
...commentsApi
|
|
5464
5631
|
},
|
|
5465
5632
|
// Explictly make the __internal field non-enumerable, to avoid aggressive
|
|
5466
5633
|
// freezing when used with Immer
|
|
@@ -5539,7 +5706,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
5539
5706
|
}
|
|
5540
5707
|
if (isLiveNode(first)) {
|
|
5541
5708
|
const node = first;
|
|
5542
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5709
|
+
if (_optionalChain([options, 'optionalAccess', _128 => _128.isDeep])) {
|
|
5543
5710
|
const storageCallback = second;
|
|
5544
5711
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
5545
5712
|
} else {
|
|
@@ -5640,12 +5807,12 @@ function createClient(options) {
|
|
|
5640
5807
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
5641
5808
|
roomId,
|
|
5642
5809
|
getServerFromClientOptions(clientOptions),
|
|
5643
|
-
_optionalChain([clientOptions, 'access',
|
|
5810
|
+
_optionalChain([clientOptions, 'access', _129 => _129.polyfills, 'optionalAccess', _130 => _130.WebSocket])
|
|
5644
5811
|
),
|
|
5645
5812
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
5646
5813
|
})),
|
|
5647
5814
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
5648
|
-
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess',
|
|
5815
|
+
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _131 => _131.unstable_batchedUpdates]),
|
|
5649
5816
|
liveblocksServer: getServerFromClientOptions(clientOptions),
|
|
5650
5817
|
httpSendEndpoint: buildLiveblocksHttpSendEndpoint(
|
|
5651
5818
|
clientOptions,
|
|
@@ -5660,7 +5827,7 @@ function createClient(options) {
|
|
|
5660
5827
|
const shouldConnect = _nullishCoalesce(options2.shouldInitiallyConnect, () => ( true));
|
|
5661
5828
|
if (shouldConnect) {
|
|
5662
5829
|
if (typeof atob === "undefined") {
|
|
5663
|
-
if (_optionalChain([clientOptions, 'access',
|
|
5830
|
+
if (_optionalChain([clientOptions, 'access', _132 => _132.polyfills, 'optionalAccess', _133 => _133.atob]) === void 0) {
|
|
5664
5831
|
throw new Error(
|
|
5665
5832
|
"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"
|
|
5666
5833
|
);
|
|
@@ -5943,12 +6110,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
5943
6110
|
}
|
|
5944
6111
|
const newState = Object.assign({}, state);
|
|
5945
6112
|
for (const key in update.updates) {
|
|
5946
|
-
if (_optionalChain([update, 'access',
|
|
6113
|
+
if (_optionalChain([update, 'access', _134 => _134.updates, 'access', _135 => _135[key], 'optionalAccess', _136 => _136.type]) === "update") {
|
|
5947
6114
|
const val = update.node.get(key);
|
|
5948
6115
|
if (val !== void 0) {
|
|
5949
6116
|
newState[key] = lsonToJson(val);
|
|
5950
6117
|
}
|
|
5951
|
-
} else if (_optionalChain([update, 'access',
|
|
6118
|
+
} else if (_optionalChain([update, 'access', _137 => _137.updates, 'access', _138 => _138[key], 'optionalAccess', _139 => _139.type]) === "delete") {
|
|
5952
6119
|
delete newState[key];
|
|
5953
6120
|
}
|
|
5954
6121
|
}
|
|
@@ -6009,12 +6176,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
6009
6176
|
}
|
|
6010
6177
|
const newState = Object.assign({}, state);
|
|
6011
6178
|
for (const key in update.updates) {
|
|
6012
|
-
if (_optionalChain([update, 'access',
|
|
6179
|
+
if (_optionalChain([update, 'access', _140 => _140.updates, 'access', _141 => _141[key], 'optionalAccess', _142 => _142.type]) === "update") {
|
|
6013
6180
|
const value = update.node.get(key);
|
|
6014
6181
|
if (value !== void 0) {
|
|
6015
6182
|
newState[key] = lsonToJson(value);
|
|
6016
6183
|
}
|
|
6017
|
-
} else if (_optionalChain([update, 'access',
|
|
6184
|
+
} else if (_optionalChain([update, 'access', _143 => _143.updates, 'access', _144 => _144[key], 'optionalAccess', _145 => _145.type]) === "delete") {
|
|
6018
6185
|
delete newState[key];
|
|
6019
6186
|
}
|
|
6020
6187
|
}
|
|
@@ -6085,6 +6252,222 @@ function shallow(a, b) {
|
|
|
6085
6252
|
return shallowObj(a, b);
|
|
6086
6253
|
}
|
|
6087
6254
|
|
|
6255
|
+
// src/lib/AsyncCache.ts
|
|
6256
|
+
var noop = () => {
|
|
6257
|
+
};
|
|
6258
|
+
function isShallowEqual(a, b) {
|
|
6259
|
+
if (a.isLoading !== b.isLoading || a.data === void 0 !== (b.data === void 0) || a.error === void 0 !== (b.error === void 0)) {
|
|
6260
|
+
return false;
|
|
6261
|
+
} else {
|
|
6262
|
+
return shallow(a.data, b.data) && shallow(a.error, b.error);
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
function createCacheItem(key, defaultAsyncFunction, options) {
|
|
6266
|
+
let asyncFunction = defaultAsyncFunction;
|
|
6267
|
+
const context = {
|
|
6268
|
+
isInvalid: true
|
|
6269
|
+
};
|
|
6270
|
+
let state = { isLoading: false };
|
|
6271
|
+
let previousState = { isLoading: false };
|
|
6272
|
+
const eventSource2 = makeEventSource();
|
|
6273
|
+
function notify() {
|
|
6274
|
+
const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _146 => _146.isStateEqual]), () => ( isShallowEqual));
|
|
6275
|
+
if (!isEqual(previousState, state)) {
|
|
6276
|
+
previousState = state;
|
|
6277
|
+
eventSource2.notify(state);
|
|
6278
|
+
}
|
|
6279
|
+
}
|
|
6280
|
+
async function resolve() {
|
|
6281
|
+
if (!context.promise) {
|
|
6282
|
+
return;
|
|
6283
|
+
}
|
|
6284
|
+
try {
|
|
6285
|
+
const data = await context.promise;
|
|
6286
|
+
context.isInvalid = false;
|
|
6287
|
+
state = {
|
|
6288
|
+
isLoading: false,
|
|
6289
|
+
data
|
|
6290
|
+
};
|
|
6291
|
+
} catch (error3) {
|
|
6292
|
+
state = {
|
|
6293
|
+
isLoading: false,
|
|
6294
|
+
data: state.data,
|
|
6295
|
+
error: error3
|
|
6296
|
+
};
|
|
6297
|
+
}
|
|
6298
|
+
context.promise = void 0;
|
|
6299
|
+
notify();
|
|
6300
|
+
}
|
|
6301
|
+
async function revalidate() {
|
|
6302
|
+
context.isInvalid = true;
|
|
6303
|
+
return get();
|
|
6304
|
+
}
|
|
6305
|
+
async function get() {
|
|
6306
|
+
if (context.isInvalid) {
|
|
6307
|
+
if (!context.promise) {
|
|
6308
|
+
context.isInvalid = true;
|
|
6309
|
+
context.promise = asyncFunction(key);
|
|
6310
|
+
state = { isLoading: true, data: state.data };
|
|
6311
|
+
notify();
|
|
6312
|
+
}
|
|
6313
|
+
await resolve();
|
|
6314
|
+
}
|
|
6315
|
+
return getState();
|
|
6316
|
+
}
|
|
6317
|
+
function getState() {
|
|
6318
|
+
return state;
|
|
6319
|
+
}
|
|
6320
|
+
function setAsyncFunction(overrideAsyncFunction) {
|
|
6321
|
+
asyncFunction = overrideAsyncFunction;
|
|
6322
|
+
}
|
|
6323
|
+
return {
|
|
6324
|
+
...eventSource2.observable,
|
|
6325
|
+
setAsyncFunction,
|
|
6326
|
+
get,
|
|
6327
|
+
getState,
|
|
6328
|
+
revalidate
|
|
6329
|
+
};
|
|
6330
|
+
}
|
|
6331
|
+
function createAsyncCache(asyncFunction, options) {
|
|
6332
|
+
const cache = /* @__PURE__ */ new Map();
|
|
6333
|
+
function create(key, overrideAsyncFunction) {
|
|
6334
|
+
let cacheItem = cache.get(key);
|
|
6335
|
+
if (cacheItem) {
|
|
6336
|
+
if (overrideAsyncFunction) {
|
|
6337
|
+
cacheItem.setAsyncFunction(overrideAsyncFunction);
|
|
6338
|
+
}
|
|
6339
|
+
return cacheItem;
|
|
6340
|
+
}
|
|
6341
|
+
cacheItem = createCacheItem(
|
|
6342
|
+
key,
|
|
6343
|
+
_nullishCoalesce(overrideAsyncFunction, () => ( asyncFunction)),
|
|
6344
|
+
options
|
|
6345
|
+
);
|
|
6346
|
+
cache.set(key, cacheItem);
|
|
6347
|
+
return cacheItem;
|
|
6348
|
+
}
|
|
6349
|
+
function get(key) {
|
|
6350
|
+
return create(key).get();
|
|
6351
|
+
}
|
|
6352
|
+
function getState(key) {
|
|
6353
|
+
return _optionalChain([cache, 'access', _147 => _147.get, 'call', _148 => _148(key), 'optionalAccess', _149 => _149.getState, 'call', _150 => _150()]);
|
|
6354
|
+
}
|
|
6355
|
+
function revalidate(key) {
|
|
6356
|
+
return create(key).revalidate();
|
|
6357
|
+
}
|
|
6358
|
+
function subscribe(key, callback) {
|
|
6359
|
+
return _nullishCoalesce(create(key).subscribe(callback), () => ( noop));
|
|
6360
|
+
}
|
|
6361
|
+
function subscribeOnce(key, callback) {
|
|
6362
|
+
return _nullishCoalesce(create(key).subscribeOnce(callback), () => ( noop));
|
|
6363
|
+
}
|
|
6364
|
+
function has(key) {
|
|
6365
|
+
return cache.has(key);
|
|
6366
|
+
}
|
|
6367
|
+
function clear() {
|
|
6368
|
+
cache.clear();
|
|
6369
|
+
}
|
|
6370
|
+
return {
|
|
6371
|
+
create,
|
|
6372
|
+
get,
|
|
6373
|
+
getState,
|
|
6374
|
+
revalidate,
|
|
6375
|
+
subscribe,
|
|
6376
|
+
subscribeOnce,
|
|
6377
|
+
has,
|
|
6378
|
+
clear
|
|
6379
|
+
};
|
|
6380
|
+
}
|
|
6381
|
+
|
|
6382
|
+
// src/lib/Poller.ts
|
|
6383
|
+
function makePoller(callback) {
|
|
6384
|
+
let context = {
|
|
6385
|
+
state: "stopped",
|
|
6386
|
+
timeoutHandle: null,
|
|
6387
|
+
interval: null,
|
|
6388
|
+
lastScheduledAt: null,
|
|
6389
|
+
remainingInterval: null
|
|
6390
|
+
};
|
|
6391
|
+
function poll() {
|
|
6392
|
+
if (context.state === "running") {
|
|
6393
|
+
schedule(context.interval);
|
|
6394
|
+
}
|
|
6395
|
+
void callback();
|
|
6396
|
+
}
|
|
6397
|
+
function schedule(interval) {
|
|
6398
|
+
context = {
|
|
6399
|
+
state: "running",
|
|
6400
|
+
interval: context.state !== "stopped" ? context.interval : interval,
|
|
6401
|
+
lastScheduledAt: performance.now(),
|
|
6402
|
+
timeoutHandle: setTimeout(poll, interval),
|
|
6403
|
+
remainingInterval: null
|
|
6404
|
+
};
|
|
6405
|
+
}
|
|
6406
|
+
function scheduleRemaining(remaining) {
|
|
6407
|
+
if (context.state !== "paused") {
|
|
6408
|
+
return;
|
|
6409
|
+
}
|
|
6410
|
+
context = {
|
|
6411
|
+
state: "running",
|
|
6412
|
+
interval: context.interval,
|
|
6413
|
+
lastScheduledAt: context.lastScheduledAt,
|
|
6414
|
+
timeoutHandle: setTimeout(poll, remaining),
|
|
6415
|
+
remainingInterval: null
|
|
6416
|
+
};
|
|
6417
|
+
}
|
|
6418
|
+
function start(interval) {
|
|
6419
|
+
if (context.state === "running") {
|
|
6420
|
+
return;
|
|
6421
|
+
}
|
|
6422
|
+
schedule(interval);
|
|
6423
|
+
}
|
|
6424
|
+
function restart(interval) {
|
|
6425
|
+
stop();
|
|
6426
|
+
start(interval);
|
|
6427
|
+
}
|
|
6428
|
+
function pause() {
|
|
6429
|
+
if (context.state !== "running") {
|
|
6430
|
+
return;
|
|
6431
|
+
}
|
|
6432
|
+
clearTimeout(context.timeoutHandle);
|
|
6433
|
+
context = {
|
|
6434
|
+
state: "paused",
|
|
6435
|
+
interval: context.interval,
|
|
6436
|
+
lastScheduledAt: context.lastScheduledAt,
|
|
6437
|
+
timeoutHandle: null,
|
|
6438
|
+
remainingInterval: context.interval - (performance.now() - context.lastScheduledAt)
|
|
6439
|
+
};
|
|
6440
|
+
}
|
|
6441
|
+
function resume() {
|
|
6442
|
+
if (context.state !== "paused") {
|
|
6443
|
+
return;
|
|
6444
|
+
}
|
|
6445
|
+
scheduleRemaining(context.remainingInterval);
|
|
6446
|
+
}
|
|
6447
|
+
function stop() {
|
|
6448
|
+
if (context.state === "stopped") {
|
|
6449
|
+
return;
|
|
6450
|
+
}
|
|
6451
|
+
if (context.timeoutHandle) {
|
|
6452
|
+
clearTimeout(context.timeoutHandle);
|
|
6453
|
+
}
|
|
6454
|
+
context = {
|
|
6455
|
+
state: "stopped",
|
|
6456
|
+
interval: null,
|
|
6457
|
+
lastScheduledAt: null,
|
|
6458
|
+
timeoutHandle: null,
|
|
6459
|
+
remainingInterval: null
|
|
6460
|
+
};
|
|
6461
|
+
}
|
|
6462
|
+
return {
|
|
6463
|
+
start,
|
|
6464
|
+
restart,
|
|
6465
|
+
pause,
|
|
6466
|
+
resume,
|
|
6467
|
+
stop
|
|
6468
|
+
};
|
|
6469
|
+
}
|
|
6470
|
+
|
|
6088
6471
|
// src/index.ts
|
|
6089
6472
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
6090
6473
|
|
|
@@ -6123,5 +6506,9 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
6123
6506
|
|
|
6124
6507
|
|
|
6125
6508
|
|
|
6126
|
-
|
|
6509
|
+
|
|
6510
|
+
|
|
6511
|
+
|
|
6512
|
+
|
|
6513
|
+
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.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;
|
|
6127
6514
|
//# sourceMappingURL=index.js.map
|