@liveblocks/core 3.2.0 → 3.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.cjs +699 -643
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -7
- package/dist/index.d.ts +38 -7
- package/dist/index.js +616 -560
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
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 = "3.
|
|
9
|
+
var PKG_VERSION = "3.3.0";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -52,151 +52,101 @@ function detectDupes(pkgName, pkgVersion, pkgFormat) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// src/
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
createdAt: new Date(reaction.createdAt)
|
|
62
|
-
}));
|
|
63
|
-
if (data.body) {
|
|
64
|
-
return {
|
|
65
|
-
...data,
|
|
66
|
-
reactions,
|
|
67
|
-
createdAt,
|
|
68
|
-
editedAt
|
|
69
|
-
};
|
|
70
|
-
} else {
|
|
71
|
-
const deletedAt = new Date(data.deletedAt);
|
|
72
|
-
return {
|
|
73
|
-
...data,
|
|
74
|
-
reactions,
|
|
75
|
-
createdAt,
|
|
76
|
-
editedAt,
|
|
77
|
-
deletedAt
|
|
78
|
-
};
|
|
55
|
+
// src/lib/EventSource.ts
|
|
56
|
+
function makeEventSource() {
|
|
57
|
+
const _observers = /* @__PURE__ */ new Set();
|
|
58
|
+
function subscribe(callback) {
|
|
59
|
+
_observers.add(callback);
|
|
60
|
+
return () => _observers.delete(callback);
|
|
79
61
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}));
|
|
108
|
-
return {
|
|
109
|
-
...data,
|
|
110
|
-
notifiedAt,
|
|
111
|
-
readAt,
|
|
112
|
-
activities
|
|
113
|
-
};
|
|
62
|
+
function subscribeOnce(callback) {
|
|
63
|
+
const unsub = subscribe((event) => {
|
|
64
|
+
unsub();
|
|
65
|
+
return callback(event);
|
|
66
|
+
});
|
|
67
|
+
return unsub;
|
|
68
|
+
}
|
|
69
|
+
async function waitUntil(predicate) {
|
|
70
|
+
let unsub;
|
|
71
|
+
return new Promise((res) => {
|
|
72
|
+
unsub = subscribe((event) => {
|
|
73
|
+
if (predicate === void 0 || predicate(event)) {
|
|
74
|
+
res(event);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}).finally(() => _optionalChain([unsub, 'optionalCall', _2 => _2()]));
|
|
78
|
+
}
|
|
79
|
+
function notify(event) {
|
|
80
|
+
let called = false;
|
|
81
|
+
for (const callback of _observers) {
|
|
82
|
+
callback(event);
|
|
83
|
+
called = true;
|
|
84
|
+
}
|
|
85
|
+
return called;
|
|
86
|
+
}
|
|
87
|
+
function count() {
|
|
88
|
+
return _observers.size;
|
|
114
89
|
}
|
|
115
90
|
return {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
...data,
|
|
132
|
-
createdAt
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function convertToThreadDeleteInfo(data) {
|
|
136
|
-
const deletedAt = new Date(data.deletedAt);
|
|
137
|
-
return {
|
|
138
|
-
...data,
|
|
139
|
-
deletedAt
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function convertToInboxNotificationDeleteInfo(data) {
|
|
143
|
-
const deletedAt = new Date(data.deletedAt);
|
|
144
|
-
return {
|
|
145
|
-
...data,
|
|
146
|
-
deletedAt
|
|
91
|
+
// Private/internal control over event emission
|
|
92
|
+
notify,
|
|
93
|
+
subscribe,
|
|
94
|
+
subscribeOnce,
|
|
95
|
+
count,
|
|
96
|
+
waitUntil,
|
|
97
|
+
dispose() {
|
|
98
|
+
_observers.clear();
|
|
99
|
+
},
|
|
100
|
+
// Publicly exposable subscription API
|
|
101
|
+
observable: {
|
|
102
|
+
subscribe,
|
|
103
|
+
subscribeOnce,
|
|
104
|
+
waitUntil
|
|
105
|
+
}
|
|
147
106
|
};
|
|
148
107
|
}
|
|
149
|
-
function
|
|
150
|
-
const
|
|
108
|
+
function makeBufferableEventSource() {
|
|
109
|
+
const eventSource2 = makeEventSource();
|
|
110
|
+
let _buffer = null;
|
|
111
|
+
function pause() {
|
|
112
|
+
_buffer = [];
|
|
113
|
+
}
|
|
114
|
+
function unpause() {
|
|
115
|
+
if (_buffer === null) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
for (const event of _buffer) {
|
|
119
|
+
eventSource2.notify(event);
|
|
120
|
+
}
|
|
121
|
+
_buffer = null;
|
|
122
|
+
}
|
|
123
|
+
function notifyOrBuffer(event) {
|
|
124
|
+
if (_buffer !== null) {
|
|
125
|
+
_buffer.push(event);
|
|
126
|
+
return false;
|
|
127
|
+
} else {
|
|
128
|
+
return eventSource2.notify(event);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
151
131
|
return {
|
|
152
|
-
...
|
|
153
|
-
|
|
132
|
+
...eventSource2,
|
|
133
|
+
notify: notifyOrBuffer,
|
|
134
|
+
pause,
|
|
135
|
+
unpause,
|
|
136
|
+
dispose() {
|
|
137
|
+
eventSource2.dispose();
|
|
138
|
+
if (_buffer !== null) {
|
|
139
|
+
_buffer.length = 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
154
142
|
};
|
|
155
143
|
}
|
|
156
144
|
|
|
157
|
-
// src/lib/
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
warn: () => warn,
|
|
163
|
-
warnWithTitle: () => warnWithTitle
|
|
164
|
-
});
|
|
165
|
-
var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
|
|
166
|
-
var bold = "font-weight:600";
|
|
167
|
-
function wrap(method) {
|
|
168
|
-
return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
|
|
169
|
-
/* istanbul ignore next */
|
|
170
|
-
(message, ...args) => console[method]("%cLiveblocks", badge, message, ...args)
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
var warn = wrap("warn");
|
|
174
|
-
var error2 = wrap("error");
|
|
175
|
-
function wrapWithTitle(method) {
|
|
176
|
-
return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
|
|
177
|
-
/* istanbul ignore next */
|
|
178
|
-
(title, message, ...args) => console[method](
|
|
179
|
-
`%cLiveblocks%c ${title}`,
|
|
180
|
-
badge,
|
|
181
|
-
bold,
|
|
182
|
-
message,
|
|
183
|
-
...args
|
|
184
|
-
)
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
var warnWithTitle = wrapWithTitle("warn");
|
|
188
|
-
var errorWithTitle = wrapWithTitle("error");
|
|
189
|
-
|
|
190
|
-
// src/lib/guards.ts
|
|
191
|
-
function isDefined(value) {
|
|
192
|
-
return value !== null && value !== void 0;
|
|
193
|
-
}
|
|
194
|
-
function isPlainObject(blob) {
|
|
195
|
-
return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
|
|
196
|
-
}
|
|
197
|
-
function isStartsWithOperator(blob) {
|
|
198
|
-
return isPlainObject(blob) && typeof blob.startsWith === "string";
|
|
199
|
-
}
|
|
145
|
+
// src/lib/freeze.ts
|
|
146
|
+
var freeze = process.env.NODE_ENV === "production" ? (
|
|
147
|
+
/* istanbul ignore next */
|
|
148
|
+
(x) => x
|
|
149
|
+
) : Object.freeze;
|
|
200
150
|
|
|
201
151
|
// src/lib/utils.ts
|
|
202
152
|
function raise(msg) {
|
|
@@ -294,201 +244,22 @@ function memoizeOnSuccess(factoryFn) {
|
|
|
294
244
|
};
|
|
295
245
|
}
|
|
296
246
|
|
|
297
|
-
// src/lib/
|
|
298
|
-
var
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
247
|
+
// src/lib/signals.ts
|
|
248
|
+
var kSinks = Symbol("kSinks");
|
|
249
|
+
var kTrigger = Symbol("kTrigger");
|
|
250
|
+
var signalsToTrigger = null;
|
|
251
|
+
var trackedReads = null;
|
|
252
|
+
function batch(callback) {
|
|
253
|
+
if (signalsToTrigger !== null) {
|
|
254
|
+
callback();
|
|
255
|
+
return;
|
|
306
256
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const bodyAsJson = bodyAsText ? tryParseJson(bodyAsText) : void 0;
|
|
314
|
-
let bodyAsJsonObject;
|
|
315
|
-
if (isPlainObject(bodyAsJson)) {
|
|
316
|
-
bodyAsJsonObject = bodyAsJson;
|
|
317
|
-
}
|
|
318
|
-
let message = "";
|
|
319
|
-
message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _2 => _2.message]) === "string" ? bodyAsJsonObject.message : "";
|
|
320
|
-
message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _3 => _3.error]) === "string" ? bodyAsJsonObject.error : "";
|
|
321
|
-
if (bodyAsJson === void 0) {
|
|
322
|
-
message ||= bodyAsText || "";
|
|
323
|
-
}
|
|
324
|
-
message ||= response.statusText;
|
|
325
|
-
let path;
|
|
326
|
-
try {
|
|
327
|
-
path = new URL(response.url).pathname;
|
|
328
|
-
} catch (e3) {
|
|
329
|
-
}
|
|
330
|
-
message += path !== void 0 ? ` (got status ${response.status} from ${path})` : ` (got status ${response.status})`;
|
|
331
|
-
const details = bodyAsJsonObject;
|
|
332
|
-
return new _HttpError(message, response, details);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Convenience accessor for response.status.
|
|
336
|
-
*/
|
|
337
|
-
get status() {
|
|
338
|
-
return this.response.status;
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
var DONT_RETRY_4XX = (x) => x instanceof HttpError && x.status >= 400 && x.status < 500;
|
|
342
|
-
async function autoRetry(promiseFn, maxTries, backoff, shouldStopRetrying = DONT_RETRY_4XX) {
|
|
343
|
-
const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
|
|
344
|
-
let attempt = 0;
|
|
345
|
-
while (true) {
|
|
346
|
-
attempt++;
|
|
347
|
-
try {
|
|
348
|
-
return await promiseFn();
|
|
349
|
-
} catch (err) {
|
|
350
|
-
if (shouldStopRetrying(err)) {
|
|
351
|
-
throw err;
|
|
352
|
-
}
|
|
353
|
-
if (attempt >= maxTries) {
|
|
354
|
-
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
const delay = _nullishCoalesce(backoff[attempt - 1], () => ( fallbackBackoff));
|
|
358
|
-
warn(
|
|
359
|
-
`Attempt ${attempt} was unsuccessful. Retrying in ${delay} milliseconds.`
|
|
360
|
-
);
|
|
361
|
-
await wait(delay);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/lib/controlledPromise.ts
|
|
366
|
-
function controlledPromise() {
|
|
367
|
-
let resolve;
|
|
368
|
-
let reject;
|
|
369
|
-
const promise = new Promise((res, rej) => {
|
|
370
|
-
resolve = res;
|
|
371
|
-
reject = rej;
|
|
372
|
-
});
|
|
373
|
-
return [promise, resolve, reject];
|
|
374
|
-
}
|
|
375
|
-
function Promise_withResolvers() {
|
|
376
|
-
const [promise, resolve, reject] = controlledPromise();
|
|
377
|
-
return { promise, resolve, reject };
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// src/lib/EventSource.ts
|
|
381
|
-
function makeEventSource() {
|
|
382
|
-
const _observers = /* @__PURE__ */ new Set();
|
|
383
|
-
function subscribe(callback) {
|
|
384
|
-
_observers.add(callback);
|
|
385
|
-
return () => _observers.delete(callback);
|
|
386
|
-
}
|
|
387
|
-
function subscribeOnce(callback) {
|
|
388
|
-
const unsub = subscribe((event) => {
|
|
389
|
-
unsub();
|
|
390
|
-
return callback(event);
|
|
391
|
-
});
|
|
392
|
-
return unsub;
|
|
393
|
-
}
|
|
394
|
-
async function waitUntil(predicate) {
|
|
395
|
-
let unsub;
|
|
396
|
-
return new Promise((res) => {
|
|
397
|
-
unsub = subscribe((event) => {
|
|
398
|
-
if (predicate === void 0 || predicate(event)) {
|
|
399
|
-
res(event);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
}).finally(() => _optionalChain([unsub, 'optionalCall', _4 => _4()]));
|
|
403
|
-
}
|
|
404
|
-
function notify(event) {
|
|
405
|
-
let called = false;
|
|
406
|
-
for (const callback of _observers) {
|
|
407
|
-
callback(event);
|
|
408
|
-
called = true;
|
|
409
|
-
}
|
|
410
|
-
return called;
|
|
411
|
-
}
|
|
412
|
-
function count() {
|
|
413
|
-
return _observers.size;
|
|
414
|
-
}
|
|
415
|
-
return {
|
|
416
|
-
// Private/internal control over event emission
|
|
417
|
-
notify,
|
|
418
|
-
subscribe,
|
|
419
|
-
subscribeOnce,
|
|
420
|
-
count,
|
|
421
|
-
waitUntil,
|
|
422
|
-
dispose() {
|
|
423
|
-
_observers.clear();
|
|
424
|
-
},
|
|
425
|
-
// Publicly exposable subscription API
|
|
426
|
-
observable: {
|
|
427
|
-
subscribe,
|
|
428
|
-
subscribeOnce,
|
|
429
|
-
waitUntil
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
function makeBufferableEventSource() {
|
|
434
|
-
const eventSource2 = makeEventSource();
|
|
435
|
-
let _buffer = null;
|
|
436
|
-
function pause() {
|
|
437
|
-
_buffer = [];
|
|
438
|
-
}
|
|
439
|
-
function unpause() {
|
|
440
|
-
if (_buffer === null) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
for (const event of _buffer) {
|
|
444
|
-
eventSource2.notify(event);
|
|
445
|
-
}
|
|
446
|
-
_buffer = null;
|
|
447
|
-
}
|
|
448
|
-
function notifyOrBuffer(event) {
|
|
449
|
-
if (_buffer !== null) {
|
|
450
|
-
_buffer.push(event);
|
|
451
|
-
return false;
|
|
452
|
-
} else {
|
|
453
|
-
return eventSource2.notify(event);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return {
|
|
457
|
-
...eventSource2,
|
|
458
|
-
notify: notifyOrBuffer,
|
|
459
|
-
pause,
|
|
460
|
-
unpause,
|
|
461
|
-
dispose() {
|
|
462
|
-
eventSource2.dispose();
|
|
463
|
-
if (_buffer !== null) {
|
|
464
|
-
_buffer.length = 0;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// src/lib/freeze.ts
|
|
471
|
-
var freeze = process.env.NODE_ENV === "production" ? (
|
|
472
|
-
/* istanbul ignore next */
|
|
473
|
-
(x) => x
|
|
474
|
-
) : Object.freeze;
|
|
475
|
-
|
|
476
|
-
// src/lib/signals.ts
|
|
477
|
-
var kSinks = Symbol("kSinks");
|
|
478
|
-
var kTrigger = Symbol("kTrigger");
|
|
479
|
-
var signalsToTrigger = null;
|
|
480
|
-
var trackedReads = null;
|
|
481
|
-
function batch(callback) {
|
|
482
|
-
if (signalsToTrigger !== null) {
|
|
483
|
-
callback();
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
signalsToTrigger = /* @__PURE__ */ new Set();
|
|
487
|
-
try {
|
|
488
|
-
callback();
|
|
489
|
-
} finally {
|
|
490
|
-
for (const signal of signalsToTrigger) {
|
|
491
|
-
signal[kTrigger]();
|
|
257
|
+
signalsToTrigger = /* @__PURE__ */ new Set();
|
|
258
|
+
try {
|
|
259
|
+
callback();
|
|
260
|
+
} finally {
|
|
261
|
+
for (const signal of signalsToTrigger) {
|
|
262
|
+
signal[kTrigger]();
|
|
492
263
|
}
|
|
493
264
|
signalsToTrigger = null;
|
|
494
265
|
}
|
|
@@ -590,7 +361,7 @@ var Signal = class extends AbstractSignal {
|
|
|
590
361
|
this.#value = "(disposed)";
|
|
591
362
|
}
|
|
592
363
|
get() {
|
|
593
|
-
_optionalChain([trackedReads, 'optionalAccess',
|
|
364
|
+
_optionalChain([trackedReads, 'optionalAccess', _3 => _3.add, 'call', _4 => _4(this)]);
|
|
594
365
|
return this.#value;
|
|
595
366
|
}
|
|
596
367
|
set(newValue) {
|
|
@@ -695,64 +466,510 @@ var DerivedSignal = class _DerivedSignal extends AbstractSignal {
|
|
|
695
466
|
this.#dirty = true;
|
|
696
467
|
this.markSinksDirty();
|
|
697
468
|
}
|
|
698
|
-
}
|
|
699
|
-
get() {
|
|
700
|
-
if (this.#dirty) {
|
|
701
|
-
this.#recompute();
|
|
469
|
+
}
|
|
470
|
+
get() {
|
|
471
|
+
if (this.#dirty) {
|
|
472
|
+
this.#recompute();
|
|
473
|
+
}
|
|
474
|
+
_optionalChain([trackedReads, 'optionalAccess', _5 => _5.add, 'call', _6 => _6(this)]);
|
|
475
|
+
return this.#prevValue;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Called by the Signal system if one or more of the dependent signals have
|
|
479
|
+
* changed. In the case of a DerivedSignal, we'll only want to re-evaluate
|
|
480
|
+
* the actual value if it's being watched, or any of their sinks are being
|
|
481
|
+
* watched actively.
|
|
482
|
+
*/
|
|
483
|
+
[kTrigger]() {
|
|
484
|
+
if (!this.hasWatchers) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const updated = this.#recompute();
|
|
488
|
+
if (updated) {
|
|
489
|
+
super[kTrigger]();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var MutableSignal = class extends AbstractSignal {
|
|
494
|
+
#state;
|
|
495
|
+
constructor(initialState) {
|
|
496
|
+
super();
|
|
497
|
+
this.#state = initialState;
|
|
498
|
+
}
|
|
499
|
+
dispose() {
|
|
500
|
+
super.dispose();
|
|
501
|
+
this.#state = "(disposed)";
|
|
502
|
+
}
|
|
503
|
+
get() {
|
|
504
|
+
_optionalChain([trackedReads, 'optionalAccess', _7 => _7.add, 'call', _8 => _8(this)]);
|
|
505
|
+
return this.#state;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Invokes a callback function that is allowed to mutate the given state
|
|
509
|
+
* value. Do not change the value outside of the callback.
|
|
510
|
+
*
|
|
511
|
+
* If the callback explicitly returns `false`, it's assumed that the state
|
|
512
|
+
* was not changed.
|
|
513
|
+
*/
|
|
514
|
+
mutate(callback) {
|
|
515
|
+
batch(() => {
|
|
516
|
+
const result = callback ? callback(this.#state) : true;
|
|
517
|
+
if (result !== null && typeof result === "object" && "then" in result) {
|
|
518
|
+
raise("MutableSignal.mutate() does not support async callbacks");
|
|
519
|
+
}
|
|
520
|
+
if (result !== false) {
|
|
521
|
+
this.markSinksDirty();
|
|
522
|
+
enqueueTrigger(this);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// src/lib/SortedList.ts
|
|
529
|
+
function bisectRight(arr, x, lt) {
|
|
530
|
+
let lo = 0;
|
|
531
|
+
let hi = arr.length;
|
|
532
|
+
while (lo < hi) {
|
|
533
|
+
const mid = lo + (hi - lo >> 1);
|
|
534
|
+
if (lt(x, arr[mid])) {
|
|
535
|
+
hi = mid;
|
|
536
|
+
} else {
|
|
537
|
+
lo = mid + 1;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return lo;
|
|
541
|
+
}
|
|
542
|
+
var SortedList = class _SortedList {
|
|
543
|
+
#data;
|
|
544
|
+
#lt;
|
|
545
|
+
constructor(alreadySortedList, lt) {
|
|
546
|
+
this.#lt = lt;
|
|
547
|
+
this.#data = alreadySortedList;
|
|
548
|
+
}
|
|
549
|
+
static with(lt) {
|
|
550
|
+
return _SortedList.fromAlreadySorted([], lt);
|
|
551
|
+
}
|
|
552
|
+
static from(arr, lt) {
|
|
553
|
+
const sorted = new _SortedList([], lt);
|
|
554
|
+
for (const item of arr) {
|
|
555
|
+
sorted.add(item);
|
|
556
|
+
}
|
|
557
|
+
return sorted;
|
|
558
|
+
}
|
|
559
|
+
static fromAlreadySorted(alreadySorted, lt) {
|
|
560
|
+
return new _SortedList(alreadySorted, lt);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Clones the sorted list to a new instance.
|
|
564
|
+
*/
|
|
565
|
+
clone() {
|
|
566
|
+
return new _SortedList(this.#data.slice(), this.#lt);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Adds a new item to the sorted list, such that it remains sorted.
|
|
570
|
+
*/
|
|
571
|
+
add(value) {
|
|
572
|
+
const idx = bisectRight(this.#data, value, this.#lt);
|
|
573
|
+
this.#data.splice(idx, 0, value);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Removes all values from the sorted list, making it empty again.
|
|
577
|
+
* Returns whether the list was mutated or not.
|
|
578
|
+
*/
|
|
579
|
+
clear() {
|
|
580
|
+
const hadData = this.#data.length > 0;
|
|
581
|
+
this.#data.length = 0;
|
|
582
|
+
return hadData;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Removes the first value matching the predicate.
|
|
586
|
+
* Returns whether the list was mutated or not.
|
|
587
|
+
*/
|
|
588
|
+
removeBy(predicate, limit = Number.POSITIVE_INFINITY) {
|
|
589
|
+
let deleted = 0;
|
|
590
|
+
for (let i = 0; i < this.#data.length; i++) {
|
|
591
|
+
if (predicate(this.#data[i])) {
|
|
592
|
+
this.#data.splice(i, 1);
|
|
593
|
+
deleted++;
|
|
594
|
+
if (deleted >= limit) {
|
|
595
|
+
break;
|
|
596
|
+
} else {
|
|
597
|
+
i--;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return deleted > 0;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Removes the given value from the sorted list, if it exists. The given
|
|
605
|
+
* value must be `===` to one of the list items. Only the first entry will be
|
|
606
|
+
* removed if the element exists in the sorted list multiple times.
|
|
607
|
+
*
|
|
608
|
+
* Returns whether the list was mutated or not.
|
|
609
|
+
*/
|
|
610
|
+
remove(value) {
|
|
611
|
+
const idx = this.#data.indexOf(value);
|
|
612
|
+
if (idx >= 0) {
|
|
613
|
+
this.#data.splice(idx, 1);
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
at(index) {
|
|
619
|
+
return this.#data[index];
|
|
620
|
+
}
|
|
621
|
+
get length() {
|
|
622
|
+
return this.#data.length;
|
|
623
|
+
}
|
|
624
|
+
*filter(predicate) {
|
|
625
|
+
for (const item of this.#data) {
|
|
626
|
+
if (predicate(item)) {
|
|
627
|
+
yield item;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
// XXXX If we keep this, add unit tests. Or remove it.
|
|
632
|
+
*findAllRight(predicate) {
|
|
633
|
+
for (let i = this.#data.length - 1; i >= 0; i--) {
|
|
634
|
+
const item = this.#data[i];
|
|
635
|
+
if (predicate(item, i)) {
|
|
636
|
+
yield item;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
[Symbol.iterator]() {
|
|
641
|
+
return this.#data[Symbol.iterator]();
|
|
642
|
+
}
|
|
643
|
+
*iterReversed() {
|
|
644
|
+
for (let i = this.#data.length - 1; i >= 0; i--) {
|
|
645
|
+
yield this.#data[i];
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/** Finds the leftmost item that matches the predicate. */
|
|
649
|
+
find(predicate, start) {
|
|
650
|
+
const idx = this.findIndex(predicate, start);
|
|
651
|
+
return idx > -1 ? this.#data.at(idx) : void 0;
|
|
652
|
+
}
|
|
653
|
+
/** Finds the leftmost index that matches the predicate. */
|
|
654
|
+
findIndex(predicate, start = 0) {
|
|
655
|
+
for (let i = Math.max(0, start); i < this.#data.length; i++) {
|
|
656
|
+
if (predicate(this.#data[i], i)) {
|
|
657
|
+
return i;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return -1;
|
|
661
|
+
}
|
|
662
|
+
/** Finds the rightmost item that matches the predicate. */
|
|
663
|
+
findRight(predicate, start) {
|
|
664
|
+
const idx = this.findIndexRight(predicate, start);
|
|
665
|
+
return idx > -1 ? this.#data.at(idx) : void 0;
|
|
666
|
+
}
|
|
667
|
+
/** Finds the rightmost index that matches the predicate. */
|
|
668
|
+
findIndexRight(predicate, start = this.#data.length - 1) {
|
|
669
|
+
for (let i = Math.min(start, this.#data.length - 1); i >= 0; i--) {
|
|
670
|
+
if (predicate(this.#data[i], i)) {
|
|
671
|
+
return i;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return -1;
|
|
675
|
+
}
|
|
676
|
+
get rawArray() {
|
|
677
|
+
return this.#data;
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// src/AiChatDB.ts
|
|
682
|
+
var AiChatDB = class {
|
|
683
|
+
#byId;
|
|
684
|
+
// A map of chat id to chat details
|
|
685
|
+
#chats;
|
|
686
|
+
// Sorted list of non-deleted chats, most recent first
|
|
687
|
+
|
|
688
|
+
constructor() {
|
|
689
|
+
this.#byId = /* @__PURE__ */ new Map();
|
|
690
|
+
this.#chats = SortedList.from([], (c1, c2) => {
|
|
691
|
+
const d2 = _nullishCoalesce(c2.lastMessageAt, () => ( c2.createdAt));
|
|
692
|
+
const d1 = _nullishCoalesce(c1.lastMessageAt, () => ( c1.createdAt));
|
|
693
|
+
return d2 < d1 ? true : d2 === d1 ? c2.id < c1.id : false;
|
|
694
|
+
});
|
|
695
|
+
this.signal = new MutableSignal(this);
|
|
696
|
+
}
|
|
697
|
+
getEvenIfDeleted(chatId) {
|
|
698
|
+
return this.#byId.get(chatId);
|
|
699
|
+
}
|
|
700
|
+
markDeleted(chatId) {
|
|
701
|
+
const chat = this.#byId.get(chatId);
|
|
702
|
+
if (chat === void 0 || chat.deletedAt !== void 0) return;
|
|
703
|
+
this.upsert({
|
|
704
|
+
...chat,
|
|
705
|
+
deletedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
upsert(chat) {
|
|
709
|
+
this.signal.mutate(() => {
|
|
710
|
+
const existingThread = this.#byId.get(chat.id);
|
|
711
|
+
if (existingThread !== void 0) {
|
|
712
|
+
if (existingThread.deletedAt !== void 0) return false;
|
|
713
|
+
this.#chats.remove(existingThread);
|
|
714
|
+
this.#byId.delete(existingThread.id);
|
|
715
|
+
}
|
|
716
|
+
if (chat.deletedAt === void 0) {
|
|
717
|
+
this.#chats.add(chat);
|
|
718
|
+
}
|
|
719
|
+
this.#byId.set(chat.id, chat);
|
|
720
|
+
return true;
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
findMany(query) {
|
|
724
|
+
return Array.from(
|
|
725
|
+
this.#chats.filter((chat) => {
|
|
726
|
+
if (query.metadata === void 0) return true;
|
|
727
|
+
for (const [key, value] of Object.entries(query.metadata)) {
|
|
728
|
+
if (value === null) {
|
|
729
|
+
if (key in chat.metadata) return false;
|
|
730
|
+
} else if (typeof value === "string") {
|
|
731
|
+
if (chat.metadata[key] !== value) return false;
|
|
732
|
+
} else {
|
|
733
|
+
const chatValue = chat.metadata[key];
|
|
734
|
+
if (!Array.isArray(chatValue) || !value.every((v) => chatValue.includes(v))) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return true;
|
|
740
|
+
})
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
// src/convert-plain-data.ts
|
|
746
|
+
function convertToCommentData(data) {
|
|
747
|
+
const editedAt = data.editedAt ? new Date(data.editedAt) : void 0;
|
|
748
|
+
const createdAt = new Date(data.createdAt);
|
|
749
|
+
const reactions = data.reactions.map((reaction) => ({
|
|
750
|
+
...reaction,
|
|
751
|
+
createdAt: new Date(reaction.createdAt)
|
|
752
|
+
}));
|
|
753
|
+
if (data.body) {
|
|
754
|
+
return {
|
|
755
|
+
...data,
|
|
756
|
+
reactions,
|
|
757
|
+
createdAt,
|
|
758
|
+
editedAt
|
|
759
|
+
};
|
|
760
|
+
} else {
|
|
761
|
+
const deletedAt = new Date(data.deletedAt);
|
|
762
|
+
return {
|
|
763
|
+
...data,
|
|
764
|
+
reactions,
|
|
765
|
+
createdAt,
|
|
766
|
+
editedAt,
|
|
767
|
+
deletedAt
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function convertToThreadData(data) {
|
|
772
|
+
const createdAt = new Date(data.createdAt);
|
|
773
|
+
const updatedAt = new Date(data.updatedAt);
|
|
774
|
+
const comments = data.comments.map(
|
|
775
|
+
(comment) => convertToCommentData(comment)
|
|
776
|
+
);
|
|
777
|
+
return {
|
|
778
|
+
...data,
|
|
779
|
+
createdAt,
|
|
780
|
+
updatedAt,
|
|
781
|
+
comments
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
function convertToCommentUserReaction(data) {
|
|
785
|
+
return {
|
|
786
|
+
...data,
|
|
787
|
+
createdAt: new Date(data.createdAt)
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function convertToInboxNotificationData(data) {
|
|
791
|
+
const notifiedAt = new Date(data.notifiedAt);
|
|
792
|
+
const readAt = data.readAt ? new Date(data.readAt) : null;
|
|
793
|
+
if ("activities" in data) {
|
|
794
|
+
const activities = data.activities.map((activity) => ({
|
|
795
|
+
...activity,
|
|
796
|
+
createdAt: new Date(activity.createdAt)
|
|
797
|
+
}));
|
|
798
|
+
return {
|
|
799
|
+
...data,
|
|
800
|
+
notifiedAt,
|
|
801
|
+
readAt,
|
|
802
|
+
activities
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
return {
|
|
806
|
+
...data,
|
|
807
|
+
notifiedAt,
|
|
808
|
+
readAt
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
function convertToSubscriptionData(data) {
|
|
812
|
+
const createdAt = new Date(data.createdAt);
|
|
813
|
+
return {
|
|
814
|
+
...data,
|
|
815
|
+
createdAt
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function convertToUserSubscriptionData(data) {
|
|
819
|
+
const createdAt = new Date(data.createdAt);
|
|
820
|
+
return {
|
|
821
|
+
...data,
|
|
822
|
+
createdAt
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
function convertToThreadDeleteInfo(data) {
|
|
826
|
+
const deletedAt = new Date(data.deletedAt);
|
|
827
|
+
return {
|
|
828
|
+
...data,
|
|
829
|
+
deletedAt
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function convertToInboxNotificationDeleteInfo(data) {
|
|
833
|
+
const deletedAt = new Date(data.deletedAt);
|
|
834
|
+
return {
|
|
835
|
+
...data,
|
|
836
|
+
deletedAt
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
function convertToSubscriptionDeleteInfo(data) {
|
|
840
|
+
const deletedAt = new Date(data.deletedAt);
|
|
841
|
+
return {
|
|
842
|
+
...data,
|
|
843
|
+
deletedAt
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/lib/fancy-console.ts
|
|
848
|
+
var fancy_console_exports = {};
|
|
849
|
+
__export(fancy_console_exports, {
|
|
850
|
+
error: () => error2,
|
|
851
|
+
errorWithTitle: () => errorWithTitle,
|
|
852
|
+
warn: () => warn,
|
|
853
|
+
warnWithTitle: () => warnWithTitle
|
|
854
|
+
});
|
|
855
|
+
var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
|
|
856
|
+
var bold = "font-weight:600";
|
|
857
|
+
function wrap(method) {
|
|
858
|
+
return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
|
|
859
|
+
/* istanbul ignore next */
|
|
860
|
+
(message, ...args) => console[method]("%cLiveblocks", badge, message, ...args)
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
var warn = wrap("warn");
|
|
864
|
+
var error2 = wrap("error");
|
|
865
|
+
function wrapWithTitle(method) {
|
|
866
|
+
return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
|
|
867
|
+
/* istanbul ignore next */
|
|
868
|
+
(title, message, ...args) => console[method](
|
|
869
|
+
`%cLiveblocks%c ${title}`,
|
|
870
|
+
badge,
|
|
871
|
+
bold,
|
|
872
|
+
message,
|
|
873
|
+
...args
|
|
874
|
+
)
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
var warnWithTitle = wrapWithTitle("warn");
|
|
878
|
+
var errorWithTitle = wrapWithTitle("error");
|
|
879
|
+
|
|
880
|
+
// src/lib/guards.ts
|
|
881
|
+
function isDefined(value) {
|
|
882
|
+
return value !== null && value !== void 0;
|
|
883
|
+
}
|
|
884
|
+
function isPlainObject(blob) {
|
|
885
|
+
return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
|
|
886
|
+
}
|
|
887
|
+
function isStartsWithOperator(blob) {
|
|
888
|
+
return isPlainObject(blob) && typeof blob.startsWith === "string";
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// src/lib/autoRetry.ts
|
|
892
|
+
var HttpError = class _HttpError extends Error {
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
constructor(message, response, details) {
|
|
896
|
+
super(message);
|
|
897
|
+
this.name = "HttpError";
|
|
898
|
+
this.response = response;
|
|
899
|
+
this.details = details;
|
|
900
|
+
}
|
|
901
|
+
static async fromResponse(response) {
|
|
902
|
+
let bodyAsText;
|
|
903
|
+
try {
|
|
904
|
+
bodyAsText = await response.text();
|
|
905
|
+
} catch (e2) {
|
|
906
|
+
}
|
|
907
|
+
const bodyAsJson = bodyAsText ? tryParseJson(bodyAsText) : void 0;
|
|
908
|
+
let bodyAsJsonObject;
|
|
909
|
+
if (isPlainObject(bodyAsJson)) {
|
|
910
|
+
bodyAsJsonObject = bodyAsJson;
|
|
911
|
+
}
|
|
912
|
+
let message = "";
|
|
913
|
+
message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _9 => _9.message]) === "string" ? bodyAsJsonObject.message : "";
|
|
914
|
+
message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _10 => _10.error]) === "string" ? bodyAsJsonObject.error : "";
|
|
915
|
+
if (bodyAsJson === void 0) {
|
|
916
|
+
message ||= bodyAsText || "";
|
|
917
|
+
}
|
|
918
|
+
message ||= response.statusText;
|
|
919
|
+
let path;
|
|
920
|
+
try {
|
|
921
|
+
path = new URL(response.url).pathname;
|
|
922
|
+
} catch (e3) {
|
|
702
923
|
}
|
|
703
|
-
|
|
704
|
-
|
|
924
|
+
message += path !== void 0 ? ` (got status ${response.status} from ${path})` : ` (got status ${response.status})`;
|
|
925
|
+
const details = bodyAsJsonObject;
|
|
926
|
+
return new _HttpError(message, response, details);
|
|
705
927
|
}
|
|
706
928
|
/**
|
|
707
|
-
*
|
|
708
|
-
* changed. In the case of a DerivedSignal, we'll only want to re-evaluate
|
|
709
|
-
* the actual value if it's being watched, or any of their sinks are being
|
|
710
|
-
* watched actively.
|
|
929
|
+
* Convenience accessor for response.status.
|
|
711
930
|
*/
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
const updated = this.#recompute();
|
|
717
|
-
if (updated) {
|
|
718
|
-
super[kTrigger]();
|
|
719
|
-
}
|
|
931
|
+
get status() {
|
|
932
|
+
return this.response.status;
|
|
720
933
|
}
|
|
721
934
|
};
|
|
722
|
-
var
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
_optionalChain([trackedReads, 'optionalAccess', _9 => _9.add, 'call', _10 => _10(this)]);
|
|
734
|
-
return this.#state;
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Invokes a callback function that is allowed to mutate the given state
|
|
738
|
-
* value. Do not change the value outside of the callback.
|
|
739
|
-
*
|
|
740
|
-
* If the callback explicitly returns `false`, it's assumed that the state
|
|
741
|
-
* was not changed.
|
|
742
|
-
*/
|
|
743
|
-
mutate(callback) {
|
|
744
|
-
batch(() => {
|
|
745
|
-
const result = callback ? callback(this.#state) : true;
|
|
746
|
-
if (result !== null && typeof result === "object" && "then" in result) {
|
|
747
|
-
raise("MutableSignal.mutate() does not support async callbacks");
|
|
935
|
+
var DONT_RETRY_4XX = (x) => x instanceof HttpError && x.status >= 400 && x.status < 500;
|
|
936
|
+
async function autoRetry(promiseFn, maxTries, backoff, shouldStopRetrying = DONT_RETRY_4XX) {
|
|
937
|
+
const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
|
|
938
|
+
let attempt = 0;
|
|
939
|
+
while (true) {
|
|
940
|
+
attempt++;
|
|
941
|
+
try {
|
|
942
|
+
return await promiseFn();
|
|
943
|
+
} catch (err) {
|
|
944
|
+
if (shouldStopRetrying(err)) {
|
|
945
|
+
throw err;
|
|
748
946
|
}
|
|
749
|
-
if (
|
|
750
|
-
|
|
751
|
-
enqueueTrigger(this);
|
|
947
|
+
if (attempt >= maxTries) {
|
|
948
|
+
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
752
949
|
}
|
|
753
|
-
}
|
|
950
|
+
}
|
|
951
|
+
const delay = _nullishCoalesce(backoff[attempt - 1], () => ( fallbackBackoff));
|
|
952
|
+
warn(
|
|
953
|
+
`Attempt ${attempt} was unsuccessful. Retrying in ${delay} milliseconds.`
|
|
954
|
+
);
|
|
955
|
+
await wait(delay);
|
|
754
956
|
}
|
|
755
|
-
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
// src/lib/controlledPromise.ts
|
|
960
|
+
function controlledPromise() {
|
|
961
|
+
let resolve;
|
|
962
|
+
let reject;
|
|
963
|
+
const promise = new Promise((res, rej) => {
|
|
964
|
+
resolve = res;
|
|
965
|
+
reject = rej;
|
|
966
|
+
});
|
|
967
|
+
return [promise, resolve, reject];
|
|
968
|
+
}
|
|
969
|
+
function Promise_withResolvers() {
|
|
970
|
+
const [promise, resolve, reject] = controlledPromise();
|
|
971
|
+
return { promise, resolve, reject };
|
|
972
|
+
}
|
|
756
973
|
|
|
757
974
|
// src/lib/stringify.ts
|
|
758
975
|
function replacer(_key, value) {
|
|
@@ -3398,159 +3615,6 @@ function shallow2(a, b) {
|
|
|
3398
3615
|
);
|
|
3399
3616
|
}
|
|
3400
3617
|
|
|
3401
|
-
// src/lib/SortedList.ts
|
|
3402
|
-
function bisectRight(arr, x, lt) {
|
|
3403
|
-
let lo = 0;
|
|
3404
|
-
let hi = arr.length;
|
|
3405
|
-
while (lo < hi) {
|
|
3406
|
-
const mid = lo + (hi - lo >> 1);
|
|
3407
|
-
if (lt(x, arr[mid])) {
|
|
3408
|
-
hi = mid;
|
|
3409
|
-
} else {
|
|
3410
|
-
lo = mid + 1;
|
|
3411
|
-
}
|
|
3412
|
-
}
|
|
3413
|
-
return lo;
|
|
3414
|
-
}
|
|
3415
|
-
var SortedList = class _SortedList {
|
|
3416
|
-
#data;
|
|
3417
|
-
#lt;
|
|
3418
|
-
constructor(alreadySortedList, lt) {
|
|
3419
|
-
this.#lt = lt;
|
|
3420
|
-
this.#data = alreadySortedList;
|
|
3421
|
-
}
|
|
3422
|
-
static with(lt) {
|
|
3423
|
-
return _SortedList.fromAlreadySorted([], lt);
|
|
3424
|
-
}
|
|
3425
|
-
static from(arr, lt) {
|
|
3426
|
-
const sorted = new _SortedList([], lt);
|
|
3427
|
-
for (const item of arr) {
|
|
3428
|
-
sorted.add(item);
|
|
3429
|
-
}
|
|
3430
|
-
return sorted;
|
|
3431
|
-
}
|
|
3432
|
-
static fromAlreadySorted(alreadySorted, lt) {
|
|
3433
|
-
return new _SortedList(alreadySorted, lt);
|
|
3434
|
-
}
|
|
3435
|
-
/**
|
|
3436
|
-
* Clones the sorted list to a new instance.
|
|
3437
|
-
*/
|
|
3438
|
-
clone() {
|
|
3439
|
-
return new _SortedList(this.#data.slice(), this.#lt);
|
|
3440
|
-
}
|
|
3441
|
-
/**
|
|
3442
|
-
* Adds a new item to the sorted list, such that it remains sorted.
|
|
3443
|
-
*/
|
|
3444
|
-
add(value) {
|
|
3445
|
-
const idx = bisectRight(this.#data, value, this.#lt);
|
|
3446
|
-
this.#data.splice(idx, 0, value);
|
|
3447
|
-
}
|
|
3448
|
-
/**
|
|
3449
|
-
* Removes all values from the sorted list, making it empty again.
|
|
3450
|
-
* Returns whether the list was mutated or not.
|
|
3451
|
-
*/
|
|
3452
|
-
clear() {
|
|
3453
|
-
const hadData = this.#data.length > 0;
|
|
3454
|
-
this.#data.length = 0;
|
|
3455
|
-
return hadData;
|
|
3456
|
-
}
|
|
3457
|
-
/**
|
|
3458
|
-
* Removes the first value matching the predicate.
|
|
3459
|
-
* Returns whether the list was mutated or not.
|
|
3460
|
-
*/
|
|
3461
|
-
removeBy(predicate, limit = Number.POSITIVE_INFINITY) {
|
|
3462
|
-
let deleted = 0;
|
|
3463
|
-
for (let i = 0; i < this.#data.length; i++) {
|
|
3464
|
-
if (predicate(this.#data[i])) {
|
|
3465
|
-
this.#data.splice(i, 1);
|
|
3466
|
-
deleted++;
|
|
3467
|
-
if (deleted >= limit) {
|
|
3468
|
-
break;
|
|
3469
|
-
} else {
|
|
3470
|
-
i--;
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
}
|
|
3474
|
-
return deleted > 0;
|
|
3475
|
-
}
|
|
3476
|
-
/**
|
|
3477
|
-
* Removes the given value from the sorted list, if it exists. The given
|
|
3478
|
-
* value must be `===` to one of the list items. Only the first entry will be
|
|
3479
|
-
* removed if the element exists in the sorted list multiple times.
|
|
3480
|
-
*
|
|
3481
|
-
* Returns whether the list was mutated or not.
|
|
3482
|
-
*/
|
|
3483
|
-
remove(value) {
|
|
3484
|
-
const idx = this.#data.indexOf(value);
|
|
3485
|
-
if (idx >= 0) {
|
|
3486
|
-
this.#data.splice(idx, 1);
|
|
3487
|
-
return true;
|
|
3488
|
-
}
|
|
3489
|
-
return false;
|
|
3490
|
-
}
|
|
3491
|
-
at(index) {
|
|
3492
|
-
return this.#data[index];
|
|
3493
|
-
}
|
|
3494
|
-
get length() {
|
|
3495
|
-
return this.#data.length;
|
|
3496
|
-
}
|
|
3497
|
-
*filter(predicate) {
|
|
3498
|
-
for (const item of this.#data) {
|
|
3499
|
-
if (predicate(item)) {
|
|
3500
|
-
yield item;
|
|
3501
|
-
}
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
// XXXX If we keep this, add unit tests. Or remove it.
|
|
3505
|
-
*findAllRight(predicate) {
|
|
3506
|
-
for (let i = this.#data.length - 1; i >= 0; i--) {
|
|
3507
|
-
const item = this.#data[i];
|
|
3508
|
-
if (predicate(item, i)) {
|
|
3509
|
-
yield item;
|
|
3510
|
-
}
|
|
3511
|
-
}
|
|
3512
|
-
}
|
|
3513
|
-
[Symbol.iterator]() {
|
|
3514
|
-
return this.#data[Symbol.iterator]();
|
|
3515
|
-
}
|
|
3516
|
-
*iterReversed() {
|
|
3517
|
-
for (let i = this.#data.length - 1; i >= 0; i--) {
|
|
3518
|
-
yield this.#data[i];
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
/** Finds the leftmost item that matches the predicate. */
|
|
3522
|
-
find(predicate, start) {
|
|
3523
|
-
const idx = this.findIndex(predicate, start);
|
|
3524
|
-
return idx > -1 ? this.#data.at(idx) : void 0;
|
|
3525
|
-
}
|
|
3526
|
-
/** Finds the leftmost index that matches the predicate. */
|
|
3527
|
-
findIndex(predicate, start = 0) {
|
|
3528
|
-
for (let i = Math.max(0, start); i < this.#data.length; i++) {
|
|
3529
|
-
if (predicate(this.#data[i], i)) {
|
|
3530
|
-
return i;
|
|
3531
|
-
}
|
|
3532
|
-
}
|
|
3533
|
-
return -1;
|
|
3534
|
-
}
|
|
3535
|
-
/** Finds the rightmost item that matches the predicate. */
|
|
3536
|
-
findRight(predicate, start) {
|
|
3537
|
-
const idx = this.findIndexRight(predicate, start);
|
|
3538
|
-
return idx > -1 ? this.#data.at(idx) : void 0;
|
|
3539
|
-
}
|
|
3540
|
-
/** Finds the rightmost index that matches the predicate. */
|
|
3541
|
-
findIndexRight(predicate, start = this.#data.length - 1) {
|
|
3542
|
-
for (let i = Math.min(start, this.#data.length - 1); i >= 0; i--) {
|
|
3543
|
-
if (predicate(this.#data[i], i)) {
|
|
3544
|
-
return i;
|
|
3545
|
-
}
|
|
3546
|
-
}
|
|
3547
|
-
return -1;
|
|
3548
|
-
}
|
|
3549
|
-
get rawArray() {
|
|
3550
|
-
return this.#data;
|
|
3551
|
-
}
|
|
3552
|
-
};
|
|
3553
|
-
|
|
3554
3618
|
// src/lib/TreePool.ts
|
|
3555
3619
|
var TreePool = class {
|
|
3556
3620
|
#_items;
|
|
@@ -4151,39 +4215,29 @@ function createStore_forChatMessages(toolsStore, setToolResultFn) {
|
|
|
4151
4215
|
};
|
|
4152
4216
|
}
|
|
4153
4217
|
function createStore_forUserAiChats() {
|
|
4154
|
-
const
|
|
4155
|
-
SortedList.with((x, y) => y.createdAt < x.createdAt)
|
|
4156
|
-
);
|
|
4157
|
-
const nonDeletedChats\u03A3 = DerivedSignal.from(
|
|
4158
|
-
() => Array.from(allChatsInclDeleted\u03A3.get()).filter((c) => !c.deletedAt)
|
|
4159
|
-
);
|
|
4218
|
+
const chatsDB = new AiChatDB();
|
|
4160
4219
|
function upsertMany(chats) {
|
|
4161
|
-
|
|
4220
|
+
batch(() => {
|
|
4162
4221
|
for (const chat of chats) {
|
|
4163
|
-
|
|
4164
|
-
list.add(chat);
|
|
4222
|
+
chatsDB.upsert(chat);
|
|
4165
4223
|
}
|
|
4166
4224
|
});
|
|
4167
4225
|
}
|
|
4168
4226
|
function upsert(chat) {
|
|
4169
|
-
|
|
4227
|
+
chatsDB.upsert(chat);
|
|
4170
4228
|
}
|
|
4171
4229
|
function markDeleted(chatId) {
|
|
4172
|
-
|
|
4173
|
-
const chat = list.find((c) => c.id === chatId);
|
|
4174
|
-
if (!chat) return false;
|
|
4175
|
-
upsert({ ...chat, deletedAt: now() });
|
|
4176
|
-
return void 0;
|
|
4177
|
-
});
|
|
4230
|
+
chatsDB.markDeleted(chatId);
|
|
4178
4231
|
}
|
|
4179
4232
|
function getChatById(chatId) {
|
|
4180
|
-
return
|
|
4181
|
-
|
|
4182
|
-
|
|
4233
|
+
return chatsDB.getEvenIfDeleted(chatId);
|
|
4234
|
+
}
|
|
4235
|
+
function findMany(query) {
|
|
4236
|
+
return chatsDB.signal.get().findMany(query);
|
|
4183
4237
|
}
|
|
4184
4238
|
return {
|
|
4185
|
-
chats\u03A3: nonDeletedChats\u03A3,
|
|
4186
4239
|
getChatById,
|
|
4240
|
+
findMany,
|
|
4187
4241
|
// Mutations
|
|
4188
4242
|
upsert,
|
|
4189
4243
|
upsertMany,
|
|
@@ -4396,7 +4450,8 @@ function createAi(config) {
|
|
|
4396
4450
|
function getChats(options = {}) {
|
|
4397
4451
|
return sendClientMsgWithResponse({
|
|
4398
4452
|
cmd: "get-chats",
|
|
4399
|
-
cursor: options.cursor
|
|
4453
|
+
cursor: options.cursor,
|
|
4454
|
+
query: options.query
|
|
4400
4455
|
});
|
|
4401
4456
|
}
|
|
4402
4457
|
function getOrCreateChat(id, options) {
|
|
@@ -4461,7 +4516,9 @@ function createAi(config) {
|
|
|
4461
4516
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4462
4517
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4463
4518
|
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4464
|
-
const
|
|
4519
|
+
const globalKnowledge = context.knowledge.get();
|
|
4520
|
+
const requestKnowledge = _optionalChain([options, 'optionalAccess', _79 => _79.knowledge]) || [];
|
|
4521
|
+
const combinedKnowledge = [...globalKnowledge, ...requestKnowledge];
|
|
4465
4522
|
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4466
4523
|
const resp = await sendClientMsgWithResponse({
|
|
4467
4524
|
cmd: "ask-in-chat",
|
|
@@ -4469,12 +4526,11 @@ function createAi(config) {
|
|
|
4469
4526
|
sourceMessage: userMessage,
|
|
4470
4527
|
targetMessageId,
|
|
4471
4528
|
generationOptions: {
|
|
4472
|
-
copilotId: _optionalChain([options, 'optionalAccess',
|
|
4473
|
-
stream: _optionalChain([options, 'optionalAccess',
|
|
4474
|
-
timeout: _optionalChain([options, 'optionalAccess',
|
|
4475
|
-
//
|
|
4476
|
-
|
|
4477
|
-
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4529
|
+
copilotId: _optionalChain([options, 'optionalAccess', _80 => _80.copilotId]),
|
|
4530
|
+
stream: _optionalChain([options, 'optionalAccess', _81 => _81.stream]),
|
|
4531
|
+
timeout: _optionalChain([options, 'optionalAccess', _82 => _82.timeout]),
|
|
4532
|
+
// Combine global knowledge with request-specific knowledge
|
|
4533
|
+
knowledge: combinedKnowledge.length > 0 ? combinedKnowledge : void 0,
|
|
4478
4534
|
tools: tools.length > 0 ? tools : void 0
|
|
4479
4535
|
}
|
|
4480
4536
|
});
|
|
@@ -4485,11 +4541,11 @@ function createAi(config) {
|
|
|
4485
4541
|
setToolResult,
|
|
4486
4542
|
getStatus: () => managedSocket.getStatus(),
|
|
4487
4543
|
signals: {
|
|
4488
|
-
chats\u03A3: context.chatsStore.chats\u03A3,
|
|
4489
4544
|
getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
|
|
4490
4545
|
getTool\u03A3: context.toolsStore.getTool\u03A3
|
|
4491
4546
|
},
|
|
4492
4547
|
getChatById: context.chatsStore.getChatById,
|
|
4548
|
+
queryChats: context.chatsStore.findMany,
|
|
4493
4549
|
registerKnowledgeLayer,
|
|
4494
4550
|
deregisterKnowledgeLayer,
|
|
4495
4551
|
updateKnowledge,
|
|
@@ -4573,7 +4629,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
4573
4629
|
return void 0;
|
|
4574
4630
|
}
|
|
4575
4631
|
async function makeAuthRequest(options) {
|
|
4576
|
-
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access',
|
|
4632
|
+
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _83 => _83.polyfills, 'optionalAccess', _84 => _84.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
|
|
4577
4633
|
if (authentication.type === "private") {
|
|
4578
4634
|
if (fetcher === void 0) {
|
|
4579
4635
|
throw new StopRetrying(
|
|
@@ -4589,7 +4645,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
4589
4645
|
"The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
|
|
4590
4646
|
);
|
|
4591
4647
|
}
|
|
4592
|
-
_optionalChain([onAuthenticate, 'optionalCall',
|
|
4648
|
+
_optionalChain([onAuthenticate, 'optionalCall', _85 => _85(parsed.parsed)]);
|
|
4593
4649
|
return parsed;
|
|
4594
4650
|
}
|
|
4595
4651
|
if (authentication.type === "custom") {
|
|
@@ -4597,7 +4653,7 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
4597
4653
|
if (response && typeof response === "object") {
|
|
4598
4654
|
if (typeof response.token === "string") {
|
|
4599
4655
|
const parsed = parseAuthToken(response.token);
|
|
4600
|
-
_optionalChain([onAuthenticate, 'optionalCall',
|
|
4656
|
+
_optionalChain([onAuthenticate, 'optionalCall', _86 => _86(parsed.parsed)]);
|
|
4601
4657
|
return parsed;
|
|
4602
4658
|
} else if (typeof response.error === "string") {
|
|
4603
4659
|
const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
|
|
@@ -4755,7 +4811,7 @@ function sendToPanel(message, options) {
|
|
|
4755
4811
|
...message,
|
|
4756
4812
|
source: "liveblocks-devtools-client"
|
|
4757
4813
|
};
|
|
4758
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
4814
|
+
if (!(_optionalChain([options, 'optionalAccess', _87 => _87.force]) || _bridgeActive)) {
|
|
4759
4815
|
return;
|
|
4760
4816
|
}
|
|
4761
4817
|
window.postMessage(fullMsg, "*");
|
|
@@ -4763,7 +4819,7 @@ function sendToPanel(message, options) {
|
|
|
4763
4819
|
var eventSource = makeEventSource();
|
|
4764
4820
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
4765
4821
|
window.addEventListener("message", (event) => {
|
|
4766
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
4822
|
+
if (event.source === window && _optionalChain([event, 'access', _88 => _88.data, 'optionalAccess', _89 => _89.source]) === "liveblocks-devtools-panel") {
|
|
4767
4823
|
eventSource.notify(event.data);
|
|
4768
4824
|
} else {
|
|
4769
4825
|
}
|
|
@@ -4905,7 +4961,7 @@ function fullSync(room) {
|
|
|
4905
4961
|
msg: "room::sync::full",
|
|
4906
4962
|
roomId: room.id,
|
|
4907
4963
|
status: room.getStatus(),
|
|
4908
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
4964
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _90 => _90.toTreeNode, 'call', _91 => _91("root"), 'access', _92 => _92.payload]), () => ( null)),
|
|
4909
4965
|
me,
|
|
4910
4966
|
others
|
|
4911
4967
|
});
|
|
@@ -5196,7 +5252,7 @@ function createManagedPool(roomId, options) {
|
|
|
5196
5252
|
generateId: () => `${getCurrentConnectionId()}:${clock++}`,
|
|
5197
5253
|
generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
|
|
5198
5254
|
dispatch(ops, reverse, storageUpdates) {
|
|
5199
|
-
_optionalChain([onDispatch, 'optionalCall',
|
|
5255
|
+
_optionalChain([onDispatch, 'optionalCall', _93 => _93(ops, reverse, storageUpdates)]);
|
|
5200
5256
|
},
|
|
5201
5257
|
assertStorageIsWritable: () => {
|
|
5202
5258
|
if (!isStorageWritable()) {
|
|
@@ -5423,7 +5479,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
5423
5479
|
return [
|
|
5424
5480
|
{
|
|
5425
5481
|
type: 8 /* CREATE_REGISTER */,
|
|
5426
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
5482
|
+
opId: _optionalChain([pool, 'optionalAccess', _94 => _94.generateOpId, 'call', _95 => _95()]),
|
|
5427
5483
|
id: this._id,
|
|
5428
5484
|
parentId,
|
|
5429
5485
|
parentKey,
|
|
@@ -5529,7 +5585,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5529
5585
|
const ops = [];
|
|
5530
5586
|
const op = {
|
|
5531
5587
|
id: this._id,
|
|
5532
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
5588
|
+
opId: _optionalChain([pool, 'optionalAccess', _96 => _96.generateOpId, 'call', _97 => _97()]),
|
|
5533
5589
|
type: 2 /* CREATE_LIST */,
|
|
5534
5590
|
parentId,
|
|
5535
5591
|
parentKey
|
|
@@ -5800,7 +5856,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5800
5856
|
#applyInsertUndoRedo(op) {
|
|
5801
5857
|
const { id, parentKey: key } = op;
|
|
5802
5858
|
const child = creationOpToLiveNode(op);
|
|
5803
|
-
if (_optionalChain([this, 'access',
|
|
5859
|
+
if (_optionalChain([this, 'access', _98 => _98._pool, 'optionalAccess', _99 => _99.getNode, 'call', _100 => _100(id)]) !== void 0) {
|
|
5804
5860
|
return { modified: false };
|
|
5805
5861
|
}
|
|
5806
5862
|
child._attach(id, nn(this._pool));
|
|
@@ -5808,8 +5864,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5808
5864
|
const existingItemIndex = this._indexOfPosition(key);
|
|
5809
5865
|
let newKey = key;
|
|
5810
5866
|
if (existingItemIndex !== -1) {
|
|
5811
|
-
const before2 = _optionalChain([this, 'access',
|
|
5812
|
-
const after2 = _optionalChain([this, 'access',
|
|
5867
|
+
const before2 = _optionalChain([this, 'access', _101 => _101.#items, 'access', _102 => _102[existingItemIndex], 'optionalAccess', _103 => _103._parentPos]);
|
|
5868
|
+
const after2 = _optionalChain([this, 'access', _104 => _104.#items, 'access', _105 => _105[existingItemIndex + 1], 'optionalAccess', _106 => _106._parentPos]);
|
|
5813
5869
|
newKey = makePosition(before2, after2);
|
|
5814
5870
|
child._setParentLink(this, newKey);
|
|
5815
5871
|
}
|
|
@@ -5823,7 +5879,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5823
5879
|
#applySetUndoRedo(op) {
|
|
5824
5880
|
const { id, parentKey: key } = op;
|
|
5825
5881
|
const child = creationOpToLiveNode(op);
|
|
5826
|
-
if (_optionalChain([this, 'access',
|
|
5882
|
+
if (_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.getNode, 'call', _109 => _109(id)]) !== void 0) {
|
|
5827
5883
|
return { modified: false };
|
|
5828
5884
|
}
|
|
5829
5885
|
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -5944,7 +6000,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5944
6000
|
} else {
|
|
5945
6001
|
this.#items[existingItemIndex]._setParentLink(
|
|
5946
6002
|
this,
|
|
5947
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6003
|
+
makePosition(newKey, _optionalChain([this, 'access', _110 => _110.#items, 'access', _111 => _111[existingItemIndex + 1], 'optionalAccess', _112 => _112._parentPos]))
|
|
5948
6004
|
);
|
|
5949
6005
|
const previousIndex = this.#items.indexOf(child);
|
|
5950
6006
|
child._setParentLink(this, newKey);
|
|
@@ -5969,7 +6025,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5969
6025
|
if (existingItemIndex !== -1) {
|
|
5970
6026
|
this.#items[existingItemIndex]._setParentLink(
|
|
5971
6027
|
this,
|
|
5972
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6028
|
+
makePosition(newKey, _optionalChain([this, 'access', _113 => _113.#items, 'access', _114 => _114[existingItemIndex + 1], 'optionalAccess', _115 => _115._parentPos]))
|
|
5973
6029
|
);
|
|
5974
6030
|
}
|
|
5975
6031
|
child._setParentLink(this, newKey);
|
|
@@ -5988,7 +6044,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
5988
6044
|
if (existingItemIndex !== -1) {
|
|
5989
6045
|
this.#items[existingItemIndex]._setParentLink(
|
|
5990
6046
|
this,
|
|
5991
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6047
|
+
makePosition(newKey, _optionalChain([this, 'access', _116 => _116.#items, 'access', _117 => _117[existingItemIndex + 1], 'optionalAccess', _118 => _118._parentPos]))
|
|
5992
6048
|
);
|
|
5993
6049
|
}
|
|
5994
6050
|
child._setParentLink(this, newKey);
|
|
@@ -6015,7 +6071,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6015
6071
|
if (existingItemIndex !== -1) {
|
|
6016
6072
|
this.#items[existingItemIndex]._setParentLink(
|
|
6017
6073
|
this,
|
|
6018
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6074
|
+
makePosition(newKey, _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120[existingItemIndex + 1], 'optionalAccess', _121 => _121._parentPos]))
|
|
6019
6075
|
);
|
|
6020
6076
|
}
|
|
6021
6077
|
child._setParentLink(this, newKey);
|
|
@@ -6073,7 +6129,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6073
6129
|
* @param element The element to add to the end of the LiveList.
|
|
6074
6130
|
*/
|
|
6075
6131
|
push(element) {
|
|
6076
|
-
_optionalChain([this, 'access',
|
|
6132
|
+
_optionalChain([this, 'access', _122 => _122._pool, 'optionalAccess', _123 => _123.assertStorageIsWritable, 'call', _124 => _124()]);
|
|
6077
6133
|
return this.insert(element, this.length);
|
|
6078
6134
|
}
|
|
6079
6135
|
/**
|
|
@@ -6082,7 +6138,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6082
6138
|
* @param index The index at which you want to insert the element.
|
|
6083
6139
|
*/
|
|
6084
6140
|
insert(element, index) {
|
|
6085
|
-
_optionalChain([this, 'access',
|
|
6141
|
+
_optionalChain([this, 'access', _125 => _125._pool, 'optionalAccess', _126 => _126.assertStorageIsWritable, 'call', _127 => _127()]);
|
|
6086
6142
|
if (index < 0 || index > this.#items.length) {
|
|
6087
6143
|
throw new Error(
|
|
6088
6144
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
@@ -6112,7 +6168,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6112
6168
|
* @param targetIndex The index where the element should be after moving.
|
|
6113
6169
|
*/
|
|
6114
6170
|
move(index, targetIndex) {
|
|
6115
|
-
_optionalChain([this, 'access',
|
|
6171
|
+
_optionalChain([this, 'access', _128 => _128._pool, 'optionalAccess', _129 => _129.assertStorageIsWritable, 'call', _130 => _130()]);
|
|
6116
6172
|
if (targetIndex < 0) {
|
|
6117
6173
|
throw new Error("targetIndex cannot be less than 0");
|
|
6118
6174
|
}
|
|
@@ -6170,7 +6226,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6170
6226
|
* @param index The index of the element to delete
|
|
6171
6227
|
*/
|
|
6172
6228
|
delete(index) {
|
|
6173
|
-
_optionalChain([this, 'access',
|
|
6229
|
+
_optionalChain([this, 'access', _131 => _131._pool, 'optionalAccess', _132 => _132.assertStorageIsWritable, 'call', _133 => _133()]);
|
|
6174
6230
|
if (index < 0 || index >= this.#items.length) {
|
|
6175
6231
|
throw new Error(
|
|
6176
6232
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -6203,7 +6259,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6203
6259
|
}
|
|
6204
6260
|
}
|
|
6205
6261
|
clear() {
|
|
6206
|
-
_optionalChain([this, 'access',
|
|
6262
|
+
_optionalChain([this, 'access', _134 => _134._pool, 'optionalAccess', _135 => _135.assertStorageIsWritable, 'call', _136 => _136()]);
|
|
6207
6263
|
if (this._pool) {
|
|
6208
6264
|
const ops = [];
|
|
6209
6265
|
const reverseOps = [];
|
|
@@ -6237,7 +6293,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6237
6293
|
}
|
|
6238
6294
|
}
|
|
6239
6295
|
set(index, item) {
|
|
6240
|
-
_optionalChain([this, 'access',
|
|
6296
|
+
_optionalChain([this, 'access', _137 => _137._pool, 'optionalAccess', _138 => _138.assertStorageIsWritable, 'call', _139 => _139()]);
|
|
6241
6297
|
if (index < 0 || index >= this.#items.length) {
|
|
6242
6298
|
throw new Error(
|
|
6243
6299
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -6383,7 +6439,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6383
6439
|
#shiftItemPosition(index, key) {
|
|
6384
6440
|
const shiftedPosition = makePosition(
|
|
6385
6441
|
key,
|
|
6386
|
-
this.#items.length > index + 1 ? _optionalChain([this, 'access',
|
|
6442
|
+
this.#items.length > index + 1 ? _optionalChain([this, 'access', _140 => _140.#items, 'access', _141 => _141[index + 1], 'optionalAccess', _142 => _142._parentPos]) : void 0
|
|
6387
6443
|
);
|
|
6388
6444
|
this.#items[index]._setParentLink(this, shiftedPosition);
|
|
6389
6445
|
}
|
|
@@ -6508,7 +6564,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
6508
6564
|
const ops = [];
|
|
6509
6565
|
const op = {
|
|
6510
6566
|
id: this._id,
|
|
6511
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
6567
|
+
opId: _optionalChain([pool, 'optionalAccess', _143 => _143.generateOpId, 'call', _144 => _144()]),
|
|
6512
6568
|
type: 7 /* CREATE_MAP */,
|
|
6513
6569
|
parentId,
|
|
6514
6570
|
parentKey
|
|
@@ -6643,7 +6699,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
6643
6699
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
6644
6700
|
*/
|
|
6645
6701
|
set(key, value) {
|
|
6646
|
-
_optionalChain([this, 'access',
|
|
6702
|
+
_optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
|
|
6647
6703
|
const oldValue = this.#map.get(key);
|
|
6648
6704
|
if (oldValue) {
|
|
6649
6705
|
oldValue._detach();
|
|
@@ -6689,7 +6745,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
6689
6745
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
6690
6746
|
*/
|
|
6691
6747
|
delete(key) {
|
|
6692
|
-
_optionalChain([this, 'access',
|
|
6748
|
+
_optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
|
|
6693
6749
|
const item = this.#map.get(key);
|
|
6694
6750
|
if (item === void 0) {
|
|
6695
6751
|
return false;
|
|
@@ -6879,7 +6935,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
6879
6935
|
if (this._id === void 0) {
|
|
6880
6936
|
throw new Error("Cannot serialize item is not attached");
|
|
6881
6937
|
}
|
|
6882
|
-
const opId = _optionalChain([pool, 'optionalAccess',
|
|
6938
|
+
const opId = _optionalChain([pool, 'optionalAccess', _151 => _151.generateOpId, 'call', _152 => _152()]);
|
|
6883
6939
|
const ops = [];
|
|
6884
6940
|
const op = {
|
|
6885
6941
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -7151,7 +7207,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7151
7207
|
* @param value The value of the property to add
|
|
7152
7208
|
*/
|
|
7153
7209
|
set(key, value) {
|
|
7154
|
-
_optionalChain([this, 'access',
|
|
7210
|
+
_optionalChain([this, 'access', _153 => _153._pool, 'optionalAccess', _154 => _154.assertStorageIsWritable, 'call', _155 => _155()]);
|
|
7155
7211
|
this.update({ [key]: value });
|
|
7156
7212
|
}
|
|
7157
7213
|
/**
|
|
@@ -7166,7 +7222,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7166
7222
|
* @param key The key of the property to delete
|
|
7167
7223
|
*/
|
|
7168
7224
|
delete(key) {
|
|
7169
|
-
_optionalChain([this, 'access',
|
|
7225
|
+
_optionalChain([this, 'access', _156 => _156._pool, 'optionalAccess', _157 => _157.assertStorageIsWritable, 'call', _158 => _158()]);
|
|
7170
7226
|
const keyAsString = key;
|
|
7171
7227
|
const oldValue = this.#map.get(keyAsString);
|
|
7172
7228
|
if (oldValue === void 0) {
|
|
@@ -7219,7 +7275,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7219
7275
|
* @param patch The object used to overrides properties
|
|
7220
7276
|
*/
|
|
7221
7277
|
update(patch) {
|
|
7222
|
-
_optionalChain([this, 'access',
|
|
7278
|
+
_optionalChain([this, 'access', _159 => _159._pool, 'optionalAccess', _160 => _160.assertStorageIsWritable, 'call', _161 => _161()]);
|
|
7223
7279
|
if (_LiveObject.detectLargeObjects) {
|
|
7224
7280
|
const data = {};
|
|
7225
7281
|
for (const [key, value] of this.#map) {
|
|
@@ -7967,15 +8023,15 @@ function installBackgroundTabSpy() {
|
|
|
7967
8023
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
7968
8024
|
const inBackgroundSince = { current: null };
|
|
7969
8025
|
function onVisibilityChange() {
|
|
7970
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
8026
|
+
if (_optionalChain([doc, 'optionalAccess', _162 => _162.visibilityState]) === "hidden") {
|
|
7971
8027
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
7972
8028
|
} else {
|
|
7973
8029
|
inBackgroundSince.current = null;
|
|
7974
8030
|
}
|
|
7975
8031
|
}
|
|
7976
|
-
_optionalChain([doc, 'optionalAccess',
|
|
8032
|
+
_optionalChain([doc, 'optionalAccess', _163 => _163.addEventListener, 'call', _164 => _164("visibilitychange", onVisibilityChange)]);
|
|
7977
8033
|
const unsub = () => {
|
|
7978
|
-
_optionalChain([doc, 'optionalAccess',
|
|
8034
|
+
_optionalChain([doc, 'optionalAccess', _165 => _165.removeEventListener, 'call', _166 => _166("visibilitychange", onVisibilityChange)]);
|
|
7979
8035
|
};
|
|
7980
8036
|
return [inBackgroundSince, unsub];
|
|
7981
8037
|
}
|
|
@@ -8155,7 +8211,7 @@ function createRoom(options, config) {
|
|
|
8155
8211
|
}
|
|
8156
8212
|
}
|
|
8157
8213
|
function isStorageWritable() {
|
|
8158
|
-
const scopes = _optionalChain([context, 'access',
|
|
8214
|
+
const scopes = _optionalChain([context, 'access', _167 => _167.dynamicSessionInfoSig, 'access', _168 => _168.get, 'call', _169 => _169(), 'optionalAccess', _170 => _170.scopes]);
|
|
8159
8215
|
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
8160
8216
|
}
|
|
8161
8217
|
const eventHub = {
|
|
@@ -8281,7 +8337,7 @@ function createRoom(options, config) {
|
|
|
8281
8337
|
}
|
|
8282
8338
|
case "experimental-fallback-to-http": {
|
|
8283
8339
|
warn("Message is too large for websockets, so sending over HTTP instead");
|
|
8284
|
-
const nonce = _nullishCoalesce(_optionalChain([context, 'access',
|
|
8340
|
+
const nonce = _nullishCoalesce(_optionalChain([context, 'access', _171 => _171.dynamicSessionInfoSig, 'access', _172 => _172.get, 'call', _173 => _173(), 'optionalAccess', _174 => _174.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
|
|
8285
8341
|
void httpClient.sendMessages({ roomId, nonce, messages }).then((resp) => {
|
|
8286
8342
|
if (!resp.ok && resp.status === 403) {
|
|
8287
8343
|
managedSocket.reconnect();
|
|
@@ -8332,7 +8388,7 @@ function createRoom(options, config) {
|
|
|
8332
8388
|
} else {
|
|
8333
8389
|
context.root = LiveObject._fromItems(message.items, context.pool);
|
|
8334
8390
|
}
|
|
8335
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
8391
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _175 => _175.get, 'call', _176 => _176(), 'optionalAccess', _177 => _177.canWrite]), () => ( true));
|
|
8336
8392
|
const stackSizeBefore = context.undoStack.length;
|
|
8337
8393
|
for (const key in context.initialStorage) {
|
|
8338
8394
|
if (context.root.get(key) === void 0) {
|
|
@@ -8535,7 +8591,7 @@ function createRoom(options, config) {
|
|
|
8535
8591
|
}
|
|
8536
8592
|
context.myPresence.patch(patch);
|
|
8537
8593
|
if (context.activeBatch) {
|
|
8538
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
8594
|
+
if (_optionalChain([options2, 'optionalAccess', _178 => _178.addToHistory])) {
|
|
8539
8595
|
context.activeBatch.reverseOps.pushLeft({
|
|
8540
8596
|
type: "presence",
|
|
8541
8597
|
data: oldValues
|
|
@@ -8544,7 +8600,7 @@ function createRoom(options, config) {
|
|
|
8544
8600
|
context.activeBatch.updates.presence = true;
|
|
8545
8601
|
} else {
|
|
8546
8602
|
flushNowOrSoon();
|
|
8547
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
8603
|
+
if (_optionalChain([options2, 'optionalAccess', _179 => _179.addToHistory])) {
|
|
8548
8604
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
8549
8605
|
}
|
|
8550
8606
|
notify({ presence: true });
|
|
@@ -8741,7 +8797,7 @@ function createRoom(options, config) {
|
|
|
8741
8797
|
if (process.env.NODE_ENV !== "production") {
|
|
8742
8798
|
const traces = /* @__PURE__ */ new Set();
|
|
8743
8799
|
for (const opId of message.opIds) {
|
|
8744
|
-
const trace = _optionalChain([context, 'access',
|
|
8800
|
+
const trace = _optionalChain([context, 'access', _180 => _180.opStackTraces, 'optionalAccess', _181 => _181.get, 'call', _182 => _182(opId)]);
|
|
8745
8801
|
if (trace) {
|
|
8746
8802
|
traces.add(trace);
|
|
8747
8803
|
}
|
|
@@ -8875,7 +8931,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
8875
8931
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
8876
8932
|
createOrUpdateRootFromMessage(message);
|
|
8877
8933
|
applyAndSendOps(unacknowledgedOps);
|
|
8878
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
8934
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _183 => _183()]);
|
|
8879
8935
|
notifyStorageStatus();
|
|
8880
8936
|
eventHub.storageDidLoad.notify();
|
|
8881
8937
|
}
|
|
@@ -9096,8 +9152,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9096
9152
|
async function getThreads(options2) {
|
|
9097
9153
|
return httpClient.getThreads({
|
|
9098
9154
|
roomId,
|
|
9099
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
9100
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
9155
|
+
query: _optionalChain([options2, 'optionalAccess', _184 => _184.query]),
|
|
9156
|
+
cursor: _optionalChain([options2, 'optionalAccess', _185 => _185.cursor])
|
|
9101
9157
|
});
|
|
9102
9158
|
}
|
|
9103
9159
|
async function getThread(threadId) {
|
|
@@ -9204,7 +9260,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9204
9260
|
function getSubscriptionSettings(options2) {
|
|
9205
9261
|
return httpClient.getSubscriptionSettings({
|
|
9206
9262
|
roomId,
|
|
9207
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
9263
|
+
signal: _optionalChain([options2, 'optionalAccess', _186 => _186.signal])
|
|
9208
9264
|
});
|
|
9209
9265
|
}
|
|
9210
9266
|
function updateSubscriptionSettings(settings) {
|
|
@@ -9219,14 +9275,14 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9219
9275
|
const syncSourceForYjs = config.createSyncSource();
|
|
9220
9276
|
function yjsStatusDidChange(status) {
|
|
9221
9277
|
return syncSourceForYjs.setSyncStatus(
|
|
9222
|
-
status === "synchronizing" ? "synchronizing" : "synchronized"
|
|
9278
|
+
status === "synchronizing" || status === "loading" ? "synchronizing" : "synchronized"
|
|
9223
9279
|
);
|
|
9224
9280
|
}
|
|
9225
9281
|
return Object.defineProperty(
|
|
9226
9282
|
{
|
|
9227
9283
|
[kInternal]: {
|
|
9228
9284
|
get presenceBuffer() {
|
|
9229
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
9285
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _187 => _187.buffer, 'access', _188 => _188.presenceUpdates, 'optionalAccess', _189 => _189.data]), () => ( null)));
|
|
9230
9286
|
},
|
|
9231
9287
|
// prettier-ignore
|
|
9232
9288
|
get undoStack() {
|
|
@@ -9241,9 +9297,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9241
9297
|
return context.yjsProvider;
|
|
9242
9298
|
},
|
|
9243
9299
|
setYjsProvider(newProvider) {
|
|
9244
|
-
_optionalChain([context, 'access',
|
|
9300
|
+
_optionalChain([context, 'access', _190 => _190.yjsProvider, 'optionalAccess', _191 => _191.off, 'call', _192 => _192("status", yjsStatusDidChange)]);
|
|
9245
9301
|
context.yjsProvider = newProvider;
|
|
9246
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
9302
|
+
_optionalChain([newProvider, 'optionalAccess', _193 => _193.on, 'call', _194 => _194("status", yjsStatusDidChange)]);
|
|
9247
9303
|
context.yjsProviderDidChange.notify();
|
|
9248
9304
|
},
|
|
9249
9305
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -9289,7 +9345,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
9289
9345
|
source.dispose();
|
|
9290
9346
|
}
|
|
9291
9347
|
eventHub.roomWillDestroy.notify();
|
|
9292
|
-
_optionalChain([context, 'access',
|
|
9348
|
+
_optionalChain([context, 'access', _195 => _195.yjsProvider, 'optionalAccess', _196 => _196.off, 'call', _197 => _197("status", yjsStatusDidChange)]);
|
|
9293
9349
|
syncSourceForStorage.destroy();
|
|
9294
9350
|
syncSourceForYjs.destroy();
|
|
9295
9351
|
uninstallBgTabSpy();
|
|
@@ -9439,7 +9495,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
9439
9495
|
}
|
|
9440
9496
|
if (isLiveNode(first)) {
|
|
9441
9497
|
const node = first;
|
|
9442
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
9498
|
+
if (_optionalChain([options, 'optionalAccess', _198 => _198.isDeep])) {
|
|
9443
9499
|
const storageCallback = second;
|
|
9444
9500
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
9445
9501
|
} else {
|
|
@@ -9518,8 +9574,8 @@ function createClient(options) {
|
|
|
9518
9574
|
const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
|
|
9519
9575
|
currentUserId.set(() => userId);
|
|
9520
9576
|
});
|
|
9521
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
9522
|
-
_optionalChain([globalThis, 'access',
|
|
9577
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _199 => _199.polyfills, 'optionalAccess', _200 => _200.fetch]) || /* istanbul ignore next */
|
|
9578
|
+
_optionalChain([globalThis, 'access', _201 => _201.fetch, 'optionalAccess', _202 => _202.bind, 'call', _203 => _203(globalThis)]);
|
|
9523
9579
|
const httpClient = createApiClient({
|
|
9524
9580
|
baseUrl,
|
|
9525
9581
|
fetchPolyfill,
|
|
@@ -9537,7 +9593,7 @@ function createClient(options) {
|
|
|
9537
9593
|
delegates: {
|
|
9538
9594
|
createSocket: makeCreateSocketDelegateForAi(
|
|
9539
9595
|
baseUrl,
|
|
9540
|
-
_optionalChain([clientOptions, 'access',
|
|
9596
|
+
_optionalChain([clientOptions, 'access', _204 => _204.polyfills, 'optionalAccess', _205 => _205.WebSocket])
|
|
9541
9597
|
),
|
|
9542
9598
|
authenticate: async () => {
|
|
9543
9599
|
const resp = await authManager.getAuthValue({
|
|
@@ -9605,7 +9661,7 @@ function createClient(options) {
|
|
|
9605
9661
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
9606
9662
|
roomId,
|
|
9607
9663
|
baseUrl,
|
|
9608
|
-
_optionalChain([clientOptions, 'access',
|
|
9664
|
+
_optionalChain([clientOptions, 'access', _206 => _206.polyfills, 'optionalAccess', _207 => _207.WebSocket])
|
|
9609
9665
|
),
|
|
9610
9666
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
9611
9667
|
})),
|
|
@@ -9628,7 +9684,7 @@ function createClient(options) {
|
|
|
9628
9684
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
9629
9685
|
if (shouldConnect) {
|
|
9630
9686
|
if (typeof atob === "undefined") {
|
|
9631
|
-
if (_optionalChain([clientOptions, 'access',
|
|
9687
|
+
if (_optionalChain([clientOptions, 'access', _208 => _208.polyfills, 'optionalAccess', _209 => _209.atob]) === void 0) {
|
|
9632
9688
|
throw new Error(
|
|
9633
9689
|
"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"
|
|
9634
9690
|
);
|
|
@@ -9640,7 +9696,7 @@ function createClient(options) {
|
|
|
9640
9696
|
return leaseRoom(newRoomDetails);
|
|
9641
9697
|
}
|
|
9642
9698
|
function getRoom(roomId) {
|
|
9643
|
-
const room = _optionalChain([roomsById, 'access',
|
|
9699
|
+
const room = _optionalChain([roomsById, 'access', _210 => _210.get, 'call', _211 => _211(roomId), 'optionalAccess', _212 => _212.room]);
|
|
9644
9700
|
return room ? room : null;
|
|
9645
9701
|
}
|
|
9646
9702
|
function logout() {
|
|
@@ -9660,7 +9716,7 @@ function createClient(options) {
|
|
|
9660
9716
|
const batchedResolveUsers = new Batch(
|
|
9661
9717
|
async (batchedUserIds) => {
|
|
9662
9718
|
const userIds = batchedUserIds.flat();
|
|
9663
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
9719
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _213 => _213({ userIds })]);
|
|
9664
9720
|
warnIfNoResolveUsers();
|
|
9665
9721
|
return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
|
|
9666
9722
|
},
|
|
@@ -9678,7 +9734,7 @@ function createClient(options) {
|
|
|
9678
9734
|
const batchedResolveRoomsInfo = new Batch(
|
|
9679
9735
|
async (batchedRoomIds) => {
|
|
9680
9736
|
const roomIds = batchedRoomIds.flat();
|
|
9681
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
9737
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _214 => _214({ roomIds })]);
|
|
9682
9738
|
warnIfNoResolveRoomsInfo();
|
|
9683
9739
|
return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
|
|
9684
9740
|
},
|
|
@@ -9731,7 +9787,7 @@ function createClient(options) {
|
|
|
9731
9787
|
}
|
|
9732
9788
|
};
|
|
9733
9789
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
9734
|
-
_optionalChain([win, 'optionalAccess',
|
|
9790
|
+
_optionalChain([win, 'optionalAccess', _215 => _215.addEventListener, 'call', _216 => _216("beforeunload", maybePreventClose)]);
|
|
9735
9791
|
}
|
|
9736
9792
|
async function getNotificationSettings(options2) {
|
|
9737
9793
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -9870,7 +9926,7 @@ var commentBodyElementsTypes = {
|
|
|
9870
9926
|
mention: "inline"
|
|
9871
9927
|
};
|
|
9872
9928
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
9873
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
9929
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _217 => _217.content])) {
|
|
9874
9930
|
return;
|
|
9875
9931
|
}
|
|
9876
9932
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -9880,13 +9936,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
9880
9936
|
for (const block of body.content) {
|
|
9881
9937
|
if (type === "all" || type === "block") {
|
|
9882
9938
|
if (guard(block)) {
|
|
9883
|
-
_optionalChain([visitor, 'optionalCall',
|
|
9939
|
+
_optionalChain([visitor, 'optionalCall', _218 => _218(block)]);
|
|
9884
9940
|
}
|
|
9885
9941
|
}
|
|
9886
9942
|
if (type === "all" || type === "inline") {
|
|
9887
9943
|
for (const inline of block.children) {
|
|
9888
9944
|
if (guard(inline)) {
|
|
9889
|
-
_optionalChain([visitor, 'optionalCall',
|
|
9945
|
+
_optionalChain([visitor, 'optionalCall', _219 => _219(inline)]);
|
|
9890
9946
|
}
|
|
9891
9947
|
}
|
|
9892
9948
|
}
|
|
@@ -9920,7 +9976,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
|
9920
9976
|
userIds
|
|
9921
9977
|
});
|
|
9922
9978
|
for (const [index, userId] of userIds.entries()) {
|
|
9923
|
-
const user = _optionalChain([users, 'optionalAccess',
|
|
9979
|
+
const user = _optionalChain([users, 'optionalAccess', _220 => _220[index]]);
|
|
9924
9980
|
if (user) {
|
|
9925
9981
|
resolvedUsers.set(userId, user);
|
|
9926
9982
|
}
|
|
@@ -10039,7 +10095,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
10039
10095
|
text: ({ element }) => element.text,
|
|
10040
10096
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
10041
10097
|
mention: ({ element, user }) => {
|
|
10042
|
-
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
10098
|
+
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _221 => _221.name]), () => ( element.id))}`;
|
|
10043
10099
|
}
|
|
10044
10100
|
};
|
|
10045
10101
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -10069,7 +10125,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
10069
10125
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
10070
10126
|
},
|
|
10071
10127
|
mention: ({ element, user }) => {
|
|
10072
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
10128
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _222 => _222.name]) ? html`${_optionalChain([user, 'optionalAccess', _223 => _223.name])}` : element.id}</span>`;
|
|
10073
10129
|
}
|
|
10074
10130
|
};
|
|
10075
10131
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -10099,19 +10155,19 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
10099
10155
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
10100
10156
|
},
|
|
10101
10157
|
mention: ({ element, user }) => {
|
|
10102
|
-
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
10158
|
+
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _224 => _224.name]), () => ( element.id))}`;
|
|
10103
10159
|
}
|
|
10104
10160
|
};
|
|
10105
10161
|
async function stringifyCommentBody(body, options) {
|
|
10106
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
10107
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
10162
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _225 => _225.format]), () => ( "plain"));
|
|
10163
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _226 => _226.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
10108
10164
|
const elements = {
|
|
10109
10165
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
10110
|
-
..._optionalChain([options, 'optionalAccess',
|
|
10166
|
+
..._optionalChain([options, 'optionalAccess', _227 => _227.elements])
|
|
10111
10167
|
};
|
|
10112
10168
|
const resolvedUsers = await resolveUsersInCommentBody(
|
|
10113
10169
|
body,
|
|
10114
|
-
_optionalChain([options, 'optionalAccess',
|
|
10170
|
+
_optionalChain([options, 'optionalAccess', _228 => _228.resolveUsers])
|
|
10115
10171
|
);
|
|
10116
10172
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
10117
10173
|
switch (block.type) {
|
|
@@ -10397,12 +10453,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
10397
10453
|
}
|
|
10398
10454
|
const newState = Object.assign({}, state);
|
|
10399
10455
|
for (const key in update.updates) {
|
|
10400
|
-
if (_optionalChain([update, 'access',
|
|
10456
|
+
if (_optionalChain([update, 'access', _229 => _229.updates, 'access', _230 => _230[key], 'optionalAccess', _231 => _231.type]) === "update") {
|
|
10401
10457
|
const val = update.node.get(key);
|
|
10402
10458
|
if (val !== void 0) {
|
|
10403
10459
|
newState[key] = lsonToJson(val);
|
|
10404
10460
|
}
|
|
10405
|
-
} else if (_optionalChain([update, 'access',
|
|
10461
|
+
} else if (_optionalChain([update, 'access', _232 => _232.updates, 'access', _233 => _233[key], 'optionalAccess', _234 => _234.type]) === "delete") {
|
|
10406
10462
|
delete newState[key];
|
|
10407
10463
|
}
|
|
10408
10464
|
}
|
|
@@ -10463,12 +10519,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
10463
10519
|
}
|
|
10464
10520
|
const newState = Object.assign({}, state);
|
|
10465
10521
|
for (const key in update.updates) {
|
|
10466
|
-
if (_optionalChain([update, 'access',
|
|
10522
|
+
if (_optionalChain([update, 'access', _235 => _235.updates, 'access', _236 => _236[key], 'optionalAccess', _237 => _237.type]) === "update") {
|
|
10467
10523
|
const value = update.node.get(key);
|
|
10468
10524
|
if (value !== void 0) {
|
|
10469
10525
|
newState[key] = lsonToJson(value);
|
|
10470
10526
|
}
|
|
10471
|
-
} else if (_optionalChain([update, 'access',
|
|
10527
|
+
} else if (_optionalChain([update, 'access', _238 => _238.updates, 'access', _239 => _239[key], 'optionalAccess', _240 => _240.type]) === "delete") {
|
|
10472
10528
|
delete newState[key];
|
|
10473
10529
|
}
|
|
10474
10530
|
}
|
|
@@ -10548,9 +10604,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
10548
10604
|
const startTime = performance.now();
|
|
10549
10605
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
10550
10606
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
10551
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
10607
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _241 => _241.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
10552
10608
|
const context = {
|
|
10553
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
10609
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _242 => _242.visibilityState]) !== "hidden",
|
|
10554
10610
|
lastSuccessfulPollAt: startTime,
|
|
10555
10611
|
count: 0,
|
|
10556
10612
|
backoff: 0
|
|
@@ -10631,11 +10687,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
10631
10687
|
pollNowIfStale();
|
|
10632
10688
|
}
|
|
10633
10689
|
function onVisibilityChange() {
|
|
10634
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
10690
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _243 => _243.visibilityState]) !== "hidden");
|
|
10635
10691
|
}
|
|
10636
|
-
_optionalChain([doc, 'optionalAccess',
|
|
10637
|
-
_optionalChain([win, 'optionalAccess',
|
|
10638
|
-
_optionalChain([win, 'optionalAccess',
|
|
10692
|
+
_optionalChain([doc, 'optionalAccess', _244 => _244.addEventListener, 'call', _245 => _245("visibilitychange", onVisibilityChange)]);
|
|
10693
|
+
_optionalChain([win, 'optionalAccess', _246 => _246.addEventListener, 'call', _247 => _247("online", onVisibilityChange)]);
|
|
10694
|
+
_optionalChain([win, 'optionalAccess', _248 => _248.addEventListener, 'call', _249 => _249("focus", pollNowIfStale)]);
|
|
10639
10695
|
fsm.start();
|
|
10640
10696
|
return {
|
|
10641
10697
|
inc,
|