@liveblocks/core 2.10.0 → 2.10.1-react19
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 +155 -50
- package/dist/index.d.ts +155 -50
- package/dist/index.js +634 -577
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +573 -516
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "2.10.
|
|
9
|
+
var PKG_VERSION = "2.10.1-react19";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -363,10 +363,39 @@ var FSM = class {
|
|
|
363
363
|
this.enterFns.set(nameOrPattern, enterFn);
|
|
364
364
|
return this;
|
|
365
365
|
}
|
|
366
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Defines a promise-based state. When the state is entered, the promise is
|
|
368
|
+
* created. When the promise resolves, the machine will transition to the
|
|
369
|
+
* provided `onOK` target state. When the promise rejects, the machine will
|
|
370
|
+
* transition to the `onError` target state.
|
|
371
|
+
*
|
|
372
|
+
* Optionally, a `maxTimeout` can be set. If the timeout happens before the
|
|
373
|
+
* promise is settled, then the machine will also transition to the `onError`
|
|
374
|
+
* target state.
|
|
375
|
+
*
|
|
376
|
+
* @param stateOrPattern The state name, or state group pattern name.
|
|
377
|
+
* @param promiseFn The callback to be invoked when the state is entered.
|
|
378
|
+
* @param onOK The state to transition to when the promise resolves.
|
|
379
|
+
* @param onError The state to transition to when the promise
|
|
380
|
+
* rejects, or when the timeout happens before the
|
|
381
|
+
* promise has been settled.
|
|
382
|
+
* @param maxTimeout Optional timeout in milliseconds.
|
|
383
|
+
*
|
|
384
|
+
* When the promise callback function is invoked, it's provided with an
|
|
385
|
+
* AbortSignal (2nd argument).
|
|
386
|
+
* If a state transition happens while the promise is pending (for example,
|
|
387
|
+
* an event, or a timeout happens), then an abort signal will be used to
|
|
388
|
+
* indicate this. Implementers can use this abort signal to terminate the
|
|
389
|
+
* in-flight promise, or ignore its results, etc.
|
|
390
|
+
*/
|
|
391
|
+
onEnterAsync(nameOrPattern, promiseFn, onOK, onError, maxTimeout) {
|
|
367
392
|
return this.onEnter(nameOrPattern, () => {
|
|
368
393
|
const abortController = new AbortController();
|
|
369
394
|
const signal = abortController.signal;
|
|
395
|
+
const timeoutId = maxTimeout ? setTimeout(() => {
|
|
396
|
+
const reason = new Error("Timed out");
|
|
397
|
+
this.transition({ type: "ASYNC_ERROR", reason }, onError);
|
|
398
|
+
}, maxTimeout) : void 0;
|
|
370
399
|
let done = false;
|
|
371
400
|
void promiseFn(this.currentContext.current, signal).then(
|
|
372
401
|
// On OK
|
|
@@ -385,6 +414,7 @@ var FSM = class {
|
|
|
385
414
|
}
|
|
386
415
|
);
|
|
387
416
|
return () => {
|
|
417
|
+
clearTimeout(timeoutId);
|
|
388
418
|
if (!done) {
|
|
389
419
|
abortController.abort();
|
|
390
420
|
}
|
|
@@ -457,11 +487,11 @@ var FSM = class {
|
|
|
457
487
|
* Like `.addTransition()`, but takes an (anonymous) transition whenever the
|
|
458
488
|
* timer fires.
|
|
459
489
|
*
|
|
460
|
-
* @param stateOrPattern
|
|
461
|
-
* @param after
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
* @param target
|
|
490
|
+
* @param stateOrPattern The state name, or state group pattern name.
|
|
491
|
+
* @param after Number of milliseconds after which to take the
|
|
492
|
+
* transition. If in the mean time, another transition
|
|
493
|
+
* is taken, the timer will get cancelled.
|
|
494
|
+
* @param target The target state to go to.
|
|
465
495
|
*/
|
|
466
496
|
addTimedTransition(stateOrPattern, after2, target) {
|
|
467
497
|
return this.onEnter(stateOrPattern, () => {
|
|
@@ -1520,8 +1550,8 @@ function prepareAuthentication(authOptions) {
|
|
|
1520
1550
|
"Invalid Liveblocks client options. Please provide either a `publicApiKey` or `authEndpoint` option. They cannot both be empty. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient"
|
|
1521
1551
|
);
|
|
1522
1552
|
}
|
|
1523
|
-
async function fetchAuthEndpoint(
|
|
1524
|
-
const res = await
|
|
1553
|
+
async function fetchAuthEndpoint(fetch, endpoint, body) {
|
|
1554
|
+
const res = await fetch(endpoint, {
|
|
1525
1555
|
method: "POST",
|
|
1526
1556
|
headers: {
|
|
1527
1557
|
"Content-Type": "application/json"
|
|
@@ -2059,12 +2089,36 @@ function convertToInboxNotificationDeleteInfo(data) {
|
|
|
2059
2089
|
};
|
|
2060
2090
|
}
|
|
2061
2091
|
|
|
2062
|
-
// src/
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2092
|
+
// src/lib/autoRetry.ts
|
|
2093
|
+
var HttpError = class extends Error {
|
|
2094
|
+
constructor(message, status, details) {
|
|
2095
|
+
super(message);
|
|
2096
|
+
this.message = message;
|
|
2097
|
+
this.status = status;
|
|
2098
|
+
this.details = details;
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
var DONT_RETRY_4XX = (x) => x instanceof HttpError && x.status >= 400 && x.status < 500;
|
|
2102
|
+
async function autoRetry(promiseFn, maxTries, backoff, shouldStopRetrying = DONT_RETRY_4XX) {
|
|
2103
|
+
const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
|
|
2104
|
+
let attempt = 0;
|
|
2105
|
+
while (true) {
|
|
2106
|
+
attempt++;
|
|
2107
|
+
try {
|
|
2108
|
+
return await promiseFn();
|
|
2109
|
+
} catch (err) {
|
|
2110
|
+
if (shouldStopRetrying(err)) {
|
|
2111
|
+
throw err;
|
|
2112
|
+
}
|
|
2113
|
+
if (attempt >= maxTries) {
|
|
2114
|
+
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
const delay = backoff[attempt - 1] ?? fallbackBackoff;
|
|
2118
|
+
warn(
|
|
2119
|
+
`Attempt ${attempt} was unsuccessful. Retrying in ${delay} milliseconds.`
|
|
2120
|
+
);
|
|
2121
|
+
await wait(delay);
|
|
2068
2122
|
}
|
|
2069
2123
|
}
|
|
2070
2124
|
|
|
@@ -2091,51 +2145,79 @@ function url(strings, ...values) {
|
|
|
2091
2145
|
);
|
|
2092
2146
|
}
|
|
2093
2147
|
|
|
2094
|
-
// src/
|
|
2095
|
-
function
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2148
|
+
// src/http-client.ts
|
|
2149
|
+
function getBearerTokenFromAuthValue(authValue) {
|
|
2150
|
+
if (authValue.type === "public") {
|
|
2151
|
+
return authValue.publicApiKey;
|
|
2152
|
+
} else {
|
|
2153
|
+
return authValue.token.raw;
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
var HttpClient = class {
|
|
2157
|
+
constructor(baseUrl, fetchPolyfill, authCallback) {
|
|
2158
|
+
this._baseUrl = baseUrl;
|
|
2159
|
+
this._fetchPolyfill = fetchPolyfill;
|
|
2160
|
+
this._authCallback = authCallback;
|
|
2161
|
+
}
|
|
2162
|
+
// ------------------------------------------------------------------
|
|
2163
|
+
// Public methods
|
|
2164
|
+
// ------------------------------------------------------------------
|
|
2165
|
+
/**
|
|
2166
|
+
* Constructs and makes the HTTP request, but does not handle the response.
|
|
2167
|
+
*
|
|
2168
|
+
* This is what .rawFetch() does: 👈 This method!
|
|
2169
|
+
* 1. Set Content-Type header
|
|
2170
|
+
* 2. Set Authorization header
|
|
2171
|
+
* 3. Call the callback to obtain the `authValue` to use in the Authorization header
|
|
2172
|
+
*
|
|
2173
|
+
* This is what .fetch() does ON TOP of that:
|
|
2174
|
+
* 4. Parse response body as Json
|
|
2175
|
+
* 5. ...but silently return `{}` if that parsing fails
|
|
2176
|
+
* 6. Throw HttpError if response is an error
|
|
2177
|
+
*/
|
|
2178
|
+
async rawFetch(endpoint, options, params) {
|
|
2102
2179
|
if (!endpoint.startsWith("/v2/c/")) {
|
|
2103
|
-
raise("
|
|
2180
|
+
raise("This client can only be used to make /v2/c/* requests");
|
|
2104
2181
|
}
|
|
2105
|
-
const
|
|
2106
|
-
|
|
2107
|
-
});
|
|
2108
|
-
if (authValue.type === "secret" && authValue.token.parsed.k === "acc" /* ACCESS_TOKEN */) {
|
|
2109
|
-
const userId = authValue.token.parsed.uid;
|
|
2110
|
-
currentUserIdStore.set(() => userId);
|
|
2111
|
-
}
|
|
2112
|
-
const url2 = urljoin(baseUrl, endpoint, params);
|
|
2113
|
-
const response = await fetcher(url2.toString(), {
|
|
2182
|
+
const url2 = urljoin(this._baseUrl, endpoint, params);
|
|
2183
|
+
return await this._fetchPolyfill(url2, {
|
|
2114
2184
|
...options,
|
|
2115
2185
|
headers: {
|
|
2186
|
+
// These headers are default, but can be overriden by custom headers
|
|
2187
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
2188
|
+
// Possible header overrides
|
|
2116
2189
|
...options?.headers,
|
|
2117
|
-
|
|
2190
|
+
// Cannot be overriden by custom headers
|
|
2191
|
+
Authorization: `Bearer ${getBearerTokenFromAuthValue(await this._authCallback())}`,
|
|
2118
2192
|
"X-LB-Client": PKG_VERSION || "dev"
|
|
2119
2193
|
}
|
|
2120
2194
|
});
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Constructs, makes the HTTP request, and handles the response by parsing
|
|
2198
|
+
* JSON and/or throwing an HttpError if it failed.
|
|
2199
|
+
*
|
|
2200
|
+
* This is what .rawFetch() does:
|
|
2201
|
+
* 1. Set Content-Type header
|
|
2202
|
+
* 2. Set Authorization header
|
|
2203
|
+
* 3. Call the callback to obtain the `authValue` to use in the Authorization header
|
|
2204
|
+
*
|
|
2205
|
+
* This is what .fetch() does ON TOP of that: 👈 This method!
|
|
2206
|
+
* 4. Parse response body as Json
|
|
2207
|
+
* 5. ...but silently return `{}` if that parsing fails (🤔)
|
|
2208
|
+
* 6. Throw HttpError if response is an error
|
|
2209
|
+
*/
|
|
2210
|
+
async fetch(endpoint, options, params) {
|
|
2211
|
+
const response = await this.rawFetch(endpoint, options, params);
|
|
2121
2212
|
if (!response.ok) {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
response.status,
|
|
2129
|
-
errorBody
|
|
2130
|
-
);
|
|
2131
|
-
} catch {
|
|
2132
|
-
error3 = new NotificationsApiError(
|
|
2133
|
-
response.statusText,
|
|
2134
|
-
response.status
|
|
2135
|
-
);
|
|
2136
|
-
}
|
|
2137
|
-
throw error3;
|
|
2213
|
+
let error3;
|
|
2214
|
+
try {
|
|
2215
|
+
const errorBody = await response.json();
|
|
2216
|
+
error3 = new HttpError(errorBody.message, response.status, errorBody);
|
|
2217
|
+
} catch {
|
|
2218
|
+
error3 = new HttpError(response.statusText, response.status);
|
|
2138
2219
|
}
|
|
2220
|
+
throw error3;
|
|
2139
2221
|
}
|
|
2140
2222
|
let body;
|
|
2141
2223
|
try {
|
|
@@ -2145,9 +2227,103 @@ function createNotificationsApi({
|
|
|
2145
2227
|
}
|
|
2146
2228
|
return body;
|
|
2147
2229
|
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Makes a GET request and returns the raw response.
|
|
2232
|
+
* Won't throw if the reponse is a non-2xx.
|
|
2233
|
+
* @deprecated Ideally, use .get() instead.
|
|
2234
|
+
*/
|
|
2235
|
+
async rawGet(endpoint, params, options) {
|
|
2236
|
+
return await this.rawFetch(endpoint, options, params);
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Makes a POST request and returns the raw response.
|
|
2240
|
+
* Won't throw if the reponse is a non-2xx.
|
|
2241
|
+
* @deprecated Ideally, use .post() instead.
|
|
2242
|
+
*/
|
|
2243
|
+
async rawPost(endpoint, body) {
|
|
2244
|
+
return await this.rawFetch(endpoint, {
|
|
2245
|
+
method: "POST",
|
|
2246
|
+
body: JSON.stringify(body)
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Makes a DELETE request and returns the raw response.
|
|
2251
|
+
* Won't throw if the reponse is a non-2xx.
|
|
2252
|
+
* @deprecated Ideally, use .delete() instead.
|
|
2253
|
+
*/
|
|
2254
|
+
async rawDelete(endpoint) {
|
|
2255
|
+
return await this.rawFetch(endpoint, { method: "DELETE" });
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* Makes a GET request, and return the JSON response.
|
|
2259
|
+
* Will throw if the reponse is a non-2xx.
|
|
2260
|
+
*/
|
|
2261
|
+
async get(endpoint, params, options) {
|
|
2262
|
+
return await this.fetch(endpoint, options, params);
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Makes a POST request, and return the JSON response.
|
|
2266
|
+
* Will throw if the reponse is a non-2xx.
|
|
2267
|
+
*/
|
|
2268
|
+
async post(endpoint, body, options, params) {
|
|
2269
|
+
return await this.fetch(
|
|
2270
|
+
endpoint,
|
|
2271
|
+
{
|
|
2272
|
+
...options,
|
|
2273
|
+
method: "POST",
|
|
2274
|
+
body: JSON.stringify(body)
|
|
2275
|
+
},
|
|
2276
|
+
params
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Makes a DELETE request, and return the JSON response.
|
|
2281
|
+
* Will throw if the reponse is a non-2xx.
|
|
2282
|
+
*/
|
|
2283
|
+
async delete(endpoint) {
|
|
2284
|
+
return await this.fetch(endpoint, { method: "DELETE" });
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Makes a PUT request for a Blob body, and return the JSON response.
|
|
2288
|
+
* Will throw if the reponse is a non-2xx.
|
|
2289
|
+
*/
|
|
2290
|
+
async putBlob(endpoint, blob, params, options) {
|
|
2291
|
+
return await this.fetch(
|
|
2292
|
+
endpoint,
|
|
2293
|
+
{
|
|
2294
|
+
...options,
|
|
2295
|
+
method: "PUT",
|
|
2296
|
+
headers: {
|
|
2297
|
+
"Content-Type": "application/octet-stream"
|
|
2298
|
+
},
|
|
2299
|
+
body: blob
|
|
2300
|
+
},
|
|
2301
|
+
params
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
};
|
|
2305
|
+
|
|
2306
|
+
// src/notifications.ts
|
|
2307
|
+
function createNotificationsApi({
|
|
2308
|
+
baseUrl,
|
|
2309
|
+
authManager,
|
|
2310
|
+
currentUserIdStore,
|
|
2311
|
+
fetchPolyfill
|
|
2312
|
+
}) {
|
|
2313
|
+
async function getAuthValue() {
|
|
2314
|
+
const authValue = await authManager.getAuthValue({
|
|
2315
|
+
requestedScope: "comments:read"
|
|
2316
|
+
});
|
|
2317
|
+
if (authValue.type === "secret" && authValue.token.parsed.k === "acc" /* ACCESS_TOKEN */) {
|
|
2318
|
+
const userId = authValue.token.parsed.uid;
|
|
2319
|
+
currentUserIdStore.set(() => userId);
|
|
2320
|
+
}
|
|
2321
|
+
return authValue;
|
|
2322
|
+
}
|
|
2323
|
+
const httpClient = new HttpClient(baseUrl, fetchPolyfill, getAuthValue);
|
|
2148
2324
|
async function getInboxNotifications(options) {
|
|
2149
2325
|
const PAGE_SIZE = 50;
|
|
2150
|
-
const json = await
|
|
2326
|
+
const json = await httpClient.get(url`/v2/c/inbox-notifications`, {
|
|
2151
2327
|
cursor: options?.cursor,
|
|
2152
2328
|
limit: PAGE_SIZE
|
|
2153
2329
|
});
|
|
@@ -2160,10 +2336,12 @@ function createNotificationsApi({
|
|
|
2160
2336
|
requestedAt: new Date(json.meta.requestedAt)
|
|
2161
2337
|
};
|
|
2162
2338
|
}
|
|
2163
|
-
async function getInboxNotificationsSince(
|
|
2164
|
-
const json = await
|
|
2165
|
-
|
|
2166
|
-
|
|
2339
|
+
async function getInboxNotificationsSince(options) {
|
|
2340
|
+
const json = await httpClient.get(
|
|
2341
|
+
url`/v2/c/inbox-notifications/delta`,
|
|
2342
|
+
{ since: options.since.toISOString() },
|
|
2343
|
+
{ signal: options?.signal }
|
|
2344
|
+
);
|
|
2167
2345
|
return {
|
|
2168
2346
|
inboxNotifications: {
|
|
2169
2347
|
updated: json.inboxNotifications.map(convertToInboxNotificationData),
|
|
@@ -2179,25 +2357,19 @@ function createNotificationsApi({
|
|
|
2179
2357
|
};
|
|
2180
2358
|
}
|
|
2181
2359
|
async function getUnreadInboxNotificationsCount() {
|
|
2182
|
-
const { count } = await
|
|
2360
|
+
const { count } = await httpClient.get(
|
|
2361
|
+
url`/v2/c/inbox-notifications/count`
|
|
2362
|
+
);
|
|
2183
2363
|
return count;
|
|
2184
2364
|
}
|
|
2185
2365
|
async function markAllInboxNotificationsAsRead() {
|
|
2186
|
-
await
|
|
2187
|
-
|
|
2188
|
-
headers: {
|
|
2189
|
-
"Content-Type": "application/json"
|
|
2190
|
-
},
|
|
2191
|
-
body: JSON.stringify({ inboxNotificationIds: "all" })
|
|
2366
|
+
await httpClient.post(url`/v2/c/inbox-notifications/read`, {
|
|
2367
|
+
inboxNotificationIds: "all"
|
|
2192
2368
|
});
|
|
2193
2369
|
}
|
|
2194
2370
|
async function markInboxNotificationsAsRead(inboxNotificationIds) {
|
|
2195
|
-
await
|
|
2196
|
-
|
|
2197
|
-
headers: {
|
|
2198
|
-
"Content-Type": "application/json"
|
|
2199
|
-
},
|
|
2200
|
-
body: JSON.stringify({ inboxNotificationIds })
|
|
2371
|
+
await httpClient.post(url`/v2/c/inbox-notifications/read`, {
|
|
2372
|
+
inboxNotificationIds
|
|
2201
2373
|
});
|
|
2202
2374
|
}
|
|
2203
2375
|
const batchedMarkInboxNotificationsAsRead = new Batch(
|
|
@@ -2212,14 +2384,12 @@ function createNotificationsApi({
|
|
|
2212
2384
|
await batchedMarkInboxNotificationsAsRead.get(inboxNotificationId);
|
|
2213
2385
|
}
|
|
2214
2386
|
async function deleteAllInboxNotifications() {
|
|
2215
|
-
await
|
|
2216
|
-
method: "DELETE"
|
|
2217
|
-
});
|
|
2387
|
+
await httpClient.delete(url`/v2/c/inbox-notifications`);
|
|
2218
2388
|
}
|
|
2219
2389
|
async function deleteInboxNotification(inboxNotificationId) {
|
|
2220
|
-
await
|
|
2221
|
-
|
|
2222
|
-
|
|
2390
|
+
await httpClient.delete(
|
|
2391
|
+
url`/v2/c/inbox-notifications/${inboxNotificationId}`
|
|
2392
|
+
);
|
|
2223
2393
|
}
|
|
2224
2394
|
async function getUserThreads_experimental(options) {
|
|
2225
2395
|
let query;
|
|
@@ -2227,7 +2397,7 @@ function createNotificationsApi({
|
|
|
2227
2397
|
query = objectToQuery(options.query);
|
|
2228
2398
|
}
|
|
2229
2399
|
const PAGE_SIZE = 50;
|
|
2230
|
-
const json = await
|
|
2400
|
+
const json = await httpClient.get(url`/v2/c/threads`, {
|
|
2231
2401
|
cursor: options.cursor,
|
|
2232
2402
|
query,
|
|
2233
2403
|
limit: PAGE_SIZE
|
|
@@ -2242,9 +2412,11 @@ function createNotificationsApi({
|
|
|
2242
2412
|
};
|
|
2243
2413
|
}
|
|
2244
2414
|
async function getUserThreadsSince_experimental(options) {
|
|
2245
|
-
const json = await
|
|
2246
|
-
|
|
2247
|
-
|
|
2415
|
+
const json = await httpClient.get(
|
|
2416
|
+
url`/v2/c/threads/delta`,
|
|
2417
|
+
{ since: options.since.toISOString() },
|
|
2418
|
+
{ signal: options.signal }
|
|
2419
|
+
);
|
|
2248
2420
|
return {
|
|
2249
2421
|
threads: {
|
|
2250
2422
|
updated: json.threads.map(convertToThreadData),
|
|
@@ -4829,36 +5001,6 @@ function findNonSerializableValue(value, path = "") {
|
|
|
4829
5001
|
return false;
|
|
4830
5002
|
}
|
|
4831
5003
|
|
|
4832
|
-
// src/lib/autoRetry.ts
|
|
4833
|
-
async function autoRetry(promiseFn, maxTries, backoff, throwError) {
|
|
4834
|
-
const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
|
|
4835
|
-
let attempt = 0;
|
|
4836
|
-
while (true) {
|
|
4837
|
-
attempt++;
|
|
4838
|
-
const promise = promiseFn();
|
|
4839
|
-
try {
|
|
4840
|
-
return await promise;
|
|
4841
|
-
} catch (err) {
|
|
4842
|
-
if (throwError?.(err) || err instanceof StopRetrying2) {
|
|
4843
|
-
throw err;
|
|
4844
|
-
}
|
|
4845
|
-
if (attempt >= maxTries) {
|
|
4846
|
-
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
4847
|
-
}
|
|
4848
|
-
}
|
|
4849
|
-
const delay = backoff[attempt - 1] ?? fallbackBackoff;
|
|
4850
|
-
warn(
|
|
4851
|
-
`Attempt ${attempt} was unsuccessful. Retrying in ${delay} milliseconds.`
|
|
4852
|
-
);
|
|
4853
|
-
await wait(delay);
|
|
4854
|
-
}
|
|
4855
|
-
}
|
|
4856
|
-
var StopRetrying2 = class extends Error {
|
|
4857
|
-
constructor(reason) {
|
|
4858
|
-
super(reason);
|
|
4859
|
-
}
|
|
4860
|
-
};
|
|
4861
|
-
|
|
4862
5004
|
// src/lib/chunk.ts
|
|
4863
5005
|
function chunk(array, size) {
|
|
4864
5006
|
const chunks = [];
|
|
@@ -5316,14 +5458,6 @@ function splitFileIntoParts(file) {
|
|
|
5316
5458
|
}
|
|
5317
5459
|
return parts;
|
|
5318
5460
|
}
|
|
5319
|
-
var CommentsApiError = class extends Error {
|
|
5320
|
-
constructor(message, status, details) {
|
|
5321
|
-
super(message);
|
|
5322
|
-
this.message = message;
|
|
5323
|
-
this.status = status;
|
|
5324
|
-
this.details = details;
|
|
5325
|
-
}
|
|
5326
|
-
};
|
|
5327
5461
|
function createRoom(options, config) {
|
|
5328
5462
|
const initialPresence = options.initialPresence;
|
|
5329
5463
|
const initialStorage = options.initialStorage;
|
|
@@ -5542,114 +5676,73 @@ function createRoom(options, config) {
|
|
|
5542
5676
|
ydoc: makeEventSource(),
|
|
5543
5677
|
comments: makeEventSource()
|
|
5544
5678
|
};
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
}
|
|
5561
|
-
async function streamFetch(authValue, roomId) {
|
|
5562
|
-
return fetchClientApi(url`/v2/c/rooms/${roomId}/storage`, authValue, {
|
|
5563
|
-
method: "GET",
|
|
5564
|
-
headers: {
|
|
5565
|
-
"Content-Type": "application/json"
|
|
5566
|
-
}
|
|
5567
|
-
});
|
|
5568
|
-
}
|
|
5569
|
-
async function httpPostToRoom(endpoint, body) {
|
|
5570
|
-
if (!managedSocket.authValue) {
|
|
5571
|
-
throw new Error("Not authorized");
|
|
5572
|
-
}
|
|
5573
|
-
return fetchClientApi(
|
|
5574
|
-
endpoint === "/send-message" ? url`/v2/c/rooms/${config.roomId}/send-message` : url`/v2/c/rooms/${config.roomId}/text-metadata`,
|
|
5575
|
-
managedSocket.authValue,
|
|
5576
|
-
{
|
|
5577
|
-
method: "POST",
|
|
5578
|
-
headers: {
|
|
5579
|
-
"Content-Type": "application/json"
|
|
5580
|
-
},
|
|
5581
|
-
body: JSON.stringify(body)
|
|
5582
|
-
}
|
|
5583
|
-
);
|
|
5584
|
-
}
|
|
5679
|
+
const fetchPolyfill = config.polyfills?.fetch || /* istanbul ignore next */
|
|
5680
|
+
globalThis.fetch?.bind(globalThis);
|
|
5681
|
+
const httpClient1 = new HttpClient(
|
|
5682
|
+
config.baseUrl,
|
|
5683
|
+
fetchPolyfill,
|
|
5684
|
+
() => Promise.resolve(managedSocket.authValue ?? raise("Not authorized"))
|
|
5685
|
+
);
|
|
5686
|
+
const httpClient2 = new HttpClient(
|
|
5687
|
+
config.baseUrl,
|
|
5688
|
+
fetchPolyfill,
|
|
5689
|
+
() => (
|
|
5690
|
+
// TODO: Use the right scope
|
|
5691
|
+
delegates.authenticate()
|
|
5692
|
+
)
|
|
5693
|
+
);
|
|
5585
5694
|
async function createTextMention(userId, mentionId) {
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
url`/v2/c/rooms/${config.roomId}/text-mentions`,
|
|
5591
|
-
managedSocket.authValue,
|
|
5592
|
-
{
|
|
5593
|
-
method: "POST",
|
|
5594
|
-
headers: {
|
|
5595
|
-
"Content-Type": "application/json"
|
|
5596
|
-
},
|
|
5597
|
-
body: JSON.stringify({
|
|
5598
|
-
userId,
|
|
5599
|
-
mentionId
|
|
5600
|
-
})
|
|
5601
|
-
}
|
|
5602
|
-
);
|
|
5695
|
+
await httpClient1.rawPost(url`/v2/c/rooms/${config.roomId}/text-mentions`, {
|
|
5696
|
+
userId,
|
|
5697
|
+
mentionId
|
|
5698
|
+
});
|
|
5603
5699
|
}
|
|
5604
5700
|
async function deleteTextMention(mentionId) {
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
}
|
|
5608
|
-
return fetchClientApi(
|
|
5609
|
-
url`/v2/c/rooms/${config.roomId}/text-mentions/${mentionId}`,
|
|
5610
|
-
managedSocket.authValue,
|
|
5611
|
-
{
|
|
5612
|
-
method: "DELETE"
|
|
5613
|
-
}
|
|
5701
|
+
await httpClient1.rawDelete(
|
|
5702
|
+
url`/v2/c/rooms/${config.roomId}/text-mentions/${mentionId}`
|
|
5614
5703
|
);
|
|
5615
5704
|
}
|
|
5616
5705
|
async function reportTextEditor(type, rootKey) {
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
{
|
|
5622
|
-
method: "POST",
|
|
5623
|
-
headers: { "Content-Type": "application/json" },
|
|
5624
|
-
body: JSON.stringify({ type, rootKey })
|
|
5625
|
-
}
|
|
5626
|
-
);
|
|
5706
|
+
await httpClient2.rawPost(url`/v2/c/rooms/${config.roomId}/text-metadata`, {
|
|
5707
|
+
type,
|
|
5708
|
+
rootKey
|
|
5709
|
+
});
|
|
5627
5710
|
}
|
|
5628
5711
|
async function listTextVersions() {
|
|
5629
|
-
const
|
|
5630
|
-
return
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5712
|
+
const result = await httpClient2.get(url`/v2/c/rooms/${config.roomId}/versions`);
|
|
5713
|
+
return {
|
|
5714
|
+
versions: result.versions.map(({ createdAt, ...version }) => {
|
|
5715
|
+
return {
|
|
5716
|
+
createdAt: new Date(createdAt),
|
|
5717
|
+
...version
|
|
5718
|
+
};
|
|
5719
|
+
}),
|
|
5720
|
+
requestedAt: new Date(result.meta.requestedAt)
|
|
5721
|
+
};
|
|
5722
|
+
}
|
|
5723
|
+
async function listTextVersionsSince(options2) {
|
|
5724
|
+
const result = await httpClient2.get(
|
|
5725
|
+
url`/v2/c/rooms/${config.roomId}/versions/delta`,
|
|
5726
|
+
{ since: options2.since.toISOString() },
|
|
5727
|
+
{ signal: options2.signal }
|
|
5636
5728
|
);
|
|
5729
|
+
return {
|
|
5730
|
+
versions: result.versions.map(({ createdAt, ...version }) => {
|
|
5731
|
+
return {
|
|
5732
|
+
createdAt: new Date(createdAt),
|
|
5733
|
+
...version
|
|
5734
|
+
};
|
|
5735
|
+
}),
|
|
5736
|
+
requestedAt: new Date(result.meta.requestedAt)
|
|
5737
|
+
};
|
|
5637
5738
|
}
|
|
5638
5739
|
async function getTextVersion(versionId) {
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
url`/v2/c/rooms/${config.roomId}/y-version/${versionId}`,
|
|
5642
|
-
authValue,
|
|
5643
|
-
{ method: "GET" }
|
|
5740
|
+
return httpClient2.rawGet(
|
|
5741
|
+
url`/v2/c/rooms/${config.roomId}/y-version/${versionId}`
|
|
5644
5742
|
);
|
|
5645
5743
|
}
|
|
5646
5744
|
async function createTextVersion() {
|
|
5647
|
-
|
|
5648
|
-
return fetchClientApi(
|
|
5649
|
-
url`/v2/c/rooms/${config.roomId}/version`,
|
|
5650
|
-
authValue,
|
|
5651
|
-
{ method: "POST" }
|
|
5652
|
-
);
|
|
5745
|
+
await httpClient2.rawPost(url`/v2/c/rooms/${config.roomId}/version`);
|
|
5653
5746
|
}
|
|
5654
5747
|
function sendMessages(messages) {
|
|
5655
5748
|
const serializedPayload = JSON.stringify(messages);
|
|
@@ -5657,13 +5750,14 @@ function createRoom(options, config) {
|
|
|
5657
5750
|
if (config.unstable_fallbackToHTTP && nonce) {
|
|
5658
5751
|
const size = new TextEncoder().encode(serializedPayload).length;
|
|
5659
5752
|
if (size > MAX_SOCKET_MESSAGE_SIZE) {
|
|
5660
|
-
void
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5753
|
+
void httpClient1.rawPost(url`/v2/c/rooms/${config.roomId}/send-message`, {
|
|
5754
|
+
nonce,
|
|
5755
|
+
messages
|
|
5756
|
+
}).then((resp) => {
|
|
5757
|
+
if (!resp.ok && resp.status === 403) {
|
|
5758
|
+
managedSocket.reconnect();
|
|
5665
5759
|
}
|
|
5666
|
-
);
|
|
5760
|
+
});
|
|
5667
5761
|
warn(
|
|
5668
5762
|
"Message was too large for websockets and sent over HTTP instead"
|
|
5669
5763
|
);
|
|
@@ -6267,10 +6361,10 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6267
6361
|
eventHub.storageDidLoad.notify();
|
|
6268
6362
|
}
|
|
6269
6363
|
async function streamStorage() {
|
|
6270
|
-
if (!managedSocket.authValue)
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6364
|
+
if (!managedSocket.authValue) return;
|
|
6365
|
+
const result = await httpClient1.rawGet(
|
|
6366
|
+
url`/v2/c/rooms/${config.roomId}/storage`
|
|
6367
|
+
);
|
|
6274
6368
|
const items = await result.json();
|
|
6275
6369
|
processInitialStorage({ type: 200 /* INITIAL_STORAGE_STATE */, items });
|
|
6276
6370
|
}
|
|
@@ -6479,76 +6573,25 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6479
6573
|
ydoc: eventHub.ydoc.observable,
|
|
6480
6574
|
comments: eventHub.comments.observable
|
|
6481
6575
|
};
|
|
6482
|
-
async function fetchCommentsApi(endpoint, params, options2) {
|
|
6483
|
-
const authValue = await delegates.authenticate();
|
|
6484
|
-
return fetchClientApi(endpoint, authValue, options2, params);
|
|
6485
|
-
}
|
|
6486
|
-
async function fetchCommentsJson(endpoint, options2, params) {
|
|
6487
|
-
const response = await fetchCommentsApi(endpoint, params, options2);
|
|
6488
|
-
if (!response.ok) {
|
|
6489
|
-
if (response.status >= 400 && response.status < 600) {
|
|
6490
|
-
let error3;
|
|
6491
|
-
try {
|
|
6492
|
-
const errorBody = await response.json();
|
|
6493
|
-
error3 = new CommentsApiError(
|
|
6494
|
-
errorBody.message,
|
|
6495
|
-
response.status,
|
|
6496
|
-
errorBody
|
|
6497
|
-
);
|
|
6498
|
-
} catch {
|
|
6499
|
-
error3 = new CommentsApiError(response.statusText, response.status);
|
|
6500
|
-
}
|
|
6501
|
-
throw error3;
|
|
6502
|
-
}
|
|
6503
|
-
}
|
|
6504
|
-
let body;
|
|
6505
|
-
try {
|
|
6506
|
-
body = await response.json();
|
|
6507
|
-
} catch {
|
|
6508
|
-
body = {};
|
|
6509
|
-
}
|
|
6510
|
-
return body;
|
|
6511
|
-
}
|
|
6512
6576
|
async function getThreadsSince(options2) {
|
|
6513
|
-
const
|
|
6577
|
+
const result = await httpClient2.get(
|
|
6514
6578
|
url`/v2/c/rooms/${config.roomId}/threads/delta`,
|
|
6515
6579
|
{ since: options2?.since?.toISOString() },
|
|
6516
|
-
{
|
|
6517
|
-
headers: {
|
|
6518
|
-
"Content-Type": "application/json"
|
|
6519
|
-
}
|
|
6520
|
-
}
|
|
6580
|
+
{ signal: options2.signal }
|
|
6521
6581
|
);
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
requestedAt: new Date(json.meta.requestedAt)
|
|
6536
|
-
};
|
|
6537
|
-
} else if (response.status === 404) {
|
|
6538
|
-
return {
|
|
6539
|
-
threads: {
|
|
6540
|
-
updated: [],
|
|
6541
|
-
deleted: []
|
|
6542
|
-
},
|
|
6543
|
-
inboxNotifications: {
|
|
6544
|
-
updated: [],
|
|
6545
|
-
deleted: []
|
|
6546
|
-
},
|
|
6547
|
-
requestedAt: /* @__PURE__ */ new Date()
|
|
6548
|
-
};
|
|
6549
|
-
} else {
|
|
6550
|
-
throw new Error("There was an error while getting threads.");
|
|
6551
|
-
}
|
|
6582
|
+
return {
|
|
6583
|
+
threads: {
|
|
6584
|
+
updated: result.data.map(convertToThreadData),
|
|
6585
|
+
deleted: result.deletedThreads.map(convertToThreadDeleteInfo)
|
|
6586
|
+
},
|
|
6587
|
+
inboxNotifications: {
|
|
6588
|
+
updated: result.inboxNotifications.map(convertToInboxNotificationData),
|
|
6589
|
+
deleted: result.deletedInboxNotifications.map(
|
|
6590
|
+
convertToInboxNotificationDeleteInfo
|
|
6591
|
+
)
|
|
6592
|
+
},
|
|
6593
|
+
requestedAt: new Date(result.meta.requestedAt)
|
|
6594
|
+
};
|
|
6552
6595
|
}
|
|
6553
6596
|
async function getThreads(options2) {
|
|
6554
6597
|
let query;
|
|
@@ -6556,40 +6599,22 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6556
6599
|
query = objectToQuery(options2.query);
|
|
6557
6600
|
}
|
|
6558
6601
|
const PAGE_SIZE = 50;
|
|
6559
|
-
const
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
inboxNotifications: json.inboxNotifications.map(
|
|
6573
|
-
convertToInboxNotificationData
|
|
6574
|
-
),
|
|
6575
|
-
nextCursor: json.meta.nextCursor,
|
|
6576
|
-
requestedAt: new Date(json.meta.requestedAt)
|
|
6577
|
-
};
|
|
6578
|
-
} else if (response.status === 404) {
|
|
6579
|
-
return {
|
|
6580
|
-
threads: [],
|
|
6581
|
-
inboxNotifications: [],
|
|
6582
|
-
deletedThreads: [],
|
|
6583
|
-
deletedInboxNotifications: [],
|
|
6584
|
-
nextCursor: null,
|
|
6585
|
-
requestedAt: /* @__PURE__ */ new Date()
|
|
6586
|
-
};
|
|
6587
|
-
} else {
|
|
6588
|
-
throw new Error("There was an error while getting threads.");
|
|
6589
|
-
}
|
|
6602
|
+
const result = await httpClient2.get(url`/v2/c/rooms/${config.roomId}/threads`, {
|
|
6603
|
+
cursor: options2?.cursor,
|
|
6604
|
+
query,
|
|
6605
|
+
limit: PAGE_SIZE
|
|
6606
|
+
});
|
|
6607
|
+
return {
|
|
6608
|
+
threads: result.data.map(convertToThreadData),
|
|
6609
|
+
inboxNotifications: result.inboxNotifications.map(
|
|
6610
|
+
convertToInboxNotificationData
|
|
6611
|
+
),
|
|
6612
|
+
nextCursor: result.meta.nextCursor,
|
|
6613
|
+
requestedAt: new Date(result.meta.requestedAt)
|
|
6614
|
+
};
|
|
6590
6615
|
}
|
|
6591
6616
|
async function getThread(threadId) {
|
|
6592
|
-
const response = await
|
|
6617
|
+
const response = await httpClient2.rawGet(
|
|
6593
6618
|
url`/v2/c/rooms/${config.roomId}/thread-with-notification/${threadId}`
|
|
6594
6619
|
);
|
|
6595
6620
|
if (response.ok) {
|
|
@@ -6614,57 +6639,42 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6614
6639
|
threadId = createThreadId(),
|
|
6615
6640
|
attachmentIds
|
|
6616
6641
|
}) {
|
|
6617
|
-
const thread = await
|
|
6642
|
+
const thread = await httpClient2.post(
|
|
6618
6643
|
url`/v2/c/rooms/${config.roomId}/threads`,
|
|
6619
6644
|
{
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6645
|
+
id: threadId,
|
|
6646
|
+
comment: {
|
|
6647
|
+
id: commentId,
|
|
6648
|
+
body,
|
|
6649
|
+
attachmentIds
|
|
6623
6650
|
},
|
|
6624
|
-
|
|
6625
|
-
id: threadId,
|
|
6626
|
-
comment: {
|
|
6627
|
-
id: commentId,
|
|
6628
|
-
body,
|
|
6629
|
-
attachmentIds
|
|
6630
|
-
},
|
|
6631
|
-
metadata
|
|
6632
|
-
})
|
|
6651
|
+
metadata
|
|
6633
6652
|
}
|
|
6634
6653
|
);
|
|
6635
6654
|
return convertToThreadData(thread);
|
|
6636
6655
|
}
|
|
6637
6656
|
async function deleteThread(threadId) {
|
|
6638
|
-
await
|
|
6639
|
-
url`/v2/c/rooms/${config.roomId}/threads/${threadId}
|
|
6640
|
-
{ method: "DELETE" }
|
|
6657
|
+
await httpClient2.delete(
|
|
6658
|
+
url`/v2/c/rooms/${config.roomId}/threads/${threadId}`
|
|
6641
6659
|
);
|
|
6642
6660
|
}
|
|
6643
6661
|
async function editThreadMetadata({
|
|
6644
6662
|
metadata,
|
|
6645
6663
|
threadId
|
|
6646
6664
|
}) {
|
|
6647
|
-
return await
|
|
6665
|
+
return await httpClient2.post(
|
|
6648
6666
|
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/metadata`,
|
|
6649
|
-
|
|
6650
|
-
method: "POST",
|
|
6651
|
-
headers: {
|
|
6652
|
-
"Content-Type": "application/json"
|
|
6653
|
-
},
|
|
6654
|
-
body: JSON.stringify(metadata)
|
|
6655
|
-
}
|
|
6667
|
+
metadata
|
|
6656
6668
|
);
|
|
6657
6669
|
}
|
|
6658
6670
|
async function markThreadAsResolved(threadId) {
|
|
6659
|
-
await
|
|
6660
|
-
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/mark-as-resolved
|
|
6661
|
-
{ method: "POST" }
|
|
6671
|
+
await httpClient2.post(
|
|
6672
|
+
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/mark-as-resolved`
|
|
6662
6673
|
);
|
|
6663
6674
|
}
|
|
6664
6675
|
async function markThreadAsUnresolved(threadId) {
|
|
6665
|
-
await
|
|
6666
|
-
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/mark-as-unresolved
|
|
6667
|
-
{ method: "POST" }
|
|
6676
|
+
await httpClient2.post(
|
|
6677
|
+
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/mark-as-unresolved`
|
|
6668
6678
|
);
|
|
6669
6679
|
}
|
|
6670
6680
|
async function createComment({
|
|
@@ -6673,18 +6683,12 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6673
6683
|
body,
|
|
6674
6684
|
attachmentIds
|
|
6675
6685
|
}) {
|
|
6676
|
-
const comment = await
|
|
6686
|
+
const comment = await httpClient2.post(
|
|
6677
6687
|
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments`,
|
|
6678
6688
|
{
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
},
|
|
6683
|
-
body: JSON.stringify({
|
|
6684
|
-
id: commentId,
|
|
6685
|
-
body,
|
|
6686
|
-
attachmentIds
|
|
6687
|
-
})
|
|
6689
|
+
id: commentId,
|
|
6690
|
+
body,
|
|
6691
|
+
attachmentIds
|
|
6688
6692
|
}
|
|
6689
6693
|
);
|
|
6690
6694
|
return convertToCommentData(comment);
|
|
@@ -6695,17 +6699,11 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6695
6699
|
body,
|
|
6696
6700
|
attachmentIds
|
|
6697
6701
|
}) {
|
|
6698
|
-
const comment = await
|
|
6702
|
+
const comment = await httpClient2.post(
|
|
6699
6703
|
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments/${commentId}`,
|
|
6700
6704
|
{
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
"Content-Type": "application/json"
|
|
6704
|
-
},
|
|
6705
|
-
body: JSON.stringify({
|
|
6706
|
-
body,
|
|
6707
|
-
attachmentIds
|
|
6708
|
-
})
|
|
6705
|
+
body,
|
|
6706
|
+
attachmentIds
|
|
6709
6707
|
}
|
|
6710
6708
|
);
|
|
6711
6709
|
return convertToCommentData(comment);
|
|
@@ -6714,9 +6712,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6714
6712
|
threadId,
|
|
6715
6713
|
commentId
|
|
6716
6714
|
}) {
|
|
6717
|
-
await
|
|
6718
|
-
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments/${commentId}
|
|
6719
|
-
{ method: "DELETE" }
|
|
6715
|
+
await httpClient2.delete(
|
|
6716
|
+
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments/${commentId}`
|
|
6720
6717
|
);
|
|
6721
6718
|
}
|
|
6722
6719
|
async function addReaction({
|
|
@@ -6724,15 +6721,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6724
6721
|
commentId,
|
|
6725
6722
|
emoji
|
|
6726
6723
|
}) {
|
|
6727
|
-
const reaction = await
|
|
6724
|
+
const reaction = await httpClient2.post(
|
|
6728
6725
|
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments/${commentId}/reactions`,
|
|
6729
|
-
{
|
|
6730
|
-
method: "POST",
|
|
6731
|
-
headers: {
|
|
6732
|
-
"Content-Type": "application/json"
|
|
6733
|
-
},
|
|
6734
|
-
body: JSON.stringify({ emoji })
|
|
6735
|
-
}
|
|
6726
|
+
{ emoji }
|
|
6736
6727
|
);
|
|
6737
6728
|
return convertToCommentUserReaction(reaction);
|
|
6738
6729
|
}
|
|
@@ -6741,9 +6732,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6741
6732
|
commentId,
|
|
6742
6733
|
emoji
|
|
6743
6734
|
}) {
|
|
6744
|
-
await
|
|
6745
|
-
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments/${commentId}/reactions/${emoji}
|
|
6746
|
-
{ method: "DELETE" }
|
|
6735
|
+
await httpClient2.delete(
|
|
6736
|
+
url`/v2/c/rooms/${config.roomId}/threads/${threadId}/comments/${commentId}/reactions/${emoji}`
|
|
6747
6737
|
);
|
|
6748
6738
|
}
|
|
6749
6739
|
function prepareAttachment(file) {
|
|
@@ -6770,23 +6760,18 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6770
6760
|
if (abortSignal?.aborted) {
|
|
6771
6761
|
throw abortError;
|
|
6772
6762
|
}
|
|
6773
|
-
if (err instanceof
|
|
6763
|
+
if (err instanceof HttpError && err.status === 413) {
|
|
6774
6764
|
throw err;
|
|
6775
6765
|
}
|
|
6776
6766
|
return false;
|
|
6777
6767
|
};
|
|
6778
6768
|
if (attachment.size <= ATTACHMENT_PART_SIZE) {
|
|
6779
6769
|
return autoRetry(
|
|
6780
|
-
() =>
|
|
6770
|
+
() => httpClient2.putBlob(
|
|
6781
6771
|
url`/v2/c/rooms/${config.roomId}/attachments/${attachment.id}/upload/${encodeURIComponent(attachment.name)}`,
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
signal: abortSignal
|
|
6786
|
-
},
|
|
6787
|
-
{
|
|
6788
|
-
fileSize: attachment.size
|
|
6789
|
-
}
|
|
6772
|
+
attachment.file,
|
|
6773
|
+
{ fileSize: attachment.size },
|
|
6774
|
+
{ signal: abortSignal }
|
|
6790
6775
|
),
|
|
6791
6776
|
RETRY_ATTEMPTS,
|
|
6792
6777
|
RETRY_DELAYS,
|
|
@@ -6796,15 +6781,11 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6796
6781
|
let uploadId;
|
|
6797
6782
|
const uploadedParts = [];
|
|
6798
6783
|
const createMultiPartUpload = await autoRetry(
|
|
6799
|
-
() =>
|
|
6784
|
+
() => httpClient2.post(
|
|
6800
6785
|
url`/v2/c/rooms/${config.roomId}/attachments/${attachment.id}/multipart/${encodeURIComponent(attachment.name)}`,
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
},
|
|
6805
|
-
{
|
|
6806
|
-
fileSize: attachment.size
|
|
6807
|
-
}
|
|
6786
|
+
void 0,
|
|
6787
|
+
{ signal: abortSignal },
|
|
6788
|
+
{ fileSize: attachment.size }
|
|
6808
6789
|
),
|
|
6809
6790
|
RETRY_ATTEMPTS,
|
|
6810
6791
|
RETRY_DELAYS,
|
|
@@ -6822,13 +6803,11 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6822
6803
|
for (const { part, partNumber } of parts2) {
|
|
6823
6804
|
uploadedPartsPromises.push(
|
|
6824
6805
|
autoRetry(
|
|
6825
|
-
() =>
|
|
6806
|
+
() => httpClient2.putBlob(
|
|
6826
6807
|
url`/v2/c/rooms/${config.roomId}/attachments/${attachment.id}/multipart/${createMultiPartUpload.uploadId}/${String(partNumber)}`,
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
signal: abortSignal
|
|
6831
|
-
}
|
|
6808
|
+
part,
|
|
6809
|
+
void 0,
|
|
6810
|
+
{ signal: abortSignal }
|
|
6832
6811
|
),
|
|
6833
6812
|
RETRY_ATTEMPTS,
|
|
6834
6813
|
RETRY_DELAYS,
|
|
@@ -6844,26 +6823,16 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6844
6823
|
const sortedUploadedParts = uploadedParts.sort(
|
|
6845
6824
|
(a, b) => a.partNumber - b.partNumber
|
|
6846
6825
|
);
|
|
6847
|
-
return
|
|
6826
|
+
return httpClient2.post(
|
|
6848
6827
|
url`/v2/c/rooms/${config.roomId}/attachments/${attachment.id}/multipart/${uploadId}/complete`,
|
|
6849
|
-
{
|
|
6850
|
-
|
|
6851
|
-
headers: {
|
|
6852
|
-
"Content-Type": "application/json"
|
|
6853
|
-
},
|
|
6854
|
-
body: JSON.stringify({ parts: sortedUploadedParts }),
|
|
6855
|
-
signal: abortSignal
|
|
6856
|
-
}
|
|
6828
|
+
{ parts: sortedUploadedParts },
|
|
6829
|
+
{ signal: abortSignal }
|
|
6857
6830
|
);
|
|
6858
6831
|
} catch (error3) {
|
|
6859
6832
|
if (uploadId && error3?.name && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
|
|
6860
6833
|
try {
|
|
6861
|
-
await
|
|
6862
|
-
url`/v2/c/rooms/${config.roomId}/attachments/${attachment.id}/multipart/${uploadId}
|
|
6863
|
-
void 0,
|
|
6864
|
-
{
|
|
6865
|
-
method: "DELETE"
|
|
6866
|
-
}
|
|
6834
|
+
await httpClient2.rawDelete(
|
|
6835
|
+
url`/v2/c/rooms/${config.roomId}/attachments/${attachment.id}/multipart/${uploadId}`
|
|
6867
6836
|
);
|
|
6868
6837
|
} catch (error4) {
|
|
6869
6838
|
}
|
|
@@ -6873,16 +6842,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6873
6842
|
}
|
|
6874
6843
|
}
|
|
6875
6844
|
async function getAttachmentUrls(attachmentIds) {
|
|
6876
|
-
const { urls } = await
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
method: "POST",
|
|
6880
|
-
headers: {
|
|
6881
|
-
"Content-Type": "application/json"
|
|
6882
|
-
},
|
|
6883
|
-
body: JSON.stringify({ attachmentIds })
|
|
6884
|
-
}
|
|
6885
|
-
);
|
|
6845
|
+
const { urls } = await httpClient2.post(url`/v2/c/rooms/${config.roomId}/attachments/presigned-urls`, {
|
|
6846
|
+
attachmentIds
|
|
6847
|
+
});
|
|
6886
6848
|
return urls;
|
|
6887
6849
|
}
|
|
6888
6850
|
const batchedGetAttachmentUrls = new Batch(
|
|
@@ -6900,38 +6862,12 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6900
6862
|
return batchedGetAttachmentUrls.get(attachmentId);
|
|
6901
6863
|
}
|
|
6902
6864
|
async function fetchNotificationsJson(endpoint, options2) {
|
|
6903
|
-
|
|
6904
|
-
const response = await fetchClientApi(endpoint, authValue, options2);
|
|
6905
|
-
if (!response.ok) {
|
|
6906
|
-
if (response.status >= 400 && response.status < 600) {
|
|
6907
|
-
let error3;
|
|
6908
|
-
try {
|
|
6909
|
-
const errorBody = await response.json();
|
|
6910
|
-
error3 = new NotificationsApiError(
|
|
6911
|
-
errorBody.message,
|
|
6912
|
-
response.status,
|
|
6913
|
-
errorBody
|
|
6914
|
-
);
|
|
6915
|
-
} catch {
|
|
6916
|
-
error3 = new NotificationsApiError(
|
|
6917
|
-
response.statusText,
|
|
6918
|
-
response.status
|
|
6919
|
-
);
|
|
6920
|
-
}
|
|
6921
|
-
throw error3;
|
|
6922
|
-
}
|
|
6923
|
-
}
|
|
6924
|
-
let body;
|
|
6925
|
-
try {
|
|
6926
|
-
body = await response.json();
|
|
6927
|
-
} catch {
|
|
6928
|
-
body = {};
|
|
6929
|
-
}
|
|
6930
|
-
return body;
|
|
6865
|
+
return await httpClient2.get(endpoint, void 0, options2);
|
|
6931
6866
|
}
|
|
6932
|
-
function getNotificationSettings() {
|
|
6867
|
+
function getNotificationSettings(options2) {
|
|
6933
6868
|
return fetchNotificationsJson(
|
|
6934
|
-
url`/v2/c/rooms/${config.roomId}/notification-settings
|
|
6869
|
+
url`/v2/c/rooms/${config.roomId}/notification-settings`,
|
|
6870
|
+
{ signal: options2?.signal }
|
|
6935
6871
|
);
|
|
6936
6872
|
}
|
|
6937
6873
|
function updateNotificationSettings(settings) {
|
|
@@ -6939,10 +6875,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6939
6875
|
url`/v2/c/rooms/${config.roomId}/notification-settings`,
|
|
6940
6876
|
{
|
|
6941
6877
|
method: "POST",
|
|
6942
|
-
body: JSON.stringify(settings)
|
|
6943
|
-
headers: {
|
|
6944
|
-
"Content-Type": "application/json"
|
|
6945
|
-
}
|
|
6878
|
+
body: JSON.stringify(settings)
|
|
6946
6879
|
}
|
|
6947
6880
|
);
|
|
6948
6881
|
}
|
|
@@ -6951,9 +6884,6 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6951
6884
|
url`/v2/c/rooms/${config.roomId}/inbox-notifications/read`,
|
|
6952
6885
|
{
|
|
6953
6886
|
method: "POST",
|
|
6954
|
-
headers: {
|
|
6955
|
-
"Content-Type": "application/json"
|
|
6956
|
-
},
|
|
6957
6887
|
body: JSON.stringify({ inboxNotificationIds })
|
|
6958
6888
|
}
|
|
6959
6889
|
);
|
|
@@ -7000,6 +6930,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7000
6930
|
deleteTextMention,
|
|
7001
6931
|
// list versions of the document
|
|
7002
6932
|
listTextVersions,
|
|
6933
|
+
// List versions of the document since the specified date
|
|
6934
|
+
listTextVersionsSince,
|
|
7003
6935
|
// get a specific version
|
|
7004
6936
|
getTextVersion,
|
|
7005
6937
|
// create a version
|
|
@@ -7322,11 +7254,11 @@ function createClient(options) {
|
|
|
7322
7254
|
}
|
|
7323
7255
|
}
|
|
7324
7256
|
const currentUserIdStore = createStore(null);
|
|
7325
|
-
const
|
|
7326
|
-
fetch;
|
|
7327
|
-
const
|
|
7257
|
+
const fetchPolyfill = clientOptions.polyfills?.fetch || /* istanbul ignore next */
|
|
7258
|
+
globalThis.fetch?.bind(globalThis);
|
|
7259
|
+
const notificationsAPI = createNotificationsApi({
|
|
7328
7260
|
baseUrl,
|
|
7329
|
-
|
|
7261
|
+
fetchPolyfill,
|
|
7330
7262
|
authManager,
|
|
7331
7263
|
currentUserIdStore
|
|
7332
7264
|
});
|
|
@@ -7370,12 +7302,12 @@ function createClient(options) {
|
|
|
7370
7302
|
function invalidateResolvedMentionSuggestions() {
|
|
7371
7303
|
mentionSuggestionsCache.clear();
|
|
7372
7304
|
}
|
|
7373
|
-
|
|
7305
|
+
const client = Object.defineProperty(
|
|
7374
7306
|
{
|
|
7375
7307
|
enterRoom,
|
|
7376
7308
|
getRoom,
|
|
7377
7309
|
logout,
|
|
7378
|
-
...
|
|
7310
|
+
...notificationsAPI,
|
|
7379
7311
|
// Advanced resolvers APIs
|
|
7380
7312
|
resolvers: {
|
|
7381
7313
|
invalidateUsers: invalidateResolvedUsers,
|
|
@@ -7393,8 +7325,10 @@ function createClient(options) {
|
|
|
7393
7325
|
return Array.from(roomsById.keys());
|
|
7394
7326
|
},
|
|
7395
7327
|
// "All" threads (= "user" threads)
|
|
7396
|
-
getUserThreads_experimental:
|
|
7397
|
-
getUserThreadsSince_experimental:
|
|
7328
|
+
getUserThreads_experimental: notificationsAPI.getUserThreads_experimental,
|
|
7329
|
+
getUserThreadsSince_experimental: notificationsAPI.getUserThreadsSince_experimental,
|
|
7330
|
+
// Type-level helper only, it's effectively only an identity-function at runtime
|
|
7331
|
+
as: () => client
|
|
7398
7332
|
}
|
|
7399
7333
|
},
|
|
7400
7334
|
kInternal,
|
|
@@ -7402,15 +7336,8 @@ function createClient(options) {
|
|
|
7402
7336
|
enumerable: false
|
|
7403
7337
|
}
|
|
7404
7338
|
);
|
|
7339
|
+
return client;
|
|
7405
7340
|
}
|
|
7406
|
-
var NotificationsApiError = class extends Error {
|
|
7407
|
-
constructor(message, status, details) {
|
|
7408
|
-
super(message);
|
|
7409
|
-
this.message = message;
|
|
7410
|
-
this.status = status;
|
|
7411
|
-
this.details = details;
|
|
7412
|
-
}
|
|
7413
|
-
};
|
|
7414
7341
|
function checkBounds(option, value, min, max, recommendedMin) {
|
|
7415
7342
|
if (typeof value !== "number" || value < min || max !== void 0 && value > max) {
|
|
7416
7343
|
throw new Error(
|
|
@@ -8128,45 +8055,102 @@ function errorIf(condition, message) {
|
|
|
8128
8055
|
}
|
|
8129
8056
|
|
|
8130
8057
|
// src/lib/Poller.ts
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
}
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8058
|
+
var BACKOFF_DELAYS2 = [1e3, 2e3, 4e3, 8e3, 1e4];
|
|
8059
|
+
function makePoller(callback, intervalMs, options) {
|
|
8060
|
+
const startTime = performance.now();
|
|
8061
|
+
const doc = typeof document !== "undefined" ? document : void 0;
|
|
8062
|
+
const win = typeof window !== "undefined" ? window : void 0;
|
|
8063
|
+
const maxStaleTimeMs = options?.maxStaleTimeMs ?? Number.POSITIVE_INFINITY;
|
|
8064
|
+
const context = {
|
|
8065
|
+
inForeground: doc?.visibilityState !== "hidden",
|
|
8066
|
+
lastSuccessfulPollAt: startTime,
|
|
8067
|
+
count: 0,
|
|
8068
|
+
backoff: 0
|
|
8069
|
+
};
|
|
8070
|
+
function mayPoll() {
|
|
8071
|
+
return context.count > 0 && context.inForeground;
|
|
8072
|
+
}
|
|
8073
|
+
const fsm = new FSM({}).addState("@idle").addState("@enabled").addState("@polling");
|
|
8074
|
+
fsm.addTransitions("@idle", { START: "@enabled" });
|
|
8075
|
+
fsm.addTransitions("@enabled", { STOP: "@idle", POLL: "@polling" });
|
|
8076
|
+
fsm.addTimedTransition(
|
|
8077
|
+
"@enabled",
|
|
8078
|
+
() => {
|
|
8079
|
+
const lastPoll = context.lastSuccessfulPollAt;
|
|
8080
|
+
const nextPoll = lastPoll + intervalMs;
|
|
8081
|
+
return Math.max(0, nextPoll - performance.now()) + context.backoff;
|
|
8082
|
+
},
|
|
8083
|
+
"@polling"
|
|
8084
|
+
);
|
|
8085
|
+
fsm.onEnterAsync(
|
|
8086
|
+
"@polling",
|
|
8087
|
+
async (_ctx, signal) => {
|
|
8088
|
+
await callback(signal);
|
|
8089
|
+
if (!signal.aborted) {
|
|
8090
|
+
context.lastSuccessfulPollAt = performance.now();
|
|
8091
|
+
}
|
|
8092
|
+
},
|
|
8093
|
+
// When OK
|
|
8094
|
+
() => {
|
|
8095
|
+
return {
|
|
8096
|
+
target: mayPoll() ? "@enabled" : "@idle",
|
|
8097
|
+
effect: () => {
|
|
8098
|
+
context.backoff = 0;
|
|
8099
|
+
}
|
|
8100
|
+
};
|
|
8101
|
+
},
|
|
8102
|
+
// When error
|
|
8103
|
+
() => {
|
|
8104
|
+
return {
|
|
8105
|
+
target: mayPoll() ? "@enabled" : "@idle",
|
|
8106
|
+
effect: () => {
|
|
8107
|
+
context.backoff = BACKOFF_DELAYS2.find((delay) => delay > context.backoff) ?? BACKOFF_DELAYS2[BACKOFF_DELAYS2.length - 1];
|
|
8108
|
+
}
|
|
8109
|
+
};
|
|
8110
|
+
},
|
|
8111
|
+
3e4
|
|
8112
|
+
// Abort the poll if the callback takes more than 30 seconds to complete
|
|
8113
|
+
);
|
|
8114
|
+
function startOrStop() {
|
|
8115
|
+
if (mayPoll()) {
|
|
8116
|
+
fsm.send({ type: "START" });
|
|
8117
|
+
} else {
|
|
8118
|
+
fsm.send({ type: "STOP" });
|
|
8149
8119
|
}
|
|
8150
|
-
schedule();
|
|
8151
8120
|
}
|
|
8152
|
-
function
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8121
|
+
function inc() {
|
|
8122
|
+
context.count++;
|
|
8123
|
+
startOrStop();
|
|
8124
|
+
}
|
|
8125
|
+
function dec() {
|
|
8126
|
+
context.count--;
|
|
8127
|
+
if (context.count < 0) {
|
|
8128
|
+
context.count = 0;
|
|
8158
8129
|
}
|
|
8159
|
-
|
|
8130
|
+
startOrStop();
|
|
8160
8131
|
}
|
|
8161
|
-
function
|
|
8162
|
-
if (
|
|
8163
|
-
|
|
8164
|
-
} else {
|
|
8165
|
-
stop();
|
|
8132
|
+
function pollNowIfStale() {
|
|
8133
|
+
if (performance.now() - context.lastSuccessfulPollAt > maxStaleTimeMs) {
|
|
8134
|
+
fsm.send({ type: "POLL" });
|
|
8166
8135
|
}
|
|
8167
8136
|
}
|
|
8137
|
+
function setInForeground(inForeground) {
|
|
8138
|
+
context.inForeground = inForeground;
|
|
8139
|
+
startOrStop();
|
|
8140
|
+
pollNowIfStale();
|
|
8141
|
+
}
|
|
8142
|
+
function onVisibilityChange() {
|
|
8143
|
+
setInForeground(doc?.visibilityState !== "hidden");
|
|
8144
|
+
}
|
|
8145
|
+
doc?.addEventListener("visibilitychange", onVisibilityChange);
|
|
8146
|
+
win?.addEventListener("online", onVisibilityChange);
|
|
8147
|
+
fsm.start();
|
|
8168
8148
|
return {
|
|
8169
|
-
|
|
8149
|
+
inc,
|
|
8150
|
+
dec,
|
|
8151
|
+
pollNowIfStale,
|
|
8152
|
+
// Internal API, used by unit tests only to simulate visibility events
|
|
8153
|
+
setInForeground
|
|
8170
8154
|
};
|
|
8171
8155
|
}
|
|
8172
8156
|
|
|
@@ -8209,19 +8193,92 @@ function shallow(a, b) {
|
|
|
8209
8193
|
return shallowObj(a, b);
|
|
8210
8194
|
}
|
|
8211
8195
|
|
|
8196
|
+
// src/lib/SortedList.ts
|
|
8197
|
+
function bisectRight(arr, x, lt) {
|
|
8198
|
+
let lo = 0;
|
|
8199
|
+
let hi = arr.length;
|
|
8200
|
+
while (lo < hi) {
|
|
8201
|
+
const mid = lo + (hi - lo >> 1);
|
|
8202
|
+
if (lt(x, arr[mid])) {
|
|
8203
|
+
hi = mid;
|
|
8204
|
+
} else {
|
|
8205
|
+
lo = mid + 1;
|
|
8206
|
+
}
|
|
8207
|
+
}
|
|
8208
|
+
return lo;
|
|
8209
|
+
}
|
|
8210
|
+
var SortedList = class _SortedList {
|
|
8211
|
+
constructor(alreadySortedList, lt) {
|
|
8212
|
+
this._lt = lt;
|
|
8213
|
+
this._data = alreadySortedList;
|
|
8214
|
+
}
|
|
8215
|
+
static from(arr, lt) {
|
|
8216
|
+
const sorted = new _SortedList([], lt);
|
|
8217
|
+
for (const item of arr) {
|
|
8218
|
+
sorted.add(item);
|
|
8219
|
+
}
|
|
8220
|
+
return sorted;
|
|
8221
|
+
}
|
|
8222
|
+
static fromAlreadySorted(alreadySorted, lt) {
|
|
8223
|
+
return new _SortedList(alreadySorted, lt);
|
|
8224
|
+
}
|
|
8225
|
+
/**
|
|
8226
|
+
* Clones the sorted list to a new instance.
|
|
8227
|
+
*/
|
|
8228
|
+
clone() {
|
|
8229
|
+
return new _SortedList(this._data.slice(), this._lt);
|
|
8230
|
+
}
|
|
8231
|
+
/**
|
|
8232
|
+
* Adds a new item to the sorted list, such that it remains sorted.
|
|
8233
|
+
*/
|
|
8234
|
+
add(value) {
|
|
8235
|
+
const idx = bisectRight(this._data, value, this._lt);
|
|
8236
|
+
this._data.splice(idx, 0, value);
|
|
8237
|
+
}
|
|
8238
|
+
/**
|
|
8239
|
+
* Removes the given value from the sorted list, if it exists. The given
|
|
8240
|
+
* value must be `===` to one of the list items. Only the first entry will be
|
|
8241
|
+
* removed if the element exists in the sorted list multiple times.
|
|
8242
|
+
*/
|
|
8243
|
+
remove(value) {
|
|
8244
|
+
const idx = this._data.indexOf(value);
|
|
8245
|
+
if (idx >= 0) {
|
|
8246
|
+
this._data.splice(idx, 1);
|
|
8247
|
+
return true;
|
|
8248
|
+
}
|
|
8249
|
+
return false;
|
|
8250
|
+
}
|
|
8251
|
+
get length() {
|
|
8252
|
+
return this._data.length;
|
|
8253
|
+
}
|
|
8254
|
+
*filter(predicate) {
|
|
8255
|
+
for (const item of this._data) {
|
|
8256
|
+
if (predicate(item)) {
|
|
8257
|
+
yield item;
|
|
8258
|
+
}
|
|
8259
|
+
}
|
|
8260
|
+
}
|
|
8261
|
+
[Symbol.iterator]() {
|
|
8262
|
+
return this._data[Symbol.iterator]();
|
|
8263
|
+
}
|
|
8264
|
+
};
|
|
8265
|
+
|
|
8212
8266
|
// src/index.ts
|
|
8213
8267
|
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
8268
|
+
var CommentsApiError = HttpError;
|
|
8269
|
+
var NotificationsApiError = HttpError;
|
|
8214
8270
|
export {
|
|
8215
8271
|
ClientMsgCode,
|
|
8216
8272
|
CommentsApiError,
|
|
8217
8273
|
CrdtType,
|
|
8274
|
+
HttpError,
|
|
8218
8275
|
LiveList,
|
|
8219
8276
|
LiveMap,
|
|
8220
8277
|
LiveObject,
|
|
8221
8278
|
NotificationsApiError,
|
|
8222
8279
|
OpCode,
|
|
8223
8280
|
ServerMsgCode,
|
|
8224
|
-
|
|
8281
|
+
SortedList,
|
|
8225
8282
|
WebsocketCloseCodes,
|
|
8226
8283
|
ackOp,
|
|
8227
8284
|
asPos,
|