@liveblocks/core 2.13.3-emails1 → 2.14.0-v2encoding
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 +23 -16
- package/dist/index.d.ts +23 -16
- package/dist/index.js +909 -691
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +859 -641
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;var __defProp = Object.defineProperty;
|
|
2
2
|
var __export = (target, all) => {
|
|
3
3
|
for (var name in all)
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -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.
|
|
9
|
+
var PKG_VERSION = "2.14.0-v2encoding";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -304,19 +304,6 @@ function Promise_withResolvers() {
|
|
|
304
304
|
// src/lib/EventSource.ts
|
|
305
305
|
function makeEventSource() {
|
|
306
306
|
const _observers = /* @__PURE__ */ new Set();
|
|
307
|
-
let _buffer = null;
|
|
308
|
-
function pause() {
|
|
309
|
-
_buffer = [];
|
|
310
|
-
}
|
|
311
|
-
function unpause() {
|
|
312
|
-
if (_buffer === null) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
for (const event of _buffer) {
|
|
316
|
-
notify(event);
|
|
317
|
-
}
|
|
318
|
-
_buffer = null;
|
|
319
|
-
}
|
|
320
307
|
function subscribe(callback) {
|
|
321
308
|
_observers.add(callback);
|
|
322
309
|
return () => _observers.delete(callback);
|
|
@@ -338,32 +325,22 @@ function makeEventSource() {
|
|
|
338
325
|
});
|
|
339
326
|
}).finally(() => _optionalChain([unsub, 'optionalCall', _2 => _2()]));
|
|
340
327
|
}
|
|
341
|
-
function notifyOrBuffer(event) {
|
|
342
|
-
if (_buffer !== null) {
|
|
343
|
-
_buffer.push(event);
|
|
344
|
-
} else {
|
|
345
|
-
notify(event);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
328
|
function notify(event) {
|
|
349
329
|
_observers.forEach((callback) => callback(event));
|
|
350
330
|
}
|
|
351
|
-
function _forceClear() {
|
|
352
|
-
_observers.clear();
|
|
353
|
-
}
|
|
354
331
|
function count() {
|
|
355
332
|
return _observers.size;
|
|
356
333
|
}
|
|
357
334
|
return {
|
|
358
335
|
// Private/internal control over event emission
|
|
359
|
-
notify
|
|
336
|
+
notify,
|
|
360
337
|
subscribe,
|
|
361
338
|
subscribeOnce,
|
|
362
|
-
_forceClear,
|
|
363
339
|
count,
|
|
364
340
|
waitUntil,
|
|
365
|
-
|
|
366
|
-
|
|
341
|
+
[Symbol.dispose]: () => {
|
|
342
|
+
_observers.clear();
|
|
343
|
+
},
|
|
367
344
|
// Publicly exposable subscription API
|
|
368
345
|
observable: {
|
|
369
346
|
subscribe,
|
|
@@ -372,6 +349,41 @@ function makeEventSource() {
|
|
|
372
349
|
}
|
|
373
350
|
};
|
|
374
351
|
}
|
|
352
|
+
function makeBufferableEventSource() {
|
|
353
|
+
const eventSource2 = makeEventSource();
|
|
354
|
+
let _buffer = null;
|
|
355
|
+
function pause() {
|
|
356
|
+
_buffer = [];
|
|
357
|
+
}
|
|
358
|
+
function unpause() {
|
|
359
|
+
if (_buffer === null) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
for (const event of _buffer) {
|
|
363
|
+
eventSource2.notify(event);
|
|
364
|
+
}
|
|
365
|
+
_buffer = null;
|
|
366
|
+
}
|
|
367
|
+
function notifyOrBuffer(event) {
|
|
368
|
+
if (_buffer !== null) {
|
|
369
|
+
_buffer.push(event);
|
|
370
|
+
} else {
|
|
371
|
+
eventSource2.notify(event);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
...eventSource2,
|
|
376
|
+
notify: notifyOrBuffer,
|
|
377
|
+
pause,
|
|
378
|
+
unpause,
|
|
379
|
+
[Symbol.dispose]: () => {
|
|
380
|
+
eventSource2[Symbol.dispose]();
|
|
381
|
+
if (_buffer !== null) {
|
|
382
|
+
_buffer.length = 0;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
375
387
|
|
|
376
388
|
// src/lib/stringify.ts
|
|
377
389
|
function stringify(object, ...args) {
|
|
@@ -391,6 +403,10 @@ function stringify(object, ...args) {
|
|
|
391
403
|
// src/lib/batch.ts
|
|
392
404
|
var DEFAULT_SIZE = 50;
|
|
393
405
|
var BatchCall = class {
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
394
410
|
constructor(input) {
|
|
395
411
|
this.input = input;
|
|
396
412
|
const { promise, resolve, reject } = Promise_withResolvers();
|
|
@@ -399,36 +415,40 @@ var BatchCall = class {
|
|
|
399
415
|
this.reject = reject;
|
|
400
416
|
}
|
|
401
417
|
};
|
|
402
|
-
var Batch = class {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
418
|
+
var Batch = (_class = class {
|
|
419
|
+
#queue = [];
|
|
420
|
+
#callback;
|
|
421
|
+
#size;
|
|
422
|
+
#delay;
|
|
423
|
+
#delayTimeoutId;
|
|
424
|
+
__init() {this.error = false}
|
|
425
|
+
constructor(callback, options) {;_class.prototype.__init.call(this);
|
|
426
|
+
this.#callback = callback;
|
|
427
|
+
this.#size = _nullishCoalesce(options.size, () => ( DEFAULT_SIZE));
|
|
428
|
+
this.#delay = options.delay;
|
|
429
|
+
}
|
|
430
|
+
#clearDelayTimeout() {
|
|
431
|
+
if (this.#delayTimeoutId !== void 0) {
|
|
432
|
+
clearTimeout(this.#delayTimeoutId);
|
|
433
|
+
this.#delayTimeoutId = void 0;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
#schedule() {
|
|
437
|
+
if (this.#queue.length === this.#size) {
|
|
438
|
+
void this.#flush();
|
|
439
|
+
} else if (this.#queue.length === 1) {
|
|
440
|
+
this.#clearDelayTimeout();
|
|
441
|
+
this.#delayTimeoutId = setTimeout(() => void this.#flush(), this.#delay);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async #flush() {
|
|
445
|
+
if (this.#queue.length === 0) {
|
|
426
446
|
return;
|
|
427
447
|
}
|
|
428
|
-
const calls = this
|
|
448
|
+
const calls = this.#queue.splice(0);
|
|
429
449
|
const inputs = calls.map((call) => call.input);
|
|
430
450
|
try {
|
|
431
|
-
const results = await this
|
|
451
|
+
const results = await this.#callback(inputs);
|
|
432
452
|
this.error = false;
|
|
433
453
|
calls.forEach((call, index) => {
|
|
434
454
|
const result = _optionalChain([results, 'optionalAccess', _3 => _3[index]]);
|
|
@@ -454,24 +474,24 @@ var Batch = class {
|
|
|
454
474
|
}
|
|
455
475
|
}
|
|
456
476
|
get(input) {
|
|
457
|
-
const existingCall = this
|
|
477
|
+
const existingCall = this.#queue.find(
|
|
458
478
|
(call2) => stringify(call2.input) === stringify(input)
|
|
459
479
|
);
|
|
460
480
|
if (existingCall) {
|
|
461
481
|
return existingCall.promise;
|
|
462
482
|
}
|
|
463
483
|
const call = new BatchCall(input);
|
|
464
|
-
this
|
|
465
|
-
this
|
|
484
|
+
this.#queue.push(call);
|
|
485
|
+
this.#schedule();
|
|
466
486
|
return call.promise;
|
|
467
487
|
}
|
|
468
488
|
clear() {
|
|
469
|
-
this
|
|
489
|
+
this.#queue = [];
|
|
470
490
|
this.error = false;
|
|
471
|
-
this
|
|
491
|
+
this.#clearDelayTimeout();
|
|
472
492
|
}
|
|
473
|
-
};
|
|
474
|
-
function createBatchStore(
|
|
493
|
+
}, _class);
|
|
494
|
+
function createBatchStore(batch2) {
|
|
475
495
|
const cache = /* @__PURE__ */ new Map();
|
|
476
496
|
const eventSource2 = makeEventSource();
|
|
477
497
|
function getCacheKey(args) {
|
|
@@ -498,7 +518,7 @@ function createBatchStore(batch) {
|
|
|
498
518
|
}
|
|
499
519
|
try {
|
|
500
520
|
setStateAndNotify(cacheKey, { isLoading: true });
|
|
501
|
-
const result = await
|
|
521
|
+
const result = await batch2.get(input);
|
|
502
522
|
setStateAndNotify(cacheKey, { isLoading: false, data: result });
|
|
503
523
|
} catch (error3) {
|
|
504
524
|
setStateAndNotify(cacheKey, {
|
|
@@ -515,7 +535,7 @@ function createBatchStore(batch) {
|
|
|
515
535
|
return [...cache.keys()];
|
|
516
536
|
}
|
|
517
537
|
function getBatch() {
|
|
518
|
-
return
|
|
538
|
+
return batch2;
|
|
519
539
|
}
|
|
520
540
|
return {
|
|
521
541
|
...eventSource2.observable,
|
|
@@ -1067,7 +1087,7 @@ function createApiClient({
|
|
|
1067
1087
|
function getOrCreateAttachmentUrlsStore(roomId) {
|
|
1068
1088
|
let store = getAttachmentUrlsBatchStoreByRoom.get(roomId);
|
|
1069
1089
|
if (store === void 0) {
|
|
1070
|
-
const
|
|
1090
|
+
const batch2 = new Batch(
|
|
1071
1091
|
async (batchedAttachmentIds) => {
|
|
1072
1092
|
const attachmentIds = batchedAttachmentIds.flat();
|
|
1073
1093
|
const { urls } = await httpClient.post(
|
|
@@ -1090,14 +1110,14 @@ function createApiClient({
|
|
|
1090
1110
|
delay: 50
|
|
1091
1111
|
}
|
|
1092
1112
|
);
|
|
1093
|
-
store = createBatchStore(
|
|
1113
|
+
store = createBatchStore(batch2);
|
|
1094
1114
|
getAttachmentUrlsBatchStoreByRoom.set(roomId, store);
|
|
1095
1115
|
}
|
|
1096
1116
|
return store;
|
|
1097
1117
|
}
|
|
1098
1118
|
function getAttachmentUrl(options) {
|
|
1099
|
-
const
|
|
1100
|
-
return
|
|
1119
|
+
const batch2 = getOrCreateAttachmentUrlsStore(options.roomId).getBatch();
|
|
1120
|
+
return batch2.get(options.attachmentId);
|
|
1101
1121
|
}
|
|
1102
1122
|
async function getNotificationSettings(options) {
|
|
1103
1123
|
return httpClient.get(
|
|
@@ -1124,9 +1144,9 @@ function createApiClient({
|
|
|
1124
1144
|
}
|
|
1125
1145
|
const markInboxNotificationsAsReadBatchByRoom = /* @__PURE__ */ new Map();
|
|
1126
1146
|
function getOrCreateMarkInboxNotificationsAsReadBatch(roomId) {
|
|
1127
|
-
let
|
|
1128
|
-
if (
|
|
1129
|
-
|
|
1147
|
+
let batch2 = markInboxNotificationsAsReadBatchByRoom.get(roomId);
|
|
1148
|
+
if (batch2 === void 0) {
|
|
1149
|
+
batch2 = new Batch(
|
|
1130
1150
|
async (batchedInboxNotificationIds) => {
|
|
1131
1151
|
const inboxNotificationIds = batchedInboxNotificationIds.flat();
|
|
1132
1152
|
await httpClient.post(
|
|
@@ -1143,13 +1163,13 @@ function createApiClient({
|
|
|
1143
1163
|
delay: 50
|
|
1144
1164
|
}
|
|
1145
1165
|
);
|
|
1146
|
-
markInboxNotificationsAsReadBatchByRoom.set(roomId,
|
|
1166
|
+
markInboxNotificationsAsReadBatchByRoom.set(roomId, batch2);
|
|
1147
1167
|
}
|
|
1148
|
-
return
|
|
1168
|
+
return batch2;
|
|
1149
1169
|
}
|
|
1150
1170
|
async function markRoomInboxNotificationAsRead(options) {
|
|
1151
|
-
const
|
|
1152
|
-
return
|
|
1171
|
+
const batch2 = getOrCreateMarkInboxNotificationsAsReadBatch(options.roomId);
|
|
1172
|
+
return batch2.get(options.inboxNotificationId);
|
|
1153
1173
|
}
|
|
1154
1174
|
async function createTextMention(options) {
|
|
1155
1175
|
await httpClient.rawPost(
|
|
@@ -1455,9 +1475,11 @@ function getBearerTokenFromAuthValue(authValue) {
|
|
|
1455
1475
|
}
|
|
1456
1476
|
}
|
|
1457
1477
|
var HttpClient = class {
|
|
1478
|
+
#baseUrl;
|
|
1479
|
+
#fetchPolyfill;
|
|
1458
1480
|
constructor(baseUrl, fetchPolyfill) {
|
|
1459
|
-
this
|
|
1460
|
-
this
|
|
1481
|
+
this.#baseUrl = baseUrl;
|
|
1482
|
+
this.#fetchPolyfill = fetchPolyfill;
|
|
1461
1483
|
}
|
|
1462
1484
|
// ------------------------------------------------------------------
|
|
1463
1485
|
// Public methods
|
|
@@ -1475,12 +1497,12 @@ var HttpClient = class {
|
|
|
1475
1497
|
* 5. ...but silently return `{}` if that parsing fails
|
|
1476
1498
|
* 6. Throw HttpError if response is an error
|
|
1477
1499
|
*/
|
|
1478
|
-
async rawFetch(endpoint, authValue, options, params) {
|
|
1500
|
+
async #rawFetch(endpoint, authValue, options, params) {
|
|
1479
1501
|
if (!endpoint.startsWith("/v2/c/")) {
|
|
1480
1502
|
raise("This client can only be used to make /v2/c/* requests");
|
|
1481
1503
|
}
|
|
1482
|
-
const url2 = urljoin(this
|
|
1483
|
-
return await this
|
|
1504
|
+
const url2 = urljoin(this.#baseUrl, endpoint, params);
|
|
1505
|
+
return await this.#fetchPolyfill(url2, {
|
|
1484
1506
|
...options,
|
|
1485
1507
|
headers: {
|
|
1486
1508
|
// These headers are default, but can be overriden by custom headers
|
|
@@ -1507,8 +1529,8 @@ var HttpClient = class {
|
|
|
1507
1529
|
* 5. ...but silently return `{}` if that parsing fails (🤔)
|
|
1508
1530
|
* 6. Throw HttpError if response is an error
|
|
1509
1531
|
*/
|
|
1510
|
-
async fetch(endpoint, authValue, options, params) {
|
|
1511
|
-
const response = await this
|
|
1532
|
+
async #fetch(endpoint, authValue, options, params) {
|
|
1533
|
+
const response = await this.#rawFetch(endpoint, authValue, options, params);
|
|
1512
1534
|
if (!response.ok) {
|
|
1513
1535
|
let error3;
|
|
1514
1536
|
try {
|
|
@@ -1533,7 +1555,7 @@ var HttpClient = class {
|
|
|
1533
1555
|
* @deprecated Ideally, use .get() instead.
|
|
1534
1556
|
*/
|
|
1535
1557
|
async rawGet(endpoint, authValue, params, options) {
|
|
1536
|
-
return await this
|
|
1558
|
+
return await this.#rawFetch(endpoint, authValue, options, params);
|
|
1537
1559
|
}
|
|
1538
1560
|
/**
|
|
1539
1561
|
* Makes a POST request and returns the raw response.
|
|
@@ -1541,7 +1563,7 @@ var HttpClient = class {
|
|
|
1541
1563
|
* @deprecated Ideally, use .post() instead.
|
|
1542
1564
|
*/
|
|
1543
1565
|
async rawPost(endpoint, authValue, body) {
|
|
1544
|
-
return await this
|
|
1566
|
+
return await this.#rawFetch(endpoint, authValue, {
|
|
1545
1567
|
method: "POST",
|
|
1546
1568
|
body: JSON.stringify(body)
|
|
1547
1569
|
});
|
|
@@ -1552,21 +1574,21 @@ var HttpClient = class {
|
|
|
1552
1574
|
* @deprecated Ideally, use .delete() instead.
|
|
1553
1575
|
*/
|
|
1554
1576
|
async rawDelete(endpoint, authValue) {
|
|
1555
|
-
return await this
|
|
1577
|
+
return await this.#rawFetch(endpoint, authValue, { method: "DELETE" });
|
|
1556
1578
|
}
|
|
1557
1579
|
/**
|
|
1558
1580
|
* Makes a GET request, and return the JSON response.
|
|
1559
1581
|
* Will throw if the reponse is a non-2xx.
|
|
1560
1582
|
*/
|
|
1561
1583
|
async get(endpoint, authValue, params, options) {
|
|
1562
|
-
return await this
|
|
1584
|
+
return await this.#fetch(endpoint, authValue, options, params);
|
|
1563
1585
|
}
|
|
1564
1586
|
/**
|
|
1565
1587
|
* Makes a POST request, and return the JSON response.
|
|
1566
1588
|
* Will throw if the reponse is a non-2xx.
|
|
1567
1589
|
*/
|
|
1568
1590
|
async post(endpoint, authValue, body, options, params) {
|
|
1569
|
-
return await this
|
|
1591
|
+
return await this.#fetch(
|
|
1570
1592
|
endpoint,
|
|
1571
1593
|
authValue,
|
|
1572
1594
|
{
|
|
@@ -1582,14 +1604,14 @@ var HttpClient = class {
|
|
|
1582
1604
|
* Will throw if the reponse is a non-2xx.
|
|
1583
1605
|
*/
|
|
1584
1606
|
async delete(endpoint, authValue) {
|
|
1585
|
-
return await this
|
|
1607
|
+
return await this.#fetch(endpoint, authValue, { method: "DELETE" });
|
|
1586
1608
|
}
|
|
1587
1609
|
/**
|
|
1588
1610
|
* Makes a PUT request for a Blob body, and return the JSON response.
|
|
1589
1611
|
* Will throw if the reponse is a non-2xx.
|
|
1590
1612
|
*/
|
|
1591
1613
|
async putBlob(endpoint, authValue, blob, params, options) {
|
|
1592
|
-
return await this
|
|
1614
|
+
return await this.#fetch(
|
|
1593
1615
|
endpoint,
|
|
1594
1616
|
authValue,
|
|
1595
1617
|
{
|
|
@@ -1660,11 +1682,12 @@ function patterns(targetState, levels) {
|
|
|
1660
1682
|
return result;
|
|
1661
1683
|
}
|
|
1662
1684
|
var SafeContext = class {
|
|
1685
|
+
#curr;
|
|
1663
1686
|
constructor(initialContext) {
|
|
1664
|
-
this
|
|
1687
|
+
this.#curr = initialContext;
|
|
1665
1688
|
}
|
|
1666
1689
|
get current() {
|
|
1667
|
-
return this
|
|
1690
|
+
return this.#curr;
|
|
1668
1691
|
}
|
|
1669
1692
|
/**
|
|
1670
1693
|
* Call a callback function that allows patching of the context, by
|
|
@@ -1675,10 +1698,10 @@ var SafeContext = class {
|
|
|
1675
1698
|
const self = this;
|
|
1676
1699
|
let allowed = true;
|
|
1677
1700
|
const patchableContext = {
|
|
1678
|
-
...this
|
|
1701
|
+
...this.#curr,
|
|
1679
1702
|
patch(patch) {
|
|
1680
1703
|
if (allowed) {
|
|
1681
|
-
self
|
|
1704
|
+
self.#curr = Object.assign({}, self.#curr, patch);
|
|
1682
1705
|
for (const pair of Object.entries(patch)) {
|
|
1683
1706
|
const [key, value] = pair;
|
|
1684
1707
|
if (key !== "patch") {
|
|
@@ -1697,12 +1720,42 @@ var SafeContext = class {
|
|
|
1697
1720
|
};
|
|
1698
1721
|
var nextId = 1;
|
|
1699
1722
|
var FSM = class {
|
|
1723
|
+
|
|
1724
|
+
// Indicates whether this state machine is still being configured, has
|
|
1725
|
+
// started, or has terminated
|
|
1726
|
+
#runningState;
|
|
1727
|
+
#currentContext;
|
|
1728
|
+
#states;
|
|
1729
|
+
#currentStateOrNull;
|
|
1730
|
+
#allowedTransitions;
|
|
1731
|
+
#eventHub;
|
|
1732
|
+
|
|
1733
|
+
//
|
|
1734
|
+
// The cleanup stack is a stack of (optional) callback functions that will
|
|
1735
|
+
// be run when exiting the current state. If a state (or state group) does
|
|
1736
|
+
// not have an exit handler, then the entry for that level may be
|
|
1737
|
+
// `undefined`, but there will be an explicit entry in the stack for it.
|
|
1738
|
+
//
|
|
1739
|
+
// This will always be true:
|
|
1740
|
+
//
|
|
1741
|
+
// cleanupStack.length == currentState.split('.').length + 1
|
|
1742
|
+
//
|
|
1743
|
+
// Each stack level represents a different state "group".
|
|
1744
|
+
//
|
|
1745
|
+
// For example, if you are in a state named `foo.bar.qux`, then the stack
|
|
1746
|
+
// will contain the exit handler for `foo.bar.qux` (at the top), then
|
|
1747
|
+
// `foo.bar.*`, then `foo.*`, and finally, `*`.
|
|
1748
|
+
//
|
|
1749
|
+
#cleanupStack;
|
|
1750
|
+
#enterFns;
|
|
1751
|
+
// Used to provide better error messages
|
|
1752
|
+
#knownEventTypes;
|
|
1700
1753
|
/**
|
|
1701
1754
|
* Returns the initial state, which is defined by the first call made to
|
|
1702
1755
|
* .addState().
|
|
1703
1756
|
*/
|
|
1704
|
-
get initialState() {
|
|
1705
|
-
const result = this
|
|
1757
|
+
get #initialState() {
|
|
1758
|
+
const result = this.#states.values()[Symbol.iterator]().next();
|
|
1706
1759
|
if (result.done) {
|
|
1707
1760
|
throw new Error("No states defined yet");
|
|
1708
1761
|
} else {
|
|
@@ -1710,25 +1763,25 @@ var FSM = class {
|
|
|
1710
1763
|
}
|
|
1711
1764
|
}
|
|
1712
1765
|
get currentState() {
|
|
1713
|
-
if (this
|
|
1714
|
-
if (this
|
|
1766
|
+
if (this.#currentStateOrNull === null) {
|
|
1767
|
+
if (this.#runningState === 0 /* NOT_STARTED_YET */) {
|
|
1715
1768
|
throw new Error("Not started yet");
|
|
1716
1769
|
} else {
|
|
1717
1770
|
throw new Error("Already stopped");
|
|
1718
1771
|
}
|
|
1719
1772
|
}
|
|
1720
|
-
return this
|
|
1773
|
+
return this.#currentStateOrNull;
|
|
1721
1774
|
}
|
|
1722
1775
|
/**
|
|
1723
1776
|
* Starts the machine by entering the initial state.
|
|
1724
1777
|
*/
|
|
1725
1778
|
start() {
|
|
1726
|
-
if (this
|
|
1779
|
+
if (this.#runningState !== 0 /* NOT_STARTED_YET */) {
|
|
1727
1780
|
throw new Error("State machine has already started");
|
|
1728
1781
|
}
|
|
1729
|
-
this
|
|
1730
|
-
this
|
|
1731
|
-
this
|
|
1782
|
+
this.#runningState = 1 /* STARTED */;
|
|
1783
|
+
this.#currentStateOrNull = this.#initialState;
|
|
1784
|
+
this.#enter(null);
|
|
1732
1785
|
return this;
|
|
1733
1786
|
}
|
|
1734
1787
|
/**
|
|
@@ -1736,24 +1789,24 @@ var FSM = class {
|
|
|
1736
1789
|
* handlers for the current state, but not enter a new state.
|
|
1737
1790
|
*/
|
|
1738
1791
|
stop() {
|
|
1739
|
-
if (this
|
|
1792
|
+
if (this.#runningState !== 1 /* STARTED */) {
|
|
1740
1793
|
throw new Error("Cannot stop a state machine that hasn't started yet");
|
|
1741
1794
|
}
|
|
1742
|
-
this
|
|
1743
|
-
this
|
|
1744
|
-
this
|
|
1795
|
+
this.#exit(null);
|
|
1796
|
+
this.#runningState = 2 /* STOPPED */;
|
|
1797
|
+
this.#currentStateOrNull = null;
|
|
1745
1798
|
}
|
|
1746
1799
|
constructor(initialContext) {
|
|
1747
1800
|
this.id = nextId++;
|
|
1748
|
-
this
|
|
1749
|
-
this
|
|
1750
|
-
this
|
|
1751
|
-
this
|
|
1752
|
-
this
|
|
1753
|
-
this
|
|
1754
|
-
this
|
|
1755
|
-
this
|
|
1756
|
-
this
|
|
1801
|
+
this.#runningState = 0 /* NOT_STARTED_YET */;
|
|
1802
|
+
this.#currentStateOrNull = null;
|
|
1803
|
+
this.#states = /* @__PURE__ */ new Set();
|
|
1804
|
+
this.#enterFns = /* @__PURE__ */ new Map();
|
|
1805
|
+
this.#cleanupStack = [];
|
|
1806
|
+
this.#knownEventTypes = /* @__PURE__ */ new Set();
|
|
1807
|
+
this.#allowedTransitions = /* @__PURE__ */ new Map();
|
|
1808
|
+
this.#currentContext = new SafeContext(initialContext);
|
|
1809
|
+
this.#eventHub = {
|
|
1757
1810
|
didReceiveEvent: makeEventSource(),
|
|
1758
1811
|
willTransition: makeEventSource(),
|
|
1759
1812
|
didIgnoreEvent: makeEventSource(),
|
|
@@ -1761,30 +1814,30 @@ var FSM = class {
|
|
|
1761
1814
|
didEnterState: makeEventSource()
|
|
1762
1815
|
};
|
|
1763
1816
|
this.events = {
|
|
1764
|
-
didReceiveEvent: this
|
|
1765
|
-
willTransition: this
|
|
1766
|
-
didIgnoreEvent: this
|
|
1767
|
-
willExitState: this
|
|
1768
|
-
didEnterState: this
|
|
1817
|
+
didReceiveEvent: this.#eventHub.didReceiveEvent.observable,
|
|
1818
|
+
willTransition: this.#eventHub.willTransition.observable,
|
|
1819
|
+
didIgnoreEvent: this.#eventHub.didIgnoreEvent.observable,
|
|
1820
|
+
willExitState: this.#eventHub.willExitState.observable,
|
|
1821
|
+
didEnterState: this.#eventHub.didEnterState.observable
|
|
1769
1822
|
};
|
|
1770
1823
|
}
|
|
1771
1824
|
get context() {
|
|
1772
|
-
return this
|
|
1825
|
+
return this.#currentContext.current;
|
|
1773
1826
|
}
|
|
1774
1827
|
/**
|
|
1775
1828
|
* Define an explicit finite state in the state machine.
|
|
1776
1829
|
*/
|
|
1777
1830
|
addState(state) {
|
|
1778
|
-
if (this
|
|
1831
|
+
if (this.#runningState !== 0 /* NOT_STARTED_YET */) {
|
|
1779
1832
|
throw new Error("Already started");
|
|
1780
1833
|
}
|
|
1781
|
-
this
|
|
1834
|
+
this.#states.add(state);
|
|
1782
1835
|
return this;
|
|
1783
1836
|
}
|
|
1784
1837
|
onEnter(nameOrPattern, enterFn) {
|
|
1785
|
-
if (this
|
|
1838
|
+
if (this.#runningState !== 0 /* NOT_STARTED_YET */) {
|
|
1786
1839
|
throw new Error("Already started");
|
|
1787
|
-
} else if (this
|
|
1840
|
+
} else if (this.#enterFns.has(nameOrPattern)) {
|
|
1788
1841
|
throw new Error(
|
|
1789
1842
|
// TODO We _currently_ don't support multiple .onEnters() for the same
|
|
1790
1843
|
// state, but this is not a fundamental limitation. Just not
|
|
@@ -1792,7 +1845,7 @@ var FSM = class {
|
|
|
1792
1845
|
`enter/exit function for ${nameOrPattern} already exists`
|
|
1793
1846
|
);
|
|
1794
1847
|
}
|
|
1795
|
-
this
|
|
1848
|
+
this.#enterFns.set(nameOrPattern, enterFn);
|
|
1796
1849
|
return this;
|
|
1797
1850
|
}
|
|
1798
1851
|
/**
|
|
@@ -1826,22 +1879,22 @@ var FSM = class {
|
|
|
1826
1879
|
const signal = abortController.signal;
|
|
1827
1880
|
const timeoutId = maxTimeout ? setTimeout(() => {
|
|
1828
1881
|
const reason = new Error("Timed out");
|
|
1829
|
-
this
|
|
1882
|
+
this.#transition({ type: "ASYNC_ERROR", reason }, onError);
|
|
1830
1883
|
}, maxTimeout) : void 0;
|
|
1831
1884
|
let done = false;
|
|
1832
|
-
void promiseFn(this
|
|
1885
|
+
void promiseFn(this.#currentContext.current, signal).then(
|
|
1833
1886
|
// On OK
|
|
1834
1887
|
(data) => {
|
|
1835
1888
|
if (!signal.aborted) {
|
|
1836
1889
|
done = true;
|
|
1837
|
-
this
|
|
1890
|
+
this.#transition({ type: "ASYNC_OK", data }, onOK);
|
|
1838
1891
|
}
|
|
1839
1892
|
},
|
|
1840
1893
|
// On Error
|
|
1841
1894
|
(reason) => {
|
|
1842
1895
|
if (!signal.aborted) {
|
|
1843
1896
|
done = true;
|
|
1844
|
-
this
|
|
1897
|
+
this.#transition({ type: "ASYNC_ERROR", reason }, onError);
|
|
1845
1898
|
}
|
|
1846
1899
|
}
|
|
1847
1900
|
);
|
|
@@ -1853,22 +1906,22 @@ var FSM = class {
|
|
|
1853
1906
|
};
|
|
1854
1907
|
});
|
|
1855
1908
|
}
|
|
1856
|
-
getStatesMatching(nameOrPattern) {
|
|
1909
|
+
#getStatesMatching(nameOrPattern) {
|
|
1857
1910
|
const matches = [];
|
|
1858
1911
|
if (nameOrPattern === "*") {
|
|
1859
|
-
for (const state of this
|
|
1912
|
+
for (const state of this.#states) {
|
|
1860
1913
|
matches.push(state);
|
|
1861
1914
|
}
|
|
1862
1915
|
} else if (nameOrPattern.endsWith(".*")) {
|
|
1863
1916
|
const prefix = nameOrPattern.slice(0, -1);
|
|
1864
|
-
for (const state of this
|
|
1917
|
+
for (const state of this.#states) {
|
|
1865
1918
|
if (state.startsWith(prefix)) {
|
|
1866
1919
|
matches.push(state);
|
|
1867
1920
|
}
|
|
1868
1921
|
}
|
|
1869
1922
|
} else {
|
|
1870
1923
|
const name = nameOrPattern;
|
|
1871
|
-
if (this
|
|
1924
|
+
if (this.#states.has(name)) {
|
|
1872
1925
|
matches.push(name);
|
|
1873
1926
|
}
|
|
1874
1927
|
}
|
|
@@ -1890,14 +1943,14 @@ var FSM = class {
|
|
|
1890
1943
|
* such events will get ignored.
|
|
1891
1944
|
*/
|
|
1892
1945
|
addTransitions(nameOrPattern, mapping) {
|
|
1893
|
-
if (this
|
|
1946
|
+
if (this.#runningState !== 0 /* NOT_STARTED_YET */) {
|
|
1894
1947
|
throw new Error("Already started");
|
|
1895
1948
|
}
|
|
1896
|
-
for (const srcState of this
|
|
1897
|
-
let map = this
|
|
1949
|
+
for (const srcState of this.#getStatesMatching(nameOrPattern)) {
|
|
1950
|
+
let map = this.#allowedTransitions.get(srcState);
|
|
1898
1951
|
if (map === void 0) {
|
|
1899
1952
|
map = /* @__PURE__ */ new Map();
|
|
1900
|
-
this
|
|
1953
|
+
this.#allowedTransitions.set(srcState, map);
|
|
1901
1954
|
}
|
|
1902
1955
|
for (const [type, target_] of Object.entries(mapping)) {
|
|
1903
1956
|
if (map.has(type)) {
|
|
@@ -1906,7 +1959,7 @@ var FSM = class {
|
|
|
1906
1959
|
);
|
|
1907
1960
|
}
|
|
1908
1961
|
const target = target_;
|
|
1909
|
-
this
|
|
1962
|
+
this.#knownEventTypes.add(type);
|
|
1910
1963
|
if (target !== void 0) {
|
|
1911
1964
|
const targetFn = typeof target === "function" ? target : () => target;
|
|
1912
1965
|
map.set(type, targetFn);
|
|
@@ -1927,17 +1980,17 @@ var FSM = class {
|
|
|
1927
1980
|
*/
|
|
1928
1981
|
addTimedTransition(stateOrPattern, after2, target) {
|
|
1929
1982
|
return this.onEnter(stateOrPattern, () => {
|
|
1930
|
-
const ms = typeof after2 === "function" ? after2(this
|
|
1983
|
+
const ms = typeof after2 === "function" ? after2(this.#currentContext.current) : after2;
|
|
1931
1984
|
const timeoutID = setTimeout(() => {
|
|
1932
|
-
this
|
|
1985
|
+
this.#transition({ type: "TIMER" }, target);
|
|
1933
1986
|
}, ms);
|
|
1934
1987
|
return () => {
|
|
1935
1988
|
clearTimeout(timeoutID);
|
|
1936
1989
|
};
|
|
1937
1990
|
});
|
|
1938
1991
|
}
|
|
1939
|
-
getTargetFn(eventName) {
|
|
1940
|
-
return _optionalChain([this, 'access', _13 => _13
|
|
1992
|
+
#getTargetFn(eventName) {
|
|
1993
|
+
return _optionalChain([this, 'access', _13 => _13.#allowedTransitions, 'access', _14 => _14.get, 'call', _15 => _15(this.currentState), 'optionalAccess', _16 => _16.get, 'call', _17 => _17(eventName)]);
|
|
1941
1994
|
}
|
|
1942
1995
|
/**
|
|
1943
1996
|
* Exits the current state, and executes any necessary cleanup functions.
|
|
@@ -1949,12 +2002,12 @@ var FSM = class {
|
|
|
1949
2002
|
* `foo.bar.qux` to `bla.bla`, then the level is 3.
|
|
1950
2003
|
* If `null`, it will exit all levels.
|
|
1951
2004
|
*/
|
|
1952
|
-
exit(levels) {
|
|
1953
|
-
this
|
|
1954
|
-
this
|
|
1955
|
-
levels = _nullishCoalesce(levels, () => ( this
|
|
2005
|
+
#exit(levels) {
|
|
2006
|
+
this.#eventHub.willExitState.notify(this.currentState);
|
|
2007
|
+
this.#currentContext.allowPatching((patchableContext) => {
|
|
2008
|
+
levels = _nullishCoalesce(levels, () => ( this.#cleanupStack.length));
|
|
1956
2009
|
for (let i = 0; i < levels; i++) {
|
|
1957
|
-
_optionalChain([this, 'access', _18 => _18
|
|
2010
|
+
_optionalChain([this, 'access', _18 => _18.#cleanupStack, 'access', _19 => _19.pop, 'call', _20 => _20(), 'optionalCall', _21 => _21(patchableContext)]);
|
|
1958
2011
|
}
|
|
1959
2012
|
});
|
|
1960
2013
|
}
|
|
@@ -1962,51 +2015,51 @@ var FSM = class {
|
|
|
1962
2015
|
* Enters the current state, and executes any necessary onEnter handlers.
|
|
1963
2016
|
* Call this directly _after_ setting the current state to the next state.
|
|
1964
2017
|
*/
|
|
1965
|
-
enter(levels) {
|
|
2018
|
+
#enter(levels) {
|
|
1966
2019
|
const enterPatterns = patterns(
|
|
1967
2020
|
this.currentState,
|
|
1968
2021
|
_nullishCoalesce(levels, () => ( this.currentState.split(".").length + 1))
|
|
1969
2022
|
);
|
|
1970
|
-
this
|
|
2023
|
+
this.#currentContext.allowPatching((patchableContext) => {
|
|
1971
2024
|
for (const pattern of enterPatterns) {
|
|
1972
|
-
const enterFn = this
|
|
2025
|
+
const enterFn = this.#enterFns.get(pattern);
|
|
1973
2026
|
const cleanupFn = _optionalChain([enterFn, 'optionalCall', _22 => _22(patchableContext)]);
|
|
1974
2027
|
if (typeof cleanupFn === "function") {
|
|
1975
|
-
this
|
|
2028
|
+
this.#cleanupStack.push(cleanupFn);
|
|
1976
2029
|
} else {
|
|
1977
|
-
this
|
|
2030
|
+
this.#cleanupStack.push(null);
|
|
1978
2031
|
}
|
|
1979
2032
|
}
|
|
1980
2033
|
});
|
|
1981
|
-
this
|
|
2034
|
+
this.#eventHub.didEnterState.notify(this.currentState);
|
|
1982
2035
|
}
|
|
1983
2036
|
/**
|
|
1984
2037
|
* Sends an event to the machine, which may cause an internal state
|
|
1985
2038
|
* transition to happen. When that happens, will trigger side effects.
|
|
1986
2039
|
*/
|
|
1987
2040
|
send(event) {
|
|
1988
|
-
if (!this
|
|
2041
|
+
if (!this.#knownEventTypes.has(event.type)) {
|
|
1989
2042
|
throw new Error(`Invalid event ${JSON.stringify(event.type)}`);
|
|
1990
2043
|
}
|
|
1991
|
-
if (this
|
|
2044
|
+
if (this.#runningState === 2 /* STOPPED */) {
|
|
1992
2045
|
return;
|
|
1993
2046
|
}
|
|
1994
|
-
const targetFn = this
|
|
2047
|
+
const targetFn = this.#getTargetFn(event.type);
|
|
1995
2048
|
if (targetFn !== void 0) {
|
|
1996
|
-
return this
|
|
2049
|
+
return this.#transition(event, targetFn);
|
|
1997
2050
|
} else {
|
|
1998
|
-
this
|
|
2051
|
+
this.#eventHub.didIgnoreEvent.notify(event);
|
|
1999
2052
|
}
|
|
2000
2053
|
}
|
|
2001
|
-
transition(event, target) {
|
|
2002
|
-
this
|
|
2054
|
+
#transition(event, target) {
|
|
2055
|
+
this.#eventHub.didReceiveEvent.notify(event);
|
|
2003
2056
|
const oldState = this.currentState;
|
|
2004
2057
|
const targetFn = typeof target === "function" ? target : () => target;
|
|
2005
|
-
const nextTarget = targetFn(event, this
|
|
2058
|
+
const nextTarget = targetFn(event, this.#currentContext.current);
|
|
2006
2059
|
let nextState;
|
|
2007
2060
|
let effects = void 0;
|
|
2008
2061
|
if (nextTarget === null) {
|
|
2009
|
-
this
|
|
2062
|
+
this.#eventHub.didIgnoreEvent.notify(event);
|
|
2010
2063
|
return;
|
|
2011
2064
|
}
|
|
2012
2065
|
if (typeof nextTarget === "string") {
|
|
@@ -2015,18 +2068,18 @@ var FSM = class {
|
|
|
2015
2068
|
nextState = nextTarget.target;
|
|
2016
2069
|
effects = Array.isArray(nextTarget.effect) ? nextTarget.effect : [nextTarget.effect];
|
|
2017
2070
|
}
|
|
2018
|
-
if (!this
|
|
2071
|
+
if (!this.#states.has(nextState)) {
|
|
2019
2072
|
throw new Error(`Invalid next state name: ${JSON.stringify(nextState)}`);
|
|
2020
2073
|
}
|
|
2021
|
-
this
|
|
2074
|
+
this.#eventHub.willTransition.notify({ from: oldState, to: nextState });
|
|
2022
2075
|
const [up, down] = distance(this.currentState, nextState);
|
|
2023
2076
|
if (up > 0) {
|
|
2024
|
-
this
|
|
2077
|
+
this.#exit(up);
|
|
2025
2078
|
}
|
|
2026
|
-
this
|
|
2079
|
+
this.#currentStateOrNull = nextState;
|
|
2027
2080
|
if (effects !== void 0) {
|
|
2028
2081
|
const effectsToRun = effects;
|
|
2029
|
-
this
|
|
2082
|
+
this.#currentContext.allowPatching((patchableContext) => {
|
|
2030
2083
|
for (const effect of effectsToRun) {
|
|
2031
2084
|
if (typeof effect === "function") {
|
|
2032
2085
|
effect(patchableContext, event);
|
|
@@ -2037,7 +2090,7 @@ var FSM = class {
|
|
|
2037
2090
|
});
|
|
2038
2091
|
}
|
|
2039
2092
|
if (down > 0) {
|
|
2040
|
-
this
|
|
2093
|
+
this.#enter(down);
|
|
2041
2094
|
}
|
|
2042
2095
|
}
|
|
2043
2096
|
};
|
|
@@ -2243,7 +2296,7 @@ function defineConnectivityEvents(machine) {
|
|
|
2243
2296
|
}
|
|
2244
2297
|
var assign = (patch) => (ctx) => ctx.patch(patch);
|
|
2245
2298
|
function createConnectionStateMachine(delegates, options) {
|
|
2246
|
-
const onMessage =
|
|
2299
|
+
const onMessage = makeBufferableEventSource();
|
|
2247
2300
|
onMessage.pause();
|
|
2248
2301
|
const onLiveblocksError = makeEventSource();
|
|
2249
2302
|
function fireErrorEvent(errmsg, errcode) {
|
|
@@ -2612,18 +2665,21 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
2612
2665
|
};
|
|
2613
2666
|
}
|
|
2614
2667
|
var ManagedSocket = class {
|
|
2668
|
+
#machine;
|
|
2669
|
+
#cleanups;
|
|
2670
|
+
|
|
2615
2671
|
constructor(delegates, enableDebugLogging = false, waitForActorId = true) {
|
|
2616
2672
|
const { machine, events, cleanups } = createConnectionStateMachine(
|
|
2617
2673
|
delegates,
|
|
2618
2674
|
{ waitForActorId, enableDebugLogging }
|
|
2619
2675
|
);
|
|
2620
|
-
this
|
|
2676
|
+
this.#machine = machine;
|
|
2621
2677
|
this.events = events;
|
|
2622
|
-
this
|
|
2678
|
+
this.#cleanups = cleanups;
|
|
2623
2679
|
}
|
|
2624
2680
|
getStatus() {
|
|
2625
2681
|
try {
|
|
2626
|
-
return toNewConnectionStatus(this
|
|
2682
|
+
return toNewConnectionStatus(this.#machine);
|
|
2627
2683
|
} catch (e4) {
|
|
2628
2684
|
return "initial";
|
|
2629
2685
|
}
|
|
@@ -2632,28 +2688,28 @@ var ManagedSocket = class {
|
|
|
2632
2688
|
* Returns the current auth authValue.
|
|
2633
2689
|
*/
|
|
2634
2690
|
get authValue() {
|
|
2635
|
-
return this
|
|
2691
|
+
return this.#machine.context.authValue;
|
|
2636
2692
|
}
|
|
2637
2693
|
/**
|
|
2638
2694
|
* Call this method to try to connect to a WebSocket. This only has an effect
|
|
2639
2695
|
* if the machine is idle at the moment, otherwise this is a no-op.
|
|
2640
2696
|
*/
|
|
2641
2697
|
connect() {
|
|
2642
|
-
this
|
|
2698
|
+
this.#machine.send({ type: "CONNECT" });
|
|
2643
2699
|
}
|
|
2644
2700
|
/**
|
|
2645
2701
|
* If idle, will try to connect. Otherwise, it will attempt to reconnect to
|
|
2646
2702
|
* the socket, potentially obtaining a new authValue first, if needed.
|
|
2647
2703
|
*/
|
|
2648
2704
|
reconnect() {
|
|
2649
|
-
this
|
|
2705
|
+
this.#machine.send({ type: "RECONNECT" });
|
|
2650
2706
|
}
|
|
2651
2707
|
/**
|
|
2652
2708
|
* Call this method to disconnect from the current WebSocket. Is going to be
|
|
2653
2709
|
* a no-op if there is no active connection.
|
|
2654
2710
|
*/
|
|
2655
2711
|
disconnect() {
|
|
2656
|
-
this
|
|
2712
|
+
this.#machine.send({ type: "DISCONNECT" });
|
|
2657
2713
|
}
|
|
2658
2714
|
/**
|
|
2659
2715
|
* Call this to stop the machine and run necessary cleanup functions. After
|
|
@@ -2661,9 +2717,9 @@ var ManagedSocket = class {
|
|
|
2661
2717
|
* letting the instance get garbage collected.
|
|
2662
2718
|
*/
|
|
2663
2719
|
destroy() {
|
|
2664
|
-
this
|
|
2720
|
+
this.#machine.stop();
|
|
2665
2721
|
let cleanup;
|
|
2666
|
-
while (cleanup = this
|
|
2722
|
+
while (cleanup = this.#cleanups.pop()) {
|
|
2667
2723
|
cleanup();
|
|
2668
2724
|
}
|
|
2669
2725
|
}
|
|
@@ -2672,7 +2728,7 @@ var ManagedSocket = class {
|
|
|
2672
2728
|
* message if this is somehow impossible.
|
|
2673
2729
|
*/
|
|
2674
2730
|
send(data) {
|
|
2675
|
-
const socket = _optionalChain([this, 'access', _43 => _43
|
|
2731
|
+
const socket = _optionalChain([this, 'access', _43 => _43.#machine, 'access', _44 => _44.context, 'optionalAccess', _45 => _45.socket]);
|
|
2676
2732
|
if (socket === null) {
|
|
2677
2733
|
warn("Cannot send: not connected yet", data);
|
|
2678
2734
|
} else if (socket.readyState !== 1) {
|
|
@@ -2686,7 +2742,7 @@ var ManagedSocket = class {
|
|
|
2686
2742
|
* Not ideal to keep exposed :(
|
|
2687
2743
|
*/
|
|
2688
2744
|
_privateSendMachineEvent(event) {
|
|
2689
|
-
this
|
|
2745
|
+
this.#machine.send(event);
|
|
2690
2746
|
}
|
|
2691
2747
|
};
|
|
2692
2748
|
|
|
@@ -3187,7 +3243,7 @@ function createStore(initialState) {
|
|
|
3187
3243
|
subscriber(state);
|
|
3188
3244
|
}
|
|
3189
3245
|
}
|
|
3190
|
-
function
|
|
3246
|
+
function batch2(cb) {
|
|
3191
3247
|
if (notifyImmediately === false) {
|
|
3192
3248
|
return cb();
|
|
3193
3249
|
}
|
|
@@ -3208,7 +3264,7 @@ function createStore(initialState) {
|
|
|
3208
3264
|
return {
|
|
3209
3265
|
get,
|
|
3210
3266
|
set,
|
|
3211
|
-
batch,
|
|
3267
|
+
batch: batch2,
|
|
3212
3268
|
subscribe
|
|
3213
3269
|
};
|
|
3214
3270
|
}
|
|
@@ -3219,7 +3275,29 @@ var freeze = process.env.NODE_ENV === "production" ? (
|
|
|
3219
3275
|
(x) => x
|
|
3220
3276
|
) : Object.freeze;
|
|
3221
3277
|
|
|
3222
|
-
// src/
|
|
3278
|
+
// src/lib/Signal.ts
|
|
3279
|
+
var kSinks = Symbol("kSinks");
|
|
3280
|
+
var kTrigger = Symbol("kTrigger");
|
|
3281
|
+
var signalsToTrigger = null;
|
|
3282
|
+
function batch(callback) {
|
|
3283
|
+
if (signalsToTrigger !== null) {
|
|
3284
|
+
callback();
|
|
3285
|
+
return;
|
|
3286
|
+
}
|
|
3287
|
+
signalsToTrigger = /* @__PURE__ */ new Set();
|
|
3288
|
+
try {
|
|
3289
|
+
callback();
|
|
3290
|
+
} finally {
|
|
3291
|
+
for (const signal of signalsToTrigger) {
|
|
3292
|
+
signal[kTrigger]();
|
|
3293
|
+
}
|
|
3294
|
+
signalsToTrigger = null;
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
function enqueueTrigger(signal) {
|
|
3298
|
+
if (!signalsToTrigger) raise("Expected to be in an active batch");
|
|
3299
|
+
signalsToTrigger.add(signal);
|
|
3300
|
+
}
|
|
3223
3301
|
function merge(target, patch) {
|
|
3224
3302
|
let updated = false;
|
|
3225
3303
|
const newValue = { ...target };
|
|
@@ -3237,57 +3315,215 @@ function merge(target, patch) {
|
|
|
3237
3315
|
});
|
|
3238
3316
|
return updated ? newValue : target;
|
|
3239
3317
|
}
|
|
3240
|
-
var
|
|
3241
|
-
|
|
3242
|
-
|
|
3318
|
+
var AbstractSignal = class {
|
|
3319
|
+
/** @internal */
|
|
3320
|
+
|
|
3321
|
+
#eventSource;
|
|
3322
|
+
/** @internal */
|
|
3323
|
+
|
|
3324
|
+
constructor(equals) {
|
|
3325
|
+
this.equals = _nullishCoalesce(equals, () => ( Object.is));
|
|
3326
|
+
this.#eventSource = makeEventSource();
|
|
3327
|
+
this[kSinks] = /* @__PURE__ */ new Set();
|
|
3328
|
+
this.get = this.get.bind(this);
|
|
3329
|
+
this.subscribe = this.subscribe.bind(this);
|
|
3330
|
+
this.subscribeOnce = this.subscribeOnce.bind(this);
|
|
3331
|
+
}
|
|
3332
|
+
[Symbol.dispose]() {
|
|
3333
|
+
this.#eventSource[Symbol.dispose]();
|
|
3334
|
+
this.#eventSource = "(disposed)";
|
|
3335
|
+
this.equals = "(disposed)";
|
|
3336
|
+
}
|
|
3337
|
+
get hasWatchers() {
|
|
3338
|
+
if (this.#eventSource.count() > 0) return true;
|
|
3339
|
+
for (const sink of this[kSinks]) {
|
|
3340
|
+
if (sink.hasWatchers) {
|
|
3341
|
+
return true;
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
return false;
|
|
3243
3345
|
}
|
|
3244
|
-
|
|
3245
|
-
|
|
3346
|
+
[kTrigger]() {
|
|
3347
|
+
this.#eventSource.notify();
|
|
3348
|
+
for (const sink of this[kSinks]) {
|
|
3349
|
+
enqueueTrigger(sink);
|
|
3350
|
+
}
|
|
3246
3351
|
}
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3352
|
+
subscribe(callback) {
|
|
3353
|
+
return this.#eventSource.subscribe(callback);
|
|
3354
|
+
}
|
|
3355
|
+
subscribeOnce(callback) {
|
|
3356
|
+
const unsub = this.subscribe(() => {
|
|
3357
|
+
unsub();
|
|
3358
|
+
return callback();
|
|
3359
|
+
});
|
|
3360
|
+
return unsub;
|
|
3361
|
+
}
|
|
3362
|
+
waitUntil() {
|
|
3363
|
+
throw new Error("waitUntil not supported on Signals");
|
|
3364
|
+
}
|
|
3365
|
+
markSinksDirty() {
|
|
3366
|
+
for (const sink of this[kSinks]) {
|
|
3367
|
+
sink.markDirty();
|
|
3251
3368
|
}
|
|
3252
3369
|
}
|
|
3253
|
-
|
|
3254
|
-
|
|
3370
|
+
addSink(sink) {
|
|
3371
|
+
this[kSinks].add(sink);
|
|
3372
|
+
}
|
|
3373
|
+
removeSink(sink) {
|
|
3374
|
+
this[kSinks].delete(sink);
|
|
3255
3375
|
}
|
|
3256
3376
|
};
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
this._value = freeze(initialValue);
|
|
3377
|
+
var Signal = class extends AbstractSignal {
|
|
3378
|
+
#value;
|
|
3379
|
+
constructor(value, equals) {
|
|
3380
|
+
super(equals);
|
|
3381
|
+
this.#value = freeze(value);
|
|
3263
3382
|
}
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3383
|
+
[Symbol.dispose]() {
|
|
3384
|
+
super[Symbol.dispose]();
|
|
3385
|
+
this.#value = "(disposed)";
|
|
3386
|
+
}
|
|
3387
|
+
get() {
|
|
3388
|
+
return this.#value;
|
|
3267
3389
|
}
|
|
3268
3390
|
set(newValue) {
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3391
|
+
batch(() => {
|
|
3392
|
+
if (typeof newValue === "function") {
|
|
3393
|
+
newValue = newValue(this.#value);
|
|
3394
|
+
}
|
|
3395
|
+
if (!this.equals(this.#value, newValue)) {
|
|
3396
|
+
this.#value = freeze(newValue);
|
|
3397
|
+
this.markSinksDirty();
|
|
3398
|
+
enqueueTrigger(this);
|
|
3399
|
+
}
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
var PatchableSignal = class extends Signal {
|
|
3404
|
+
constructor(data) {
|
|
3405
|
+
super(freeze(compactObject(data)));
|
|
3406
|
+
}
|
|
3407
|
+
set() {
|
|
3408
|
+
throw new Error("Don't call .set() directly, use .patch()");
|
|
3409
|
+
}
|
|
3410
|
+
/**
|
|
3411
|
+
* Patches the current object.
|
|
3412
|
+
*/
|
|
3413
|
+
patch(patch) {
|
|
3414
|
+
super.set((old) => merge(old, patch));
|
|
3415
|
+
}
|
|
3416
|
+
};
|
|
3417
|
+
var INITIAL = Symbol();
|
|
3418
|
+
var DerivedSignal = class _DerivedSignal extends AbstractSignal {
|
|
3419
|
+
#prevValue;
|
|
3420
|
+
#dirty;
|
|
3421
|
+
// When true, the value in #value may not be up-to-date and needs re-checking
|
|
3422
|
+
#parents;
|
|
3423
|
+
#transform;
|
|
3424
|
+
// prettier-ignore
|
|
3425
|
+
static from(...args) {
|
|
3426
|
+
const last = args.pop();
|
|
3427
|
+
if (typeof last !== "function")
|
|
3428
|
+
raise("Invalid .from() call, last argument expected to be a function");
|
|
3429
|
+
if (typeof args[args.length - 1] === "function") {
|
|
3430
|
+
const equals = last;
|
|
3431
|
+
const transform = args.pop();
|
|
3432
|
+
return new _DerivedSignal(args, transform, equals);
|
|
3433
|
+
} else {
|
|
3434
|
+
const transform = last;
|
|
3435
|
+
return new _DerivedSignal(args, transform);
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
constructor(parents, transform, equals) {
|
|
3439
|
+
super(equals);
|
|
3440
|
+
this.#dirty = true;
|
|
3441
|
+
this.#prevValue = INITIAL;
|
|
3442
|
+
this.#parents = parents;
|
|
3443
|
+
this.#transform = transform;
|
|
3444
|
+
for (const parent of parents) {
|
|
3445
|
+
parent.addSink(this);
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
[Symbol.dispose]() {
|
|
3449
|
+
for (const parent of this.#parents) {
|
|
3450
|
+
parent.removeSink(this);
|
|
3451
|
+
}
|
|
3452
|
+
this.#prevValue = "(disposed)";
|
|
3453
|
+
this.#parents = "(disposed)";
|
|
3454
|
+
this.#transform = "(disposed)";
|
|
3455
|
+
}
|
|
3456
|
+
get isDirty() {
|
|
3457
|
+
return this.#dirty;
|
|
3458
|
+
}
|
|
3459
|
+
#recompute() {
|
|
3460
|
+
const derived = this.#transform(...this.#parents.map((p) => p.get()));
|
|
3461
|
+
this.#dirty = false;
|
|
3462
|
+
if (!this.equals(this.#prevValue, derived)) {
|
|
3463
|
+
this.#prevValue = derived;
|
|
3464
|
+
return true;
|
|
3465
|
+
}
|
|
3466
|
+
return false;
|
|
3467
|
+
}
|
|
3468
|
+
markDirty() {
|
|
3469
|
+
if (!this.#dirty) {
|
|
3470
|
+
this.#dirty = true;
|
|
3471
|
+
this.markSinksDirty();
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
get() {
|
|
3475
|
+
if (this.#dirty) {
|
|
3476
|
+
this.#recompute();
|
|
3477
|
+
}
|
|
3478
|
+
return this.#prevValue;
|
|
3479
|
+
}
|
|
3480
|
+
/**
|
|
3481
|
+
* Called by the Signal system if one or more of the dependent signals have
|
|
3482
|
+
* changed. In the case of a DerivedSignal, we'll only want to re-evaluate
|
|
3483
|
+
* the actual value if it's being watched, or any of their sinks are being
|
|
3484
|
+
* watched actively.
|
|
3485
|
+
*/
|
|
3486
|
+
[kTrigger]() {
|
|
3487
|
+
if (!this.hasWatchers) {
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
const updated = this.#recompute();
|
|
3491
|
+
if (updated) {
|
|
3492
|
+
super[kTrigger]();
|
|
3272
3493
|
}
|
|
3273
3494
|
}
|
|
3274
3495
|
};
|
|
3275
|
-
var
|
|
3276
|
-
|
|
3496
|
+
var MutableSignal = class extends AbstractSignal {
|
|
3497
|
+
#state;
|
|
3498
|
+
constructor(initialState) {
|
|
3277
3499
|
super();
|
|
3278
|
-
|
|
3279
|
-
const otherRefs = args;
|
|
3280
|
-
this._refs = otherRefs;
|
|
3281
|
-
this._refs.forEach((ref) => {
|
|
3282
|
-
ref.didInvalidate.subscribe(() => this.invalidate());
|
|
3283
|
-
});
|
|
3284
|
-
this._transform = transformFn;
|
|
3500
|
+
this.#state = initialState;
|
|
3285
3501
|
}
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3502
|
+
[Symbol.dispose]() {
|
|
3503
|
+
super[Symbol.dispose]();
|
|
3504
|
+
this.#state = "(disposed)";
|
|
3505
|
+
}
|
|
3506
|
+
get() {
|
|
3507
|
+
return this.#state;
|
|
3508
|
+
}
|
|
3509
|
+
/**
|
|
3510
|
+
* Invokes a callback function that is allowed to mutate the given state
|
|
3511
|
+
* value. Do not change the value outside of the callback.
|
|
3512
|
+
*
|
|
3513
|
+
* If the callback explicitly returns `false`, it's assumed that the state
|
|
3514
|
+
* was not changed.
|
|
3515
|
+
*/
|
|
3516
|
+
mutate(callback) {
|
|
3517
|
+
batch(() => {
|
|
3518
|
+
const result = callback(this.#state);
|
|
3519
|
+
if (result !== null && typeof result === "object" && "then" in result) {
|
|
3520
|
+
raise("MutableSignal.mutate() does not support async callbacks");
|
|
3521
|
+
}
|
|
3522
|
+
if (result !== false) {
|
|
3523
|
+
this.markSinksDirty();
|
|
3524
|
+
enqueueTrigger(this);
|
|
3525
|
+
}
|
|
3526
|
+
});
|
|
3291
3527
|
}
|
|
3292
3528
|
};
|
|
3293
3529
|
|
|
@@ -3455,10 +3691,10 @@ function Orphaned(oldKey, oldPos = asPos(oldKey)) {
|
|
|
3455
3691
|
return Object.freeze({ type: "Orphaned", oldKey, oldPos });
|
|
3456
3692
|
}
|
|
3457
3693
|
var AbstractCrdt = class {
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3694
|
+
// ^^^^^^^^^^^^ TODO: Make this an interface
|
|
3695
|
+
#pool;
|
|
3696
|
+
#id;
|
|
3697
|
+
#parent = NoParent;
|
|
3462
3698
|
/** @internal */
|
|
3463
3699
|
_getParentKeyOrThrow() {
|
|
3464
3700
|
switch (this.parent.type) {
|
|
@@ -3487,18 +3723,18 @@ var AbstractCrdt = class {
|
|
|
3487
3723
|
}
|
|
3488
3724
|
/** @internal */
|
|
3489
3725
|
get _pool() {
|
|
3490
|
-
return this
|
|
3726
|
+
return this.#pool;
|
|
3491
3727
|
}
|
|
3492
3728
|
get roomId() {
|
|
3493
|
-
return this
|
|
3729
|
+
return this.#pool ? this.#pool.roomId : null;
|
|
3494
3730
|
}
|
|
3495
3731
|
/** @internal */
|
|
3496
3732
|
get _id() {
|
|
3497
|
-
return this
|
|
3733
|
+
return this.#id;
|
|
3498
3734
|
}
|
|
3499
3735
|
/** @internal */
|
|
3500
3736
|
get parent() {
|
|
3501
|
-
return this
|
|
3737
|
+
return this.#parent;
|
|
3502
3738
|
}
|
|
3503
3739
|
/** @internal */
|
|
3504
3740
|
get _parentKey() {
|
|
@@ -3532,12 +3768,12 @@ var AbstractCrdt = class {
|
|
|
3532
3768
|
if (this.parent.node !== newParentNode) {
|
|
3533
3769
|
throw new Error("Cannot set parent: node already has a parent");
|
|
3534
3770
|
} else {
|
|
3535
|
-
this
|
|
3771
|
+
this.#parent = HasParent(newParentNode, newParentKey);
|
|
3536
3772
|
return;
|
|
3537
3773
|
}
|
|
3538
3774
|
case "Orphaned":
|
|
3539
3775
|
case "NoParent": {
|
|
3540
|
-
this
|
|
3776
|
+
this.#parent = HasParent(newParentNode, newParentKey);
|
|
3541
3777
|
return;
|
|
3542
3778
|
}
|
|
3543
3779
|
default:
|
|
@@ -3546,25 +3782,25 @@ var AbstractCrdt = class {
|
|
|
3546
3782
|
}
|
|
3547
3783
|
/** @internal */
|
|
3548
3784
|
_attach(id, pool) {
|
|
3549
|
-
if (this
|
|
3785
|
+
if (this.#id || this.#pool) {
|
|
3550
3786
|
throw new Error("Cannot attach node: already attached");
|
|
3551
3787
|
}
|
|
3552
3788
|
pool.addNode(id, crdtAsLiveNode(this));
|
|
3553
|
-
this
|
|
3554
|
-
this
|
|
3789
|
+
this.#id = id;
|
|
3790
|
+
this.#pool = pool;
|
|
3555
3791
|
}
|
|
3556
3792
|
/** @internal */
|
|
3557
3793
|
_detach() {
|
|
3558
|
-
if (this
|
|
3559
|
-
this.
|
|
3794
|
+
if (this.#pool && this.#id) {
|
|
3795
|
+
this.#pool.deleteNode(this.#id);
|
|
3560
3796
|
}
|
|
3561
3797
|
switch (this.parent.type) {
|
|
3562
3798
|
case "HasParent": {
|
|
3563
|
-
this
|
|
3799
|
+
this.#parent = Orphaned(this.parent.key, this.parent.pos);
|
|
3564
3800
|
break;
|
|
3565
3801
|
}
|
|
3566
3802
|
case "NoParent": {
|
|
3567
|
-
this
|
|
3803
|
+
this.#parent = NoParent;
|
|
3568
3804
|
break;
|
|
3569
3805
|
}
|
|
3570
3806
|
case "Orphaned": {
|
|
@@ -3573,8 +3809,13 @@ var AbstractCrdt = class {
|
|
|
3573
3809
|
default:
|
|
3574
3810
|
assertNever(this.parent, "Unknown state");
|
|
3575
3811
|
}
|
|
3576
|
-
this
|
|
3812
|
+
this.#pool = void 0;
|
|
3577
3813
|
}
|
|
3814
|
+
/** This caches the result of the last .toImmutable() call for this Live node. */
|
|
3815
|
+
#cachedImmutable;
|
|
3816
|
+
#cachedTreeNodeKey;
|
|
3817
|
+
/** This caches the result of the last .toTreeNode() call for this Live node. */
|
|
3818
|
+
#cachedTreeNode;
|
|
3578
3819
|
/**
|
|
3579
3820
|
* @internal
|
|
3580
3821
|
*
|
|
@@ -3583,9 +3824,9 @@ var AbstractCrdt = class {
|
|
|
3583
3824
|
* mutation to the Live node.
|
|
3584
3825
|
*/
|
|
3585
3826
|
invalidate() {
|
|
3586
|
-
if (this
|
|
3587
|
-
this
|
|
3588
|
-
this
|
|
3827
|
+
if (this.#cachedImmutable !== void 0 || this.#cachedTreeNode !== void 0) {
|
|
3828
|
+
this.#cachedImmutable = void 0;
|
|
3829
|
+
this.#cachedTreeNode = void 0;
|
|
3589
3830
|
if (this.parent.type === "HasParent") {
|
|
3590
3831
|
this.parent.node.invalidate();
|
|
3591
3832
|
}
|
|
@@ -3597,20 +3838,20 @@ var AbstractCrdt = class {
|
|
|
3597
3838
|
* Return an snapshot of this Live tree for use in DevTools.
|
|
3598
3839
|
*/
|
|
3599
3840
|
toTreeNode(key) {
|
|
3600
|
-
if (this
|
|
3601
|
-
this
|
|
3602
|
-
this
|
|
3841
|
+
if (this.#cachedTreeNode === void 0 || this.#cachedTreeNodeKey !== key) {
|
|
3842
|
+
this.#cachedTreeNodeKey = key;
|
|
3843
|
+
this.#cachedTreeNode = this._toTreeNode(key);
|
|
3603
3844
|
}
|
|
3604
|
-
return this
|
|
3845
|
+
return this.#cachedTreeNode;
|
|
3605
3846
|
}
|
|
3606
3847
|
/**
|
|
3607
3848
|
* Return an immutable snapshot of this Live node and its children.
|
|
3608
3849
|
*/
|
|
3609
3850
|
toImmutable() {
|
|
3610
|
-
if (this
|
|
3611
|
-
this
|
|
3851
|
+
if (this.#cachedImmutable === void 0) {
|
|
3852
|
+
this.#cachedImmutable = this._toImmutable();
|
|
3612
3853
|
}
|
|
3613
|
-
return this
|
|
3854
|
+
return this.#cachedImmutable;
|
|
3614
3855
|
}
|
|
3615
3856
|
};
|
|
3616
3857
|
|
|
@@ -3631,12 +3872,13 @@ function isChildCrdt(crdt) {
|
|
|
3631
3872
|
|
|
3632
3873
|
// src/crdts/LiveRegister.ts
|
|
3633
3874
|
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
3875
|
+
#data;
|
|
3634
3876
|
constructor(data) {
|
|
3635
3877
|
super();
|
|
3636
|
-
this
|
|
3878
|
+
this.#data = data;
|
|
3637
3879
|
}
|
|
3638
3880
|
get data() {
|
|
3639
|
-
return this
|
|
3881
|
+
return this.#data;
|
|
3640
3882
|
}
|
|
3641
3883
|
/** @internal */
|
|
3642
3884
|
static _deserialize([id, item], _parentToChildren, pool) {
|
|
@@ -3692,12 +3934,12 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
3692
3934
|
type: "Json",
|
|
3693
3935
|
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
3694
3936
|
key,
|
|
3695
|
-
payload: this
|
|
3937
|
+
payload: this.#data
|
|
3696
3938
|
};
|
|
3697
3939
|
}
|
|
3698
3940
|
/** @internal */
|
|
3699
3941
|
_toImmutable() {
|
|
3700
|
-
return this
|
|
3942
|
+
return this.#data;
|
|
3701
3943
|
}
|
|
3702
3944
|
clone() {
|
|
3703
3945
|
return deepClone(this.data);
|
|
@@ -3711,17 +3953,21 @@ function compareNodePosition(itemA, itemB) {
|
|
|
3711
3953
|
return posA === posB ? 0 : posA < posB ? -1 : 1;
|
|
3712
3954
|
}
|
|
3713
3955
|
var LiveList = class _LiveList extends AbstractCrdt {
|
|
3956
|
+
// TODO: Naive array at first, find a better data structure. Maybe an Order statistics tree?
|
|
3957
|
+
#items;
|
|
3958
|
+
#implicitlyDeletedItems;
|
|
3959
|
+
#unacknowledgedSets;
|
|
3714
3960
|
constructor(items) {
|
|
3715
3961
|
super();
|
|
3716
|
-
this
|
|
3717
|
-
this
|
|
3718
|
-
this
|
|
3962
|
+
this.#items = [];
|
|
3963
|
+
this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
|
|
3964
|
+
this.#unacknowledgedSets = /* @__PURE__ */ new Map();
|
|
3719
3965
|
let position = void 0;
|
|
3720
3966
|
for (const item of items) {
|
|
3721
3967
|
const newPosition = makePosition(position);
|
|
3722
3968
|
const node = lsonToLiveNode(item);
|
|
3723
3969
|
node._setParentLink(this, newPosition);
|
|
3724
|
-
this.
|
|
3970
|
+
this.#items.push(node);
|
|
3725
3971
|
position = newPosition;
|
|
3726
3972
|
}
|
|
3727
3973
|
}
|
|
@@ -3762,7 +4008,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3762
4008
|
parentKey
|
|
3763
4009
|
};
|
|
3764
4010
|
ops.push(op);
|
|
3765
|
-
for (const item of this
|
|
4011
|
+
for (const item of this.#items) {
|
|
3766
4012
|
const parentKey2 = item._getParentKeyOrThrow();
|
|
3767
4013
|
const childOps = HACK_addIntentAndDeletedIdToOperation(
|
|
3768
4014
|
item._toOps(this._id, parentKey2, pool),
|
|
@@ -3770,7 +4016,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3770
4016
|
);
|
|
3771
4017
|
const childOpId = childOps[0].opId;
|
|
3772
4018
|
if (childOpId !== void 0) {
|
|
3773
|
-
this.
|
|
4019
|
+
this.#unacknowledgedSets.set(parentKey2, childOpId);
|
|
3774
4020
|
}
|
|
3775
4021
|
ops.push(...childOps);
|
|
3776
4022
|
}
|
|
@@ -3782,36 +4028,35 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3782
4028
|
* Adds a new item into the sorted list, in the correct position.
|
|
3783
4029
|
*/
|
|
3784
4030
|
_insertAndSort(item) {
|
|
3785
|
-
this.
|
|
4031
|
+
this.#items.push(item);
|
|
3786
4032
|
this._sortItems();
|
|
3787
4033
|
}
|
|
3788
4034
|
/** @internal */
|
|
3789
4035
|
_sortItems() {
|
|
3790
|
-
this.
|
|
4036
|
+
this.#items.sort(compareNodePosition);
|
|
3791
4037
|
this.invalidate();
|
|
3792
4038
|
}
|
|
3793
4039
|
/** @internal */
|
|
3794
4040
|
_indexOfPosition(position) {
|
|
3795
|
-
return this.
|
|
4041
|
+
return this.#items.findIndex(
|
|
3796
4042
|
(item) => item._getParentKeyOrThrow() === position
|
|
3797
4043
|
);
|
|
3798
4044
|
}
|
|
3799
4045
|
/** @internal */
|
|
3800
4046
|
_attach(id, pool) {
|
|
3801
4047
|
super._attach(id, pool);
|
|
3802
|
-
for (const item of this
|
|
4048
|
+
for (const item of this.#items) {
|
|
3803
4049
|
item._attach(pool.generateId(), pool);
|
|
3804
4050
|
}
|
|
3805
4051
|
}
|
|
3806
4052
|
/** @internal */
|
|
3807
4053
|
_detach() {
|
|
3808
4054
|
super._detach();
|
|
3809
|
-
for (const item of this
|
|
4055
|
+
for (const item of this.#items) {
|
|
3810
4056
|
item._detach();
|
|
3811
4057
|
}
|
|
3812
4058
|
}
|
|
3813
|
-
|
|
3814
|
-
_applySetRemote(op) {
|
|
4059
|
+
#applySetRemote(op) {
|
|
3815
4060
|
if (this._pool === void 0) {
|
|
3816
4061
|
throw new Error("Can't attach child if managed pool is not present");
|
|
3817
4062
|
}
|
|
@@ -3822,10 +4067,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3822
4067
|
const deletedId = op.deletedId;
|
|
3823
4068
|
const indexOfItemWithSamePosition = this._indexOfPosition(key);
|
|
3824
4069
|
if (indexOfItemWithSamePosition !== -1) {
|
|
3825
|
-
const itemWithSamePosition = this
|
|
4070
|
+
const itemWithSamePosition = this.#items[indexOfItemWithSamePosition];
|
|
3826
4071
|
if (itemWithSamePosition._id === deletedId) {
|
|
3827
4072
|
itemWithSamePosition._detach();
|
|
3828
|
-
this
|
|
4073
|
+
this.#items[indexOfItemWithSamePosition] = child;
|
|
3829
4074
|
return {
|
|
3830
4075
|
modified: makeUpdate(this, [
|
|
3831
4076
|
setDelta(indexOfItemWithSamePosition, child)
|
|
@@ -3833,12 +4078,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3833
4078
|
reverse: []
|
|
3834
4079
|
};
|
|
3835
4080
|
} else {
|
|
3836
|
-
this.
|
|
3837
|
-
this
|
|
4081
|
+
this.#implicitlyDeletedItems.add(itemWithSamePosition);
|
|
4082
|
+
this.#items[indexOfItemWithSamePosition] = child;
|
|
3838
4083
|
const delta = [
|
|
3839
4084
|
setDelta(indexOfItemWithSamePosition, child)
|
|
3840
4085
|
];
|
|
3841
|
-
const deleteDelta2 = this
|
|
4086
|
+
const deleteDelta2 = this.#detachItemAssociatedToSetOperation(
|
|
3842
4087
|
op.deletedId
|
|
3843
4088
|
);
|
|
3844
4089
|
if (deleteDelta2) {
|
|
@@ -3851,7 +4096,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3851
4096
|
}
|
|
3852
4097
|
} else {
|
|
3853
4098
|
const updates = [];
|
|
3854
|
-
const deleteDelta2 = this
|
|
4099
|
+
const deleteDelta2 = this.#detachItemAssociatedToSetOperation(
|
|
3855
4100
|
op.deletedId
|
|
3856
4101
|
);
|
|
3857
4102
|
if (deleteDelta2) {
|
|
@@ -3865,26 +4110,25 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3865
4110
|
};
|
|
3866
4111
|
}
|
|
3867
4112
|
}
|
|
3868
|
-
|
|
3869
|
-
_applySetAck(op) {
|
|
4113
|
+
#applySetAck(op) {
|
|
3870
4114
|
if (this._pool === void 0) {
|
|
3871
4115
|
throw new Error("Can't attach child if managed pool is not present");
|
|
3872
4116
|
}
|
|
3873
4117
|
const delta = [];
|
|
3874
|
-
const deletedDelta = this
|
|
4118
|
+
const deletedDelta = this.#detachItemAssociatedToSetOperation(op.deletedId);
|
|
3875
4119
|
if (deletedDelta) {
|
|
3876
4120
|
delta.push(deletedDelta);
|
|
3877
4121
|
}
|
|
3878
|
-
const unacknowledgedOpId = this.
|
|
4122
|
+
const unacknowledgedOpId = this.#unacknowledgedSets.get(op.parentKey);
|
|
3879
4123
|
if (unacknowledgedOpId !== void 0) {
|
|
3880
4124
|
if (unacknowledgedOpId !== op.opId) {
|
|
3881
4125
|
return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
|
|
3882
4126
|
} else {
|
|
3883
|
-
this.
|
|
4127
|
+
this.#unacknowledgedSets.delete(op.parentKey);
|
|
3884
4128
|
}
|
|
3885
4129
|
}
|
|
3886
4130
|
const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
|
|
3887
|
-
const existingItem = this.
|
|
4131
|
+
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
3888
4132
|
if (existingItem !== void 0) {
|
|
3889
4133
|
if (existingItem._parentKey === op.parentKey) {
|
|
3890
4134
|
return {
|
|
@@ -3893,16 +4137,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3893
4137
|
};
|
|
3894
4138
|
}
|
|
3895
4139
|
if (indexOfItemWithSamePosition !== -1) {
|
|
3896
|
-
this.
|
|
3897
|
-
this
|
|
4140
|
+
this.#implicitlyDeletedItems.add(
|
|
4141
|
+
this.#items[indexOfItemWithSamePosition]
|
|
3898
4142
|
);
|
|
3899
|
-
const [prevNode] = this.
|
|
4143
|
+
const [prevNode] = this.#items.splice(indexOfItemWithSamePosition, 1);
|
|
3900
4144
|
delta.push(deleteDelta(indexOfItemWithSamePosition, prevNode));
|
|
3901
4145
|
}
|
|
3902
|
-
const prevIndex = this.
|
|
4146
|
+
const prevIndex = this.#items.indexOf(existingItem);
|
|
3903
4147
|
existingItem._setParentLink(this, op.parentKey);
|
|
3904
4148
|
this._sortItems();
|
|
3905
|
-
const newIndex = this.
|
|
4149
|
+
const newIndex = this.#items.indexOf(existingItem);
|
|
3906
4150
|
if (newIndex !== prevIndex) {
|
|
3907
4151
|
delta.push(moveDelta(prevIndex, newIndex, existingItem));
|
|
3908
4152
|
}
|
|
@@ -3912,11 +4156,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3912
4156
|
};
|
|
3913
4157
|
} else {
|
|
3914
4158
|
const orphan = this._pool.getNode(op.id);
|
|
3915
|
-
if (orphan && this.
|
|
4159
|
+
if (orphan && this.#implicitlyDeletedItems.has(orphan)) {
|
|
3916
4160
|
orphan._setParentLink(this, op.parentKey);
|
|
3917
|
-
this.
|
|
4161
|
+
this.#implicitlyDeletedItems.delete(orphan);
|
|
3918
4162
|
this._insertAndSort(orphan);
|
|
3919
|
-
const recreatedItemIndex = this.
|
|
4163
|
+
const recreatedItemIndex = this.#items.indexOf(orphan);
|
|
3920
4164
|
return {
|
|
3921
4165
|
modified: makeUpdate(this, [
|
|
3922
4166
|
// If there is an item at this position, update is a set, else it's an insert
|
|
@@ -3927,9 +4171,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3927
4171
|
};
|
|
3928
4172
|
} else {
|
|
3929
4173
|
if (indexOfItemWithSamePosition !== -1) {
|
|
3930
|
-
this.
|
|
4174
|
+
this.#items.splice(indexOfItemWithSamePosition, 1);
|
|
3931
4175
|
}
|
|
3932
|
-
const { newItem, newIndex } = this
|
|
4176
|
+
const { newItem, newIndex } = this.#createAttachItemAndSort(
|
|
3933
4177
|
op,
|
|
3934
4178
|
op.parentKey
|
|
3935
4179
|
);
|
|
@@ -3946,9 +4190,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3946
4190
|
}
|
|
3947
4191
|
/**
|
|
3948
4192
|
* Returns the update delta of the deletion or null
|
|
3949
|
-
* @internal
|
|
3950
4193
|
*/
|
|
3951
|
-
|
|
4194
|
+
#detachItemAssociatedToSetOperation(deletedId) {
|
|
3952
4195
|
if (deletedId === void 0 || this._pool === void 0) {
|
|
3953
4196
|
return null;
|
|
3954
4197
|
}
|
|
@@ -3962,25 +4205,23 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3962
4205
|
}
|
|
3963
4206
|
return result.modified.updates[0];
|
|
3964
4207
|
}
|
|
3965
|
-
|
|
3966
|
-
_applyRemoteInsert(op) {
|
|
4208
|
+
#applyRemoteInsert(op) {
|
|
3967
4209
|
if (this._pool === void 0) {
|
|
3968
4210
|
throw new Error("Can't attach child if managed pool is not present");
|
|
3969
4211
|
}
|
|
3970
4212
|
const key = asPos(op.parentKey);
|
|
3971
4213
|
const existingItemIndex = this._indexOfPosition(key);
|
|
3972
4214
|
if (existingItemIndex !== -1) {
|
|
3973
|
-
this
|
|
4215
|
+
this.#shiftItemPosition(existingItemIndex, key);
|
|
3974
4216
|
}
|
|
3975
|
-
const { newItem, newIndex } = this
|
|
4217
|
+
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
3976
4218
|
return {
|
|
3977
4219
|
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
3978
4220
|
reverse: []
|
|
3979
4221
|
};
|
|
3980
4222
|
}
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
const existingItem = this._items.find((item) => item._id === op.id);
|
|
4223
|
+
#applyInsertAck(op) {
|
|
4224
|
+
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
3984
4225
|
const key = asPos(op.parentKey);
|
|
3985
4226
|
const itemIndexAtPosition = this._indexOfPosition(key);
|
|
3986
4227
|
if (existingItem) {
|
|
@@ -3989,9 +4230,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3989
4230
|
modified: false
|
|
3990
4231
|
};
|
|
3991
4232
|
} else {
|
|
3992
|
-
const oldPositionIndex = this.
|
|
4233
|
+
const oldPositionIndex = this.#items.indexOf(existingItem);
|
|
3993
4234
|
if (itemIndexAtPosition !== -1) {
|
|
3994
|
-
this
|
|
4235
|
+
this.#shiftItemPosition(itemIndexAtPosition, key);
|
|
3995
4236
|
}
|
|
3996
4237
|
existingItem._setParentLink(this, key);
|
|
3997
4238
|
this._sortItems();
|
|
@@ -4008,9 +4249,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4008
4249
|
}
|
|
4009
4250
|
} else {
|
|
4010
4251
|
const orphan = nn(this._pool).getNode(op.id);
|
|
4011
|
-
if (orphan && this.
|
|
4252
|
+
if (orphan && this.#implicitlyDeletedItems.has(orphan)) {
|
|
4012
4253
|
orphan._setParentLink(this, key);
|
|
4013
|
-
this.
|
|
4254
|
+
this.#implicitlyDeletedItems.delete(orphan);
|
|
4014
4255
|
this._insertAndSort(orphan);
|
|
4015
4256
|
const newIndex = this._indexOfPosition(key);
|
|
4016
4257
|
return {
|
|
@@ -4019,9 +4260,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4019
4260
|
};
|
|
4020
4261
|
} else {
|
|
4021
4262
|
if (itemIndexAtPosition !== -1) {
|
|
4022
|
-
this
|
|
4263
|
+
this.#shiftItemPosition(itemIndexAtPosition, key);
|
|
4023
4264
|
}
|
|
4024
|
-
const { newItem, newIndex } = this
|
|
4265
|
+
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
4025
4266
|
return {
|
|
4026
4267
|
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
4027
4268
|
reverse: []
|
|
@@ -4029,8 +4270,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4029
4270
|
}
|
|
4030
4271
|
}
|
|
4031
4272
|
}
|
|
4032
|
-
|
|
4033
|
-
_applyInsertUndoRedo(op) {
|
|
4273
|
+
#applyInsertUndoRedo(op) {
|
|
4034
4274
|
const { id, parentKey: key } = op;
|
|
4035
4275
|
const child = creationOpToLiveNode(op);
|
|
4036
4276
|
if (_optionalChain([this, 'access', _60 => _60._pool, 'optionalAccess', _61 => _61.getNode, 'call', _62 => _62(id)]) !== void 0) {
|
|
@@ -4041,8 +4281,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4041
4281
|
const existingItemIndex = this._indexOfPosition(key);
|
|
4042
4282
|
let newKey = key;
|
|
4043
4283
|
if (existingItemIndex !== -1) {
|
|
4044
|
-
const before2 = _optionalChain([this, 'access', _63 => _63
|
|
4045
|
-
const after2 = _optionalChain([this, 'access', _66 => _66
|
|
4284
|
+
const before2 = _optionalChain([this, 'access', _63 => _63.#items, 'access', _64 => _64[existingItemIndex], 'optionalAccess', _65 => _65._parentPos]);
|
|
4285
|
+
const after2 = _optionalChain([this, 'access', _66 => _66.#items, 'access', _67 => _67[existingItemIndex + 1], 'optionalAccess', _68 => _68._parentPos]);
|
|
4046
4286
|
newKey = makePosition(before2, after2);
|
|
4047
4287
|
child._setParentLink(this, newKey);
|
|
4048
4288
|
}
|
|
@@ -4053,28 +4293,27 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4053
4293
|
reverse: [{ type: 5 /* DELETE_CRDT */, id }]
|
|
4054
4294
|
};
|
|
4055
4295
|
}
|
|
4056
|
-
|
|
4057
|
-
_applySetUndoRedo(op) {
|
|
4296
|
+
#applySetUndoRedo(op) {
|
|
4058
4297
|
const { id, parentKey: key } = op;
|
|
4059
4298
|
const child = creationOpToLiveNode(op);
|
|
4060
4299
|
if (_optionalChain([this, 'access', _69 => _69._pool, 'optionalAccess', _70 => _70.getNode, 'call', _71 => _71(id)]) !== void 0) {
|
|
4061
4300
|
return { modified: false };
|
|
4062
4301
|
}
|
|
4063
|
-
this.
|
|
4302
|
+
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
4064
4303
|
const indexOfItemWithSameKey = this._indexOfPosition(key);
|
|
4065
4304
|
child._attach(id, nn(this._pool));
|
|
4066
4305
|
child._setParentLink(this, key);
|
|
4067
4306
|
const newKey = key;
|
|
4068
4307
|
if (indexOfItemWithSameKey !== -1) {
|
|
4069
|
-
const existingItem = this
|
|
4308
|
+
const existingItem = this.#items[indexOfItemWithSameKey];
|
|
4070
4309
|
existingItem._detach();
|
|
4071
|
-
this
|
|
4310
|
+
this.#items[indexOfItemWithSameKey] = child;
|
|
4072
4311
|
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
4073
4312
|
existingItem._toOps(nn(this._id), key, this._pool),
|
|
4074
4313
|
op.id
|
|
4075
4314
|
);
|
|
4076
4315
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
4077
|
-
const deletedDelta = this
|
|
4316
|
+
const deletedDelta = this.#detachItemAssociatedToSetOperation(
|
|
4078
4317
|
op.deletedId
|
|
4079
4318
|
);
|
|
4080
4319
|
if (deletedDelta) {
|
|
@@ -4086,7 +4325,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4086
4325
|
};
|
|
4087
4326
|
} else {
|
|
4088
4327
|
this._insertAndSort(child);
|
|
4089
|
-
this
|
|
4328
|
+
this.#detachItemAssociatedToSetOperation(op.deletedId);
|
|
4090
4329
|
const newIndex = this._indexOfPosition(newKey);
|
|
4091
4330
|
return {
|
|
4092
4331
|
reverse: [{ type: 5 /* DELETE_CRDT */, id }],
|
|
@@ -4102,19 +4341,19 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4102
4341
|
let result;
|
|
4103
4342
|
if (op.intent === "set") {
|
|
4104
4343
|
if (source === 1 /* REMOTE */) {
|
|
4105
|
-
result = this
|
|
4344
|
+
result = this.#applySetRemote(op);
|
|
4106
4345
|
} else if (source === 2 /* ACK */) {
|
|
4107
|
-
result = this
|
|
4346
|
+
result = this.#applySetAck(op);
|
|
4108
4347
|
} else {
|
|
4109
|
-
result = this
|
|
4348
|
+
result = this.#applySetUndoRedo(op);
|
|
4110
4349
|
}
|
|
4111
4350
|
} else {
|
|
4112
4351
|
if (source === 1 /* REMOTE */) {
|
|
4113
|
-
result = this
|
|
4352
|
+
result = this.#applyRemoteInsert(op);
|
|
4114
4353
|
} else if (source === 2 /* ACK */) {
|
|
4115
|
-
result = this
|
|
4354
|
+
result = this.#applyInsertAck(op);
|
|
4116
4355
|
} else {
|
|
4117
|
-
result = this
|
|
4356
|
+
result = this.#applyInsertUndoRedo(op);
|
|
4118
4357
|
}
|
|
4119
4358
|
}
|
|
4120
4359
|
if (result.modified !== false) {
|
|
@@ -4127,13 +4366,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4127
4366
|
if (child) {
|
|
4128
4367
|
const parentKey = nn(child._parentKey);
|
|
4129
4368
|
const reverse = child._toOps(nn(this._id), parentKey, this._pool);
|
|
4130
|
-
const indexToDelete = this.
|
|
4369
|
+
const indexToDelete = this.#items.indexOf(child);
|
|
4131
4370
|
if (indexToDelete === -1) {
|
|
4132
4371
|
return {
|
|
4133
4372
|
modified: false
|
|
4134
4373
|
};
|
|
4135
4374
|
}
|
|
4136
|
-
const [previousNode] = this.
|
|
4375
|
+
const [previousNode] = this.#items.splice(indexToDelete, 1);
|
|
4137
4376
|
this.invalidate();
|
|
4138
4377
|
child._detach();
|
|
4139
4378
|
return {
|
|
@@ -4143,13 +4382,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4143
4382
|
}
|
|
4144
4383
|
return { modified: false };
|
|
4145
4384
|
}
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
this._implicitlyDeletedItems.delete(child);
|
|
4385
|
+
#applySetChildKeyRemote(newKey, child) {
|
|
4386
|
+
if (this.#implicitlyDeletedItems.has(child)) {
|
|
4387
|
+
this.#implicitlyDeletedItems.delete(child);
|
|
4150
4388
|
child._setParentLink(this, newKey);
|
|
4151
4389
|
this._insertAndSort(child);
|
|
4152
|
-
const newIndex = this.
|
|
4390
|
+
const newIndex = this.#items.indexOf(child);
|
|
4153
4391
|
return {
|
|
4154
4392
|
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
4155
4393
|
reverse: []
|
|
@@ -4163,10 +4401,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4163
4401
|
}
|
|
4164
4402
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
4165
4403
|
if (existingItemIndex === -1) {
|
|
4166
|
-
const previousIndex = this.
|
|
4404
|
+
const previousIndex = this.#items.indexOf(child);
|
|
4167
4405
|
child._setParentLink(this, newKey);
|
|
4168
4406
|
this._sortItems();
|
|
4169
|
-
const newIndex = this.
|
|
4407
|
+
const newIndex = this.#items.indexOf(child);
|
|
4170
4408
|
if (newIndex === previousIndex) {
|
|
4171
4409
|
return {
|
|
4172
4410
|
modified: false
|
|
@@ -4177,14 +4415,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4177
4415
|
reverse: []
|
|
4178
4416
|
};
|
|
4179
4417
|
} else {
|
|
4180
|
-
this
|
|
4418
|
+
this.#items[existingItemIndex]._setParentLink(
|
|
4181
4419
|
this,
|
|
4182
|
-
makePosition(newKey, _optionalChain([this, 'access', _72 => _72
|
|
4420
|
+
makePosition(newKey, _optionalChain([this, 'access', _72 => _72.#items, 'access', _73 => _73[existingItemIndex + 1], 'optionalAccess', _74 => _74._parentPos]))
|
|
4183
4421
|
);
|
|
4184
|
-
const previousIndex = this.
|
|
4422
|
+
const previousIndex = this.#items.indexOf(child);
|
|
4185
4423
|
child._setParentLink(this, newKey);
|
|
4186
4424
|
this._sortItems();
|
|
4187
|
-
const newIndex = this.
|
|
4425
|
+
const newIndex = this.#items.indexOf(child);
|
|
4188
4426
|
if (newIndex === previousIndex) {
|
|
4189
4427
|
return {
|
|
4190
4428
|
modified: false
|
|
@@ -4196,16 +4434,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4196
4434
|
};
|
|
4197
4435
|
}
|
|
4198
4436
|
}
|
|
4199
|
-
|
|
4200
|
-
_applySetChildKeyAck(newKey, child) {
|
|
4437
|
+
#applySetChildKeyAck(newKey, child) {
|
|
4201
4438
|
const previousKey = nn(child._parentKey);
|
|
4202
|
-
if (this.
|
|
4439
|
+
if (this.#implicitlyDeletedItems.has(child)) {
|
|
4203
4440
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
4204
|
-
this.
|
|
4441
|
+
this.#implicitlyDeletedItems.delete(child);
|
|
4205
4442
|
if (existingItemIndex !== -1) {
|
|
4206
|
-
this
|
|
4443
|
+
this.#items[existingItemIndex]._setParentLink(
|
|
4207
4444
|
this,
|
|
4208
|
-
makePosition(newKey, _optionalChain([this, 'access', _75 => _75
|
|
4445
|
+
makePosition(newKey, _optionalChain([this, 'access', _75 => _75.#items, 'access', _76 => _76[existingItemIndex + 1], 'optionalAccess', _77 => _77._parentPos]))
|
|
4209
4446
|
);
|
|
4210
4447
|
}
|
|
4211
4448
|
child._setParentLink(this, newKey);
|
|
@@ -4219,17 +4456,17 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4219
4456
|
modified: false
|
|
4220
4457
|
};
|
|
4221
4458
|
}
|
|
4222
|
-
const previousIndex = this.
|
|
4459
|
+
const previousIndex = this.#items.indexOf(child);
|
|
4223
4460
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
4224
4461
|
if (existingItemIndex !== -1) {
|
|
4225
|
-
this
|
|
4462
|
+
this.#items[existingItemIndex]._setParentLink(
|
|
4226
4463
|
this,
|
|
4227
|
-
makePosition(newKey, _optionalChain([this, 'access', _78 => _78
|
|
4464
|
+
makePosition(newKey, _optionalChain([this, 'access', _78 => _78.#items, 'access', _79 => _79[existingItemIndex + 1], 'optionalAccess', _80 => _80._parentPos]))
|
|
4228
4465
|
);
|
|
4229
4466
|
}
|
|
4230
4467
|
child._setParentLink(this, newKey);
|
|
4231
4468
|
this._sortItems();
|
|
4232
|
-
const newIndex = this.
|
|
4469
|
+
const newIndex = this.#items.indexOf(child);
|
|
4233
4470
|
if (previousIndex === newIndex) {
|
|
4234
4471
|
return {
|
|
4235
4472
|
modified: false
|
|
@@ -4244,20 +4481,19 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4244
4481
|
}
|
|
4245
4482
|
}
|
|
4246
4483
|
}
|
|
4247
|
-
|
|
4248
|
-
_applySetChildKeyUndoRedo(newKey, child) {
|
|
4484
|
+
#applySetChildKeyUndoRedo(newKey, child) {
|
|
4249
4485
|
const previousKey = nn(child._parentKey);
|
|
4250
|
-
const previousIndex = this.
|
|
4486
|
+
const previousIndex = this.#items.indexOf(child);
|
|
4251
4487
|
const existingItemIndex = this._indexOfPosition(newKey);
|
|
4252
4488
|
if (existingItemIndex !== -1) {
|
|
4253
|
-
this
|
|
4489
|
+
this.#items[existingItemIndex]._setParentLink(
|
|
4254
4490
|
this,
|
|
4255
|
-
makePosition(newKey, _optionalChain([this, 'access', _81 => _81
|
|
4491
|
+
makePosition(newKey, _optionalChain([this, 'access', _81 => _81.#items, 'access', _82 => _82[existingItemIndex + 1], 'optionalAccess', _83 => _83._parentPos]))
|
|
4256
4492
|
);
|
|
4257
4493
|
}
|
|
4258
4494
|
child._setParentLink(this, newKey);
|
|
4259
4495
|
this._sortItems();
|
|
4260
|
-
const newIndex = this.
|
|
4496
|
+
const newIndex = this.#items.indexOf(child);
|
|
4261
4497
|
if (previousIndex === newIndex) {
|
|
4262
4498
|
return {
|
|
4263
4499
|
modified: false
|
|
@@ -4277,11 +4513,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4277
4513
|
/** @internal */
|
|
4278
4514
|
_setChildKey(newKey, child, source) {
|
|
4279
4515
|
if (source === 1 /* REMOTE */) {
|
|
4280
|
-
return this
|
|
4516
|
+
return this.#applySetChildKeyRemote(newKey, child);
|
|
4281
4517
|
} else if (source === 2 /* ACK */) {
|
|
4282
|
-
return this
|
|
4518
|
+
return this.#applySetChildKeyAck(newKey, child);
|
|
4283
4519
|
} else {
|
|
4284
|
-
return this
|
|
4520
|
+
return this.#applySetChildKeyUndoRedo(newKey, child);
|
|
4285
4521
|
}
|
|
4286
4522
|
}
|
|
4287
4523
|
/** @internal */
|
|
@@ -4303,7 +4539,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4303
4539
|
* Returns the number of elements.
|
|
4304
4540
|
*/
|
|
4305
4541
|
get length() {
|
|
4306
|
-
return this.
|
|
4542
|
+
return this.#items.length;
|
|
4307
4543
|
}
|
|
4308
4544
|
/**
|
|
4309
4545
|
* Adds one element to the end of the LiveList.
|
|
@@ -4320,13 +4556,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4320
4556
|
*/
|
|
4321
4557
|
insert(element, index) {
|
|
4322
4558
|
_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.assertStorageIsWritable, 'call', _89 => _89()]);
|
|
4323
|
-
if (index < 0 || index > this.
|
|
4559
|
+
if (index < 0 || index > this.#items.length) {
|
|
4324
4560
|
throw new Error(
|
|
4325
|
-
`Cannot insert list item at index "${index}". index should be between 0 and ${this.
|
|
4561
|
+
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
4326
4562
|
);
|
|
4327
4563
|
}
|
|
4328
|
-
const before2 = this
|
|
4329
|
-
const after2 = this
|
|
4564
|
+
const before2 = this.#items[index - 1] ? this.#items[index - 1]._parentPos : void 0;
|
|
4565
|
+
const after2 = this.#items[index] ? this.#items[index]._parentPos : void 0;
|
|
4330
4566
|
const position = makePosition(before2, after2);
|
|
4331
4567
|
const value = lsonToLiveNode(element);
|
|
4332
4568
|
value._setParentLink(this, position);
|
|
@@ -4353,7 +4589,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4353
4589
|
if (targetIndex < 0) {
|
|
4354
4590
|
throw new Error("targetIndex cannot be less than 0");
|
|
4355
4591
|
}
|
|
4356
|
-
if (targetIndex >= this.
|
|
4592
|
+
if (targetIndex >= this.#items.length) {
|
|
4357
4593
|
throw new Error(
|
|
4358
4594
|
"targetIndex cannot be greater or equal than the list length"
|
|
4359
4595
|
);
|
|
@@ -4361,20 +4597,20 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4361
4597
|
if (index < 0) {
|
|
4362
4598
|
throw new Error("index cannot be less than 0");
|
|
4363
4599
|
}
|
|
4364
|
-
if (index >= this.
|
|
4600
|
+
if (index >= this.#items.length) {
|
|
4365
4601
|
throw new Error("index cannot be greater or equal than the list length");
|
|
4366
4602
|
}
|
|
4367
4603
|
let beforePosition = null;
|
|
4368
4604
|
let afterPosition = null;
|
|
4369
4605
|
if (index < targetIndex) {
|
|
4370
|
-
afterPosition = targetIndex === this.
|
|
4371
|
-
beforePosition = this
|
|
4606
|
+
afterPosition = targetIndex === this.#items.length - 1 ? void 0 : this.#items[targetIndex + 1]._parentPos;
|
|
4607
|
+
beforePosition = this.#items[targetIndex]._parentPos;
|
|
4372
4608
|
} else {
|
|
4373
|
-
afterPosition = this
|
|
4374
|
-
beforePosition = targetIndex === 0 ? void 0 : this
|
|
4609
|
+
afterPosition = this.#items[targetIndex]._parentPos;
|
|
4610
|
+
beforePosition = targetIndex === 0 ? void 0 : this.#items[targetIndex - 1]._parentPos;
|
|
4375
4611
|
}
|
|
4376
4612
|
const position = makePosition(beforePosition, afterPosition);
|
|
4377
|
-
const item = this
|
|
4613
|
+
const item = this.#items[index];
|
|
4378
4614
|
const previousPosition = item._getParentKeyOrThrow();
|
|
4379
4615
|
item._setParentLink(this, position);
|
|
4380
4616
|
this._sortItems();
|
|
@@ -4408,14 +4644,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4408
4644
|
*/
|
|
4409
4645
|
delete(index) {
|
|
4410
4646
|
_optionalChain([this, 'access', _93 => _93._pool, 'optionalAccess', _94 => _94.assertStorageIsWritable, 'call', _95 => _95()]);
|
|
4411
|
-
if (index < 0 || index >= this.
|
|
4647
|
+
if (index < 0 || index >= this.#items.length) {
|
|
4412
4648
|
throw new Error(
|
|
4413
|
-
`Cannot delete list item at index "${index}". index should be between 0 and ${this.
|
|
4649
|
+
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
4414
4650
|
);
|
|
4415
4651
|
}
|
|
4416
|
-
const item = this
|
|
4652
|
+
const item = this.#items[index];
|
|
4417
4653
|
item._detach();
|
|
4418
|
-
const [prev] = this.
|
|
4654
|
+
const [prev] = this.#items.splice(index, 1);
|
|
4419
4655
|
this.invalidate();
|
|
4420
4656
|
if (this._pool) {
|
|
4421
4657
|
const childRecordId = item._id;
|
|
@@ -4445,7 +4681,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4445
4681
|
const ops = [];
|
|
4446
4682
|
const reverseOps = [];
|
|
4447
4683
|
const updateDelta = [];
|
|
4448
|
-
for (const item of this
|
|
4684
|
+
for (const item of this.#items) {
|
|
4449
4685
|
item._detach();
|
|
4450
4686
|
const childId = item._id;
|
|
4451
4687
|
if (childId) {
|
|
@@ -4460,33 +4696,33 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4460
4696
|
updateDelta.push(deleteDelta(0, item));
|
|
4461
4697
|
}
|
|
4462
4698
|
}
|
|
4463
|
-
this
|
|
4699
|
+
this.#items = [];
|
|
4464
4700
|
this.invalidate();
|
|
4465
4701
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
4466
4702
|
storageUpdates.set(nn(this._id), makeUpdate(this, updateDelta));
|
|
4467
4703
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
4468
4704
|
} else {
|
|
4469
|
-
for (const item of this
|
|
4705
|
+
for (const item of this.#items) {
|
|
4470
4706
|
item._detach();
|
|
4471
4707
|
}
|
|
4472
|
-
this
|
|
4708
|
+
this.#items = [];
|
|
4473
4709
|
this.invalidate();
|
|
4474
4710
|
}
|
|
4475
4711
|
}
|
|
4476
4712
|
set(index, item) {
|
|
4477
4713
|
_optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.assertStorageIsWritable, 'call', _101 => _101()]);
|
|
4478
|
-
if (index < 0 || index >= this.
|
|
4714
|
+
if (index < 0 || index >= this.#items.length) {
|
|
4479
4715
|
throw new Error(
|
|
4480
|
-
`Cannot set list item at index "${index}". index should be between 0 and ${this.
|
|
4716
|
+
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
4481
4717
|
);
|
|
4482
4718
|
}
|
|
4483
|
-
const existingItem = this
|
|
4719
|
+
const existingItem = this.#items[index];
|
|
4484
4720
|
const position = existingItem._getParentKeyOrThrow();
|
|
4485
4721
|
const existingId = existingItem._id;
|
|
4486
4722
|
existingItem._detach();
|
|
4487
4723
|
const value = lsonToLiveNode(item);
|
|
4488
4724
|
value._setParentLink(this, position);
|
|
4489
|
-
this
|
|
4725
|
+
this.#items[index] = value;
|
|
4490
4726
|
this.invalidate();
|
|
4491
4727
|
if (this._pool && this._id) {
|
|
4492
4728
|
const id = this._pool.generateId();
|
|
@@ -4497,7 +4733,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4497
4733
|
value._toOps(this._id, position, this._pool),
|
|
4498
4734
|
existingId
|
|
4499
4735
|
);
|
|
4500
|
-
this.
|
|
4736
|
+
this.#unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
4501
4737
|
const reverseOps = HACK_addIntentAndDeletedIdToOperation(
|
|
4502
4738
|
existingItem._toOps(this._id, position, void 0),
|
|
4503
4739
|
id
|
|
@@ -4509,7 +4745,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4509
4745
|
* Returns an Array of all the elements in the LiveList.
|
|
4510
4746
|
*/
|
|
4511
4747
|
toArray() {
|
|
4512
|
-
return this.
|
|
4748
|
+
return this.#items.map(
|
|
4513
4749
|
(entry) => liveNodeToLson(entry)
|
|
4514
4750
|
// ^^^^^^^^
|
|
4515
4751
|
// FIXME! This isn't safe.
|
|
@@ -4560,10 +4796,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4560
4796
|
* @returns The element at the specified index or undefined.
|
|
4561
4797
|
*/
|
|
4562
4798
|
get(index) {
|
|
4563
|
-
if (index < 0 || index >= this.
|
|
4799
|
+
if (index < 0 || index >= this.#items.length) {
|
|
4564
4800
|
return void 0;
|
|
4565
4801
|
}
|
|
4566
|
-
return liveNodeToLson(this
|
|
4802
|
+
return liveNodeToLson(this.#items[index]);
|
|
4567
4803
|
}
|
|
4568
4804
|
/**
|
|
4569
4805
|
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
@@ -4589,7 +4825,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4589
4825
|
* @returns An array with each element being the result of the callback function.
|
|
4590
4826
|
*/
|
|
4591
4827
|
map(callback) {
|
|
4592
|
-
return this.
|
|
4828
|
+
return this.#items.map(
|
|
4593
4829
|
(entry, i) => callback(
|
|
4594
4830
|
liveNodeToLson(entry),
|
|
4595
4831
|
// ^^^^^^^^
|
|
@@ -4607,10 +4843,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4607
4843
|
return this.toArray().some(predicate);
|
|
4608
4844
|
}
|
|
4609
4845
|
[Symbol.iterator]() {
|
|
4610
|
-
return new LiveListIterator(this
|
|
4846
|
+
return new LiveListIterator(this.#items);
|
|
4611
4847
|
}
|
|
4612
|
-
|
|
4613
|
-
_createAttachItemAndSort(op, key) {
|
|
4848
|
+
#createAttachItemAndSort(op, key) {
|
|
4614
4849
|
const newItem = creationOpToLiveNode(op);
|
|
4615
4850
|
newItem._attach(op.id, nn(this._pool));
|
|
4616
4851
|
newItem._setParentLink(this, key);
|
|
@@ -4618,13 +4853,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4618
4853
|
const newIndex = this._indexOfPosition(key);
|
|
4619
4854
|
return { newItem, newIndex };
|
|
4620
4855
|
}
|
|
4621
|
-
|
|
4622
|
-
_shiftItemPosition(index, key) {
|
|
4856
|
+
#shiftItemPosition(index, key) {
|
|
4623
4857
|
const shiftedPosition = makePosition(
|
|
4624
4858
|
key,
|
|
4625
|
-
this.
|
|
4859
|
+
this.#items.length > index + 1 ? _optionalChain([this, 'access', _102 => _102.#items, 'access', _103 => _103[index + 1], 'optionalAccess', _104 => _104._parentPos]) : void 0
|
|
4626
4860
|
);
|
|
4627
|
-
this
|
|
4861
|
+
this.#items[index]._setParentLink(this, shiftedPosition);
|
|
4628
4862
|
}
|
|
4629
4863
|
/** @internal */
|
|
4630
4864
|
_toTreeNode(key) {
|
|
@@ -4632,7 +4866,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4632
4866
|
type: "LiveList",
|
|
4633
4867
|
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
4634
4868
|
key,
|
|
4635
|
-
payload: this.
|
|
4869
|
+
payload: this.#items.map(
|
|
4636
4870
|
(item, index) => item.toTreeNode(index.toString())
|
|
4637
4871
|
)
|
|
4638
4872
|
};
|
|
@@ -4642,22 +4876,23 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
4642
4876
|
}
|
|
4643
4877
|
/** @internal */
|
|
4644
4878
|
_toImmutable() {
|
|
4645
|
-
const result = this.
|
|
4879
|
+
const result = this.#items.map((node) => node.toImmutable());
|
|
4646
4880
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
4647
4881
|
}
|
|
4648
4882
|
clone() {
|
|
4649
|
-
return new _LiveList(this.
|
|
4883
|
+
return new _LiveList(this.#items.map((item) => item.clone()));
|
|
4650
4884
|
}
|
|
4651
4885
|
};
|
|
4652
4886
|
var LiveListIterator = class {
|
|
4887
|
+
#innerIterator;
|
|
4653
4888
|
constructor(items) {
|
|
4654
|
-
this
|
|
4889
|
+
this.#innerIterator = items[Symbol.iterator]();
|
|
4655
4890
|
}
|
|
4656
4891
|
[Symbol.iterator]() {
|
|
4657
4892
|
return this;
|
|
4658
4893
|
}
|
|
4659
4894
|
next() {
|
|
4660
|
-
const result = this.
|
|
4895
|
+
const result = this.#innerIterator.next();
|
|
4661
4896
|
if (result.done) {
|
|
4662
4897
|
return {
|
|
4663
4898
|
done: true,
|
|
@@ -4721,9 +4956,11 @@ function HACK_addIntentAndDeletedIdToOperation(ops, deletedId) {
|
|
|
4721
4956
|
|
|
4722
4957
|
// src/crdts/LiveMap.ts
|
|
4723
4958
|
var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
4959
|
+
#map;
|
|
4960
|
+
#unacknowledgedSet;
|
|
4724
4961
|
constructor(entries2) {
|
|
4725
4962
|
super();
|
|
4726
|
-
this
|
|
4963
|
+
this.#unacknowledgedSet = /* @__PURE__ */ new Map();
|
|
4727
4964
|
if (entries2) {
|
|
4728
4965
|
const mappedEntries = [];
|
|
4729
4966
|
for (const [key, value] of entries2) {
|
|
@@ -4731,14 +4968,12 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4731
4968
|
node._setParentLink(this, key);
|
|
4732
4969
|
mappedEntries.push([key, node]);
|
|
4733
4970
|
}
|
|
4734
|
-
this
|
|
4971
|
+
this.#map = new Map(mappedEntries);
|
|
4735
4972
|
} else {
|
|
4736
|
-
this
|
|
4973
|
+
this.#map = /* @__PURE__ */ new Map();
|
|
4737
4974
|
}
|
|
4738
4975
|
}
|
|
4739
|
-
/**
|
|
4740
|
-
* @internal
|
|
4741
|
-
*/
|
|
4976
|
+
/** @internal */
|
|
4742
4977
|
_toOps(parentId, parentKey, pool) {
|
|
4743
4978
|
if (this._id === void 0) {
|
|
4744
4979
|
throw new Error("Cannot serialize item is not attached");
|
|
@@ -4752,14 +4987,12 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4752
4987
|
parentKey
|
|
4753
4988
|
};
|
|
4754
4989
|
ops.push(op);
|
|
4755
|
-
for (const [key, value] of this
|
|
4990
|
+
for (const [key, value] of this.#map) {
|
|
4756
4991
|
ops.push(...value._toOps(this._id, key, pool));
|
|
4757
4992
|
}
|
|
4758
4993
|
return ops;
|
|
4759
4994
|
}
|
|
4760
|
-
/**
|
|
4761
|
-
* @internal
|
|
4762
|
-
*/
|
|
4995
|
+
/** @internal */
|
|
4763
4996
|
static _deserialize([id, _item], parentToChildren, pool) {
|
|
4764
4997
|
const map = new _LiveMap();
|
|
4765
4998
|
map._attach(id, pool);
|
|
@@ -4770,25 +5003,21 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4770
5003
|
for (const [id2, crdt] of children) {
|
|
4771
5004
|
const child = deserialize([id2, crdt], parentToChildren, pool);
|
|
4772
5005
|
child._setParentLink(map, crdt.parentKey);
|
|
4773
|
-
map.
|
|
5006
|
+
map.#map.set(crdt.parentKey, child);
|
|
4774
5007
|
map.invalidate();
|
|
4775
5008
|
}
|
|
4776
5009
|
return map;
|
|
4777
5010
|
}
|
|
4778
|
-
/**
|
|
4779
|
-
* @internal
|
|
4780
|
-
*/
|
|
5011
|
+
/** @internal */
|
|
4781
5012
|
_attach(id, pool) {
|
|
4782
5013
|
super._attach(id, pool);
|
|
4783
|
-
for (const [_key, value] of this
|
|
5014
|
+
for (const [_key, value] of this.#map) {
|
|
4784
5015
|
if (isLiveNode(value)) {
|
|
4785
5016
|
value._attach(pool.generateId(), pool);
|
|
4786
5017
|
}
|
|
4787
5018
|
}
|
|
4788
5019
|
}
|
|
4789
|
-
/**
|
|
4790
|
-
* @internal
|
|
4791
|
-
*/
|
|
5020
|
+
/** @internal */
|
|
4792
5021
|
_attachChild(op, source) {
|
|
4793
5022
|
if (this._pool === void 0) {
|
|
4794
5023
|
throw new Error("Can't attach child if managed pool is not present");
|
|
@@ -4800,17 +5029,17 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4800
5029
|
return { modified: false };
|
|
4801
5030
|
}
|
|
4802
5031
|
if (source === 2 /* ACK */) {
|
|
4803
|
-
const lastUpdateOpId = this
|
|
5032
|
+
const lastUpdateOpId = this.#unacknowledgedSet.get(key);
|
|
4804
5033
|
if (lastUpdateOpId === opId) {
|
|
4805
|
-
this
|
|
5034
|
+
this.#unacknowledgedSet.delete(key);
|
|
4806
5035
|
return { modified: false };
|
|
4807
5036
|
} else if (lastUpdateOpId !== void 0) {
|
|
4808
5037
|
return { modified: false };
|
|
4809
5038
|
}
|
|
4810
5039
|
} else if (source === 1 /* REMOTE */) {
|
|
4811
|
-
this
|
|
5040
|
+
this.#unacknowledgedSet.delete(key);
|
|
4812
5041
|
}
|
|
4813
|
-
const previousValue = this.
|
|
5042
|
+
const previousValue = this.#map.get(key);
|
|
4814
5043
|
let reverse;
|
|
4815
5044
|
if (previousValue) {
|
|
4816
5045
|
const thisId = nn(this._id);
|
|
@@ -4821,7 +5050,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4821
5050
|
}
|
|
4822
5051
|
child._setParentLink(this, key);
|
|
4823
5052
|
child._attach(id, this._pool);
|
|
4824
|
-
this.
|
|
5053
|
+
this.#map.set(key, child);
|
|
4825
5054
|
this.invalidate();
|
|
4826
5055
|
return {
|
|
4827
5056
|
modified: {
|
|
@@ -4832,25 +5061,21 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4832
5061
|
reverse
|
|
4833
5062
|
};
|
|
4834
5063
|
}
|
|
4835
|
-
/**
|
|
4836
|
-
* @internal
|
|
4837
|
-
*/
|
|
5064
|
+
/** @internal */
|
|
4838
5065
|
_detach() {
|
|
4839
5066
|
super._detach();
|
|
4840
|
-
for (const item of this.
|
|
5067
|
+
for (const item of this.#map.values()) {
|
|
4841
5068
|
item._detach();
|
|
4842
5069
|
}
|
|
4843
5070
|
}
|
|
4844
|
-
/**
|
|
4845
|
-
* @internal
|
|
4846
|
-
*/
|
|
5071
|
+
/** @internal */
|
|
4847
5072
|
_detachChild(child) {
|
|
4848
5073
|
const id = nn(this._id);
|
|
4849
5074
|
const parentKey = nn(child._parentKey);
|
|
4850
5075
|
const reverse = child._toOps(id, parentKey, this._pool);
|
|
4851
|
-
for (const [key, value] of this
|
|
5076
|
+
for (const [key, value] of this.#map) {
|
|
4852
5077
|
if (value === child) {
|
|
4853
|
-
this.
|
|
5078
|
+
this.#map.delete(key);
|
|
4854
5079
|
this.invalidate();
|
|
4855
5080
|
}
|
|
4856
5081
|
}
|
|
@@ -4862,9 +5087,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4862
5087
|
};
|
|
4863
5088
|
return { modified: storageUpdate, reverse };
|
|
4864
5089
|
}
|
|
4865
|
-
/**
|
|
4866
|
-
* @internal
|
|
4867
|
-
*/
|
|
5090
|
+
/** @internal */
|
|
4868
5091
|
_serialize() {
|
|
4869
5092
|
if (this.parent.type !== "HasParent") {
|
|
4870
5093
|
throw new Error("Cannot serialize LiveMap if parent is missing");
|
|
@@ -4881,7 +5104,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4881
5104
|
* @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
|
|
4882
5105
|
*/
|
|
4883
5106
|
get(key) {
|
|
4884
|
-
const value = this.
|
|
5107
|
+
const value = this.#map.get(key);
|
|
4885
5108
|
if (value === void 0) {
|
|
4886
5109
|
return void 0;
|
|
4887
5110
|
}
|
|
@@ -4894,13 +5117,13 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4894
5117
|
*/
|
|
4895
5118
|
set(key, value) {
|
|
4896
5119
|
_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.assertStorageIsWritable, 'call', _109 => _109()]);
|
|
4897
|
-
const oldValue = this.
|
|
5120
|
+
const oldValue = this.#map.get(key);
|
|
4898
5121
|
if (oldValue) {
|
|
4899
5122
|
oldValue._detach();
|
|
4900
5123
|
}
|
|
4901
5124
|
const item = lsonToLiveNode(value);
|
|
4902
5125
|
item._setParentLink(this, key);
|
|
4903
|
-
this.
|
|
5126
|
+
this.#map.set(key, item);
|
|
4904
5127
|
this.invalidate();
|
|
4905
5128
|
if (this._pool && this._id) {
|
|
4906
5129
|
const id = this._pool.generateId();
|
|
@@ -4912,7 +5135,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4912
5135
|
updates: { [key]: { type: "update" } }
|
|
4913
5136
|
});
|
|
4914
5137
|
const ops = item._toOps(this._id, key, this._pool);
|
|
4915
|
-
this
|
|
5138
|
+
this.#unacknowledgedSet.set(key, nn(ops[0].opId));
|
|
4916
5139
|
this._pool.dispatch(
|
|
4917
5140
|
item._toOps(this._id, key, this._pool),
|
|
4918
5141
|
oldValue ? oldValue._toOps(this._id, key) : [{ type: 5 /* DELETE_CRDT */, id }],
|
|
@@ -4924,14 +5147,14 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4924
5147
|
* Returns the number of elements in the LiveMap.
|
|
4925
5148
|
*/
|
|
4926
5149
|
get size() {
|
|
4927
|
-
return this.
|
|
5150
|
+
return this.#map.size;
|
|
4928
5151
|
}
|
|
4929
5152
|
/**
|
|
4930
5153
|
* Returns a boolean indicating whether an element with the specified key exists or not.
|
|
4931
5154
|
* @param key The key of the element to test for presence.
|
|
4932
5155
|
*/
|
|
4933
5156
|
has(key) {
|
|
4934
|
-
return this.
|
|
5157
|
+
return this.#map.has(key);
|
|
4935
5158
|
}
|
|
4936
5159
|
/**
|
|
4937
5160
|
* Removes the specified element by key.
|
|
@@ -4940,12 +5163,12 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4940
5163
|
*/
|
|
4941
5164
|
delete(key) {
|
|
4942
5165
|
_optionalChain([this, 'access', _110 => _110._pool, 'optionalAccess', _111 => _111.assertStorageIsWritable, 'call', _112 => _112()]);
|
|
4943
|
-
const item = this.
|
|
5166
|
+
const item = this.#map.get(key);
|
|
4944
5167
|
if (item === void 0) {
|
|
4945
5168
|
return false;
|
|
4946
5169
|
}
|
|
4947
5170
|
item._detach();
|
|
4948
|
-
this.
|
|
5171
|
+
this.#map.delete(key);
|
|
4949
5172
|
this.invalidate();
|
|
4950
5173
|
if (this._pool && item._id) {
|
|
4951
5174
|
const thisId = nn(this._id);
|
|
@@ -4973,7 +5196,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
4973
5196
|
* Returns a new Iterator object that contains the [key, value] pairs for each element.
|
|
4974
5197
|
*/
|
|
4975
5198
|
entries() {
|
|
4976
|
-
const innerIterator = this.
|
|
5199
|
+
const innerIterator = this.#map.entries();
|
|
4977
5200
|
return {
|
|
4978
5201
|
[Symbol.iterator]() {
|
|
4979
5202
|
return this;
|
|
@@ -5005,13 +5228,13 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5005
5228
|
* Returns a new Iterator object that contains the keys for each element.
|
|
5006
5229
|
*/
|
|
5007
5230
|
keys() {
|
|
5008
|
-
return this.
|
|
5231
|
+
return this.#map.keys();
|
|
5009
5232
|
}
|
|
5010
5233
|
/**
|
|
5011
5234
|
* Returns a new Iterator object that contains the values for each element.
|
|
5012
5235
|
*/
|
|
5013
5236
|
values() {
|
|
5014
|
-
const innerIterator = this.
|
|
5237
|
+
const innerIterator = this.#map.values();
|
|
5015
5238
|
return {
|
|
5016
5239
|
[Symbol.iterator]() {
|
|
5017
5240
|
return this;
|
|
@@ -5044,7 +5267,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5044
5267
|
type: "LiveMap",
|
|
5045
5268
|
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
5046
5269
|
key,
|
|
5047
|
-
payload: Array.from(this.
|
|
5270
|
+
payload: Array.from(this.#map.entries()).map(
|
|
5048
5271
|
([key2, val]) => val.toTreeNode(key2)
|
|
5049
5272
|
)
|
|
5050
5273
|
};
|
|
@@ -5055,22 +5278,23 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
5055
5278
|
/** @internal */
|
|
5056
5279
|
_toImmutable() {
|
|
5057
5280
|
const result = /* @__PURE__ */ new Map();
|
|
5058
|
-
for (const [key, value] of this
|
|
5281
|
+
for (const [key, value] of this.#map) {
|
|
5059
5282
|
result.set(key, value.toImmutable());
|
|
5060
5283
|
}
|
|
5061
5284
|
return freeze(result);
|
|
5062
5285
|
}
|
|
5063
5286
|
clone() {
|
|
5064
5287
|
return new _LiveMap(
|
|
5065
|
-
Array.from(this
|
|
5288
|
+
Array.from(this.#map).map(([key, node]) => [key, node.clone()])
|
|
5066
5289
|
);
|
|
5067
5290
|
}
|
|
5068
5291
|
};
|
|
5069
5292
|
|
|
5070
5293
|
// src/crdts/LiveObject.ts
|
|
5071
5294
|
var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
5072
|
-
|
|
5073
|
-
|
|
5295
|
+
#map;
|
|
5296
|
+
#propToLastUpdate;
|
|
5297
|
+
static #buildRootAndParentToChildren(items) {
|
|
5074
5298
|
const parentToChildren = /* @__PURE__ */ new Map();
|
|
5075
5299
|
let root = null;
|
|
5076
5300
|
for (const [id, crdt] of items) {
|
|
@@ -5093,7 +5317,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5093
5317
|
}
|
|
5094
5318
|
/** @internal */
|
|
5095
5319
|
static _fromItems(items, pool) {
|
|
5096
|
-
const [root, parentToChildren] = _LiveObject
|
|
5320
|
+
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(items);
|
|
5097
5321
|
return _LiveObject._deserialize(
|
|
5098
5322
|
root,
|
|
5099
5323
|
parentToChildren,
|
|
@@ -5102,7 +5326,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5102
5326
|
}
|
|
5103
5327
|
constructor(obj = {}) {
|
|
5104
5328
|
super();
|
|
5105
|
-
this
|
|
5329
|
+
this.#propToLastUpdate = /* @__PURE__ */ new Map();
|
|
5106
5330
|
const o = compactObject(obj);
|
|
5107
5331
|
for (const key of Object.keys(o)) {
|
|
5108
5332
|
const value = o[key];
|
|
@@ -5110,7 +5334,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5110
5334
|
value._setParentLink(this, key);
|
|
5111
5335
|
}
|
|
5112
5336
|
}
|
|
5113
|
-
this
|
|
5337
|
+
this.#map = new Map(Object.entries(o));
|
|
5114
5338
|
}
|
|
5115
5339
|
/** @internal */
|
|
5116
5340
|
_toOps(parentId, parentKey, pool) {
|
|
@@ -5128,7 +5352,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5128
5352
|
data: {}
|
|
5129
5353
|
};
|
|
5130
5354
|
ops.push(op);
|
|
5131
|
-
for (const [key, value] of this
|
|
5355
|
+
for (const [key, value] of this.#map) {
|
|
5132
5356
|
if (isLiveNode(value)) {
|
|
5133
5357
|
ops.push(...value._toOps(this._id, key, pool));
|
|
5134
5358
|
} else {
|
|
@@ -5154,7 +5378,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5154
5378
|
if (isLiveStructure(child)) {
|
|
5155
5379
|
child._setParentLink(liveObj, crdt.parentKey);
|
|
5156
5380
|
}
|
|
5157
|
-
liveObj.
|
|
5381
|
+
liveObj.#map.set(crdt.parentKey, child);
|
|
5158
5382
|
liveObj.invalidate();
|
|
5159
5383
|
}
|
|
5160
5384
|
return liveObj;
|
|
@@ -5162,7 +5386,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5162
5386
|
/** @internal */
|
|
5163
5387
|
_attach(id, pool) {
|
|
5164
5388
|
super._attach(id, pool);
|
|
5165
|
-
for (const [_key, value] of this
|
|
5389
|
+
for (const [_key, value] of this.#map) {
|
|
5166
5390
|
if (isLiveNode(value)) {
|
|
5167
5391
|
value._attach(pool.generateId(), pool);
|
|
5168
5392
|
}
|
|
@@ -5176,22 +5400,22 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5176
5400
|
const { id, opId, parentKey: key } = op;
|
|
5177
5401
|
const child = creationOpToLson(op);
|
|
5178
5402
|
if (this._pool.getNode(id) !== void 0) {
|
|
5179
|
-
if (this.
|
|
5180
|
-
this.
|
|
5403
|
+
if (this.#propToLastUpdate.get(key) === opId) {
|
|
5404
|
+
this.#propToLastUpdate.delete(key);
|
|
5181
5405
|
}
|
|
5182
5406
|
return { modified: false };
|
|
5183
5407
|
}
|
|
5184
5408
|
if (source === 0 /* UNDOREDO_RECONNECT */) {
|
|
5185
|
-
this.
|
|
5186
|
-
} else if (this.
|
|
5187
|
-
} else if (this.
|
|
5188
|
-
this.
|
|
5409
|
+
this.#propToLastUpdate.set(key, nn(opId));
|
|
5410
|
+
} else if (this.#propToLastUpdate.get(key) === void 0) {
|
|
5411
|
+
} else if (this.#propToLastUpdate.get(key) === opId) {
|
|
5412
|
+
this.#propToLastUpdate.delete(key);
|
|
5189
5413
|
return { modified: false };
|
|
5190
5414
|
} else {
|
|
5191
5415
|
return { modified: false };
|
|
5192
5416
|
}
|
|
5193
5417
|
const thisId = nn(this._id);
|
|
5194
|
-
const previousValue = this.
|
|
5418
|
+
const previousValue = this.#map.get(key);
|
|
5195
5419
|
let reverse;
|
|
5196
5420
|
if (isLiveNode(previousValue)) {
|
|
5197
5421
|
reverse = previousValue._toOps(thisId, key);
|
|
@@ -5207,7 +5431,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5207
5431
|
}
|
|
5208
5432
|
];
|
|
5209
5433
|
}
|
|
5210
|
-
this.
|
|
5434
|
+
this.#map.set(key, child);
|
|
5211
5435
|
this.invalidate();
|
|
5212
5436
|
if (isLiveStructure(child)) {
|
|
5213
5437
|
child._setParentLink(this, key);
|
|
@@ -5228,9 +5452,9 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5228
5452
|
const id = nn(this._id);
|
|
5229
5453
|
const parentKey = nn(child._parentKey);
|
|
5230
5454
|
const reverse = child._toOps(id, parentKey, this._pool);
|
|
5231
|
-
for (const [key, value] of this
|
|
5455
|
+
for (const [key, value] of this.#map) {
|
|
5232
5456
|
if (value === child) {
|
|
5233
|
-
this.
|
|
5457
|
+
this.#map.delete(key);
|
|
5234
5458
|
this.invalidate();
|
|
5235
5459
|
}
|
|
5236
5460
|
}
|
|
@@ -5246,12 +5470,10 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5246
5470
|
}
|
|
5247
5471
|
return { modified: false };
|
|
5248
5472
|
}
|
|
5249
|
-
/**
|
|
5250
|
-
* @internal
|
|
5251
|
-
*/
|
|
5473
|
+
/** @internal */
|
|
5252
5474
|
_detach() {
|
|
5253
5475
|
super._detach();
|
|
5254
|
-
for (const value of this.
|
|
5476
|
+
for (const value of this.#map.values()) {
|
|
5255
5477
|
if (isLiveNode(value)) {
|
|
5256
5478
|
value._detach();
|
|
5257
5479
|
}
|
|
@@ -5260,18 +5482,16 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5260
5482
|
/** @internal */
|
|
5261
5483
|
_apply(op, isLocal) {
|
|
5262
5484
|
if (op.type === 3 /* UPDATE_OBJECT */) {
|
|
5263
|
-
return this
|
|
5485
|
+
return this.#applyUpdate(op, isLocal);
|
|
5264
5486
|
} else if (op.type === 6 /* DELETE_OBJECT_KEY */) {
|
|
5265
|
-
return this
|
|
5487
|
+
return this.#applyDeleteObjectKey(op, isLocal);
|
|
5266
5488
|
}
|
|
5267
5489
|
return super._apply(op, isLocal);
|
|
5268
5490
|
}
|
|
5269
|
-
/**
|
|
5270
|
-
* @internal
|
|
5271
|
-
*/
|
|
5491
|
+
/** @internal */
|
|
5272
5492
|
_serialize() {
|
|
5273
5493
|
const data = {};
|
|
5274
|
-
for (const [key, value] of this
|
|
5494
|
+
for (const [key, value] of this.#map) {
|
|
5275
5495
|
if (!isLiveNode(value)) {
|
|
5276
5496
|
data[key] = value;
|
|
5277
5497
|
}
|
|
@@ -5290,8 +5510,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5290
5510
|
};
|
|
5291
5511
|
}
|
|
5292
5512
|
}
|
|
5293
|
-
|
|
5294
|
-
_applyUpdate(op, isLocal) {
|
|
5513
|
+
#applyUpdate(op, isLocal) {
|
|
5295
5514
|
let isModified = false;
|
|
5296
5515
|
const id = nn(this._id);
|
|
5297
5516
|
const reverse = [];
|
|
@@ -5301,7 +5520,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5301
5520
|
data: {}
|
|
5302
5521
|
};
|
|
5303
5522
|
for (const key in op.data) {
|
|
5304
|
-
const oldValue = this.
|
|
5523
|
+
const oldValue = this.#map.get(key);
|
|
5305
5524
|
if (isLiveNode(oldValue)) {
|
|
5306
5525
|
reverse.push(...oldValue._toOps(id, key));
|
|
5307
5526
|
oldValue._detach();
|
|
@@ -5318,22 +5537,22 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5318
5537
|
continue;
|
|
5319
5538
|
}
|
|
5320
5539
|
if (isLocal) {
|
|
5321
|
-
this.
|
|
5322
|
-
} else if (this.
|
|
5540
|
+
this.#propToLastUpdate.set(key, nn(op.opId));
|
|
5541
|
+
} else if (this.#propToLastUpdate.get(key) === void 0) {
|
|
5323
5542
|
isModified = true;
|
|
5324
|
-
} else if (this.
|
|
5325
|
-
this.
|
|
5543
|
+
} else if (this.#propToLastUpdate.get(key) === op.opId) {
|
|
5544
|
+
this.#propToLastUpdate.delete(key);
|
|
5326
5545
|
continue;
|
|
5327
5546
|
} else {
|
|
5328
5547
|
continue;
|
|
5329
5548
|
}
|
|
5330
|
-
const oldValue = this.
|
|
5549
|
+
const oldValue = this.#map.get(key);
|
|
5331
5550
|
if (isLiveNode(oldValue)) {
|
|
5332
5551
|
oldValue._detach();
|
|
5333
5552
|
}
|
|
5334
5553
|
isModified = true;
|
|
5335
5554
|
updateDelta[key] = { type: "update" };
|
|
5336
|
-
this.
|
|
5555
|
+
this.#map.set(key, value);
|
|
5337
5556
|
this.invalidate();
|
|
5338
5557
|
}
|
|
5339
5558
|
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
@@ -5348,16 +5567,15 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5348
5567
|
reverse
|
|
5349
5568
|
} : { modified: false };
|
|
5350
5569
|
}
|
|
5351
|
-
|
|
5352
|
-
_applyDeleteObjectKey(op, isLocal) {
|
|
5570
|
+
#applyDeleteObjectKey(op, isLocal) {
|
|
5353
5571
|
const key = op.key;
|
|
5354
|
-
if (this.
|
|
5572
|
+
if (this.#map.has(key) === false) {
|
|
5355
5573
|
return { modified: false };
|
|
5356
5574
|
}
|
|
5357
|
-
if (!isLocal && this.
|
|
5575
|
+
if (!isLocal && this.#propToLastUpdate.get(key) !== void 0) {
|
|
5358
5576
|
return { modified: false };
|
|
5359
5577
|
}
|
|
5360
|
-
const oldValue = this.
|
|
5578
|
+
const oldValue = this.#map.get(key);
|
|
5361
5579
|
const id = nn(this._id);
|
|
5362
5580
|
let reverse = [];
|
|
5363
5581
|
if (isLiveNode(oldValue)) {
|
|
@@ -5372,7 +5590,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5372
5590
|
}
|
|
5373
5591
|
];
|
|
5374
5592
|
}
|
|
5375
|
-
this.
|
|
5593
|
+
this.#map.delete(key);
|
|
5376
5594
|
this.invalidate();
|
|
5377
5595
|
return {
|
|
5378
5596
|
modified: {
|
|
@@ -5387,7 +5605,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5387
5605
|
* Transform the LiveObject into a javascript object
|
|
5388
5606
|
*/
|
|
5389
5607
|
toObject() {
|
|
5390
|
-
return Object.fromEntries(this
|
|
5608
|
+
return Object.fromEntries(this.#map);
|
|
5391
5609
|
}
|
|
5392
5610
|
/**
|
|
5393
5611
|
* Adds or updates a property with a specified key and a value.
|
|
@@ -5403,7 +5621,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5403
5621
|
* @param key The key of the property to get
|
|
5404
5622
|
*/
|
|
5405
5623
|
get(key) {
|
|
5406
|
-
return this.
|
|
5624
|
+
return this.#map.get(key);
|
|
5407
5625
|
}
|
|
5408
5626
|
/**
|
|
5409
5627
|
* Deletes a key from the LiveObject
|
|
@@ -5412,7 +5630,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5412
5630
|
delete(key) {
|
|
5413
5631
|
_optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.assertStorageIsWritable, 'call', _120 => _120()]);
|
|
5414
5632
|
const keyAsString = key;
|
|
5415
|
-
const oldValue = this.
|
|
5633
|
+
const oldValue = this.#map.get(keyAsString);
|
|
5416
5634
|
if (oldValue === void 0) {
|
|
5417
5635
|
return;
|
|
5418
5636
|
}
|
|
@@ -5420,7 +5638,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5420
5638
|
if (isLiveNode(oldValue)) {
|
|
5421
5639
|
oldValue._detach();
|
|
5422
5640
|
}
|
|
5423
|
-
this.
|
|
5641
|
+
this.#map.delete(keyAsString);
|
|
5424
5642
|
this.invalidate();
|
|
5425
5643
|
return;
|
|
5426
5644
|
}
|
|
@@ -5437,7 +5655,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5437
5655
|
}
|
|
5438
5656
|
];
|
|
5439
5657
|
}
|
|
5440
|
-
this.
|
|
5658
|
+
this.#map.delete(keyAsString);
|
|
5441
5659
|
this.invalidate();
|
|
5442
5660
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
5443
5661
|
storageUpdates.set(this._id, {
|
|
@@ -5470,14 +5688,14 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5470
5688
|
if (newValue === void 0) {
|
|
5471
5689
|
continue;
|
|
5472
5690
|
}
|
|
5473
|
-
const oldValue = this.
|
|
5691
|
+
const oldValue = this.#map.get(key);
|
|
5474
5692
|
if (isLiveNode(oldValue)) {
|
|
5475
5693
|
oldValue._detach();
|
|
5476
5694
|
}
|
|
5477
5695
|
if (isLiveNode(newValue)) {
|
|
5478
5696
|
newValue._setParentLink(this, key);
|
|
5479
5697
|
}
|
|
5480
|
-
this.
|
|
5698
|
+
this.#map.set(key, newValue);
|
|
5481
5699
|
this.invalidate();
|
|
5482
5700
|
}
|
|
5483
5701
|
return;
|
|
@@ -5497,7 +5715,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5497
5715
|
if (newValue === void 0) {
|
|
5498
5716
|
continue;
|
|
5499
5717
|
}
|
|
5500
|
-
const oldValue = this.
|
|
5718
|
+
const oldValue = this.#map.get(key);
|
|
5501
5719
|
if (isLiveNode(oldValue)) {
|
|
5502
5720
|
reverseOps.push(...oldValue._toOps(this._id, key));
|
|
5503
5721
|
oldValue._detach();
|
|
@@ -5514,14 +5732,14 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5514
5732
|
(op) => op.parentId === this._id
|
|
5515
5733
|
);
|
|
5516
5734
|
if (createCrdtOp) {
|
|
5517
|
-
this.
|
|
5735
|
+
this.#propToLastUpdate.set(key, nn(createCrdtOp.opId));
|
|
5518
5736
|
}
|
|
5519
5737
|
ops.push(...newAttachChildOps);
|
|
5520
5738
|
} else {
|
|
5521
5739
|
updatedProps[key] = newValue;
|
|
5522
|
-
this.
|
|
5740
|
+
this.#propToLastUpdate.set(key, opId);
|
|
5523
5741
|
}
|
|
5524
|
-
this.
|
|
5742
|
+
this.#map.set(key, newValue);
|
|
5525
5743
|
this.invalidate();
|
|
5526
5744
|
updateDelta[key] = { type: "update" };
|
|
5527
5745
|
}
|
|
@@ -5558,7 +5776,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5558
5776
|
type: "LiveObject",
|
|
5559
5777
|
id: nodeId,
|
|
5560
5778
|
key,
|
|
5561
|
-
payload: Array.from(this.
|
|
5779
|
+
payload: Array.from(this.#map.entries()).map(
|
|
5562
5780
|
([key2, value]) => isLiveNode(value) ? value.toTreeNode(key2) : { type: "Json", id: `${nodeId}:${key2}`, key: key2, payload: value }
|
|
5563
5781
|
)
|
|
5564
5782
|
};
|
|
@@ -5566,7 +5784,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5566
5784
|
/** @internal */
|
|
5567
5785
|
_toImmutable() {
|
|
5568
5786
|
const result = {};
|
|
5569
|
-
for (const [key, val] of this
|
|
5787
|
+
for (const [key, val] of this.#map) {
|
|
5570
5788
|
result[key] = isLiveStructure(val) ? val.toImmutable() : val;
|
|
5571
5789
|
}
|
|
5572
5790
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
@@ -5574,7 +5792,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
5574
5792
|
clone() {
|
|
5575
5793
|
return new _LiveObject(
|
|
5576
5794
|
Object.fromEntries(
|
|
5577
|
-
Array.from(this
|
|
5795
|
+
Array.from(this.#map).map(([key, value]) => [
|
|
5578
5796
|
key,
|
|
5579
5797
|
isLiveStructure(value) ? value.clone() : deepClone(value)
|
|
5580
5798
|
])
|
|
@@ -5868,7 +6086,7 @@ var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
|
|
|
5868
6086
|
return ClientMsgCode2;
|
|
5869
6087
|
})(ClientMsgCode || {});
|
|
5870
6088
|
|
|
5871
|
-
// src/refs/
|
|
6089
|
+
// src/refs/ManagedOthers.ts
|
|
5872
6090
|
function makeUser(conn, presence) {
|
|
5873
6091
|
const { connectionId, id, info } = conn;
|
|
5874
6092
|
const canWrite = canWriteStorage(conn.scopes);
|
|
@@ -5885,98 +6103,110 @@ function makeUser(conn, presence) {
|
|
|
5885
6103
|
})
|
|
5886
6104
|
);
|
|
5887
6105
|
}
|
|
5888
|
-
var
|
|
5889
|
-
//
|
|
5890
|
-
//
|
|
5891
|
-
|
|
6106
|
+
var ManagedOthers = class {
|
|
6107
|
+
// Track mutable state internally, but signal to the outside when the
|
|
6108
|
+
// observable derived state changes only
|
|
6109
|
+
#internal;
|
|
6110
|
+
#userCache;
|
|
6111
|
+
// The "clean" signal that is exposed to the outside world
|
|
6112
|
+
|
|
5892
6113
|
constructor() {
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
const users = compact(
|
|
5904
|
-
Array.from(this._presences.keys()).map(
|
|
5905
|
-
(connectionId) => this.getUser(Number(connectionId))
|
|
6114
|
+
this.#internal = new MutableSignal({
|
|
6115
|
+
connections: /* @__PURE__ */ new Map(),
|
|
6116
|
+
presences: /* @__PURE__ */ new Map()
|
|
6117
|
+
});
|
|
6118
|
+
this.signal = DerivedSignal.from(
|
|
6119
|
+
this.#internal,
|
|
6120
|
+
(_ignore) => compact(
|
|
6121
|
+
Array.from(this.#internal.get().presences.keys()).map(
|
|
6122
|
+
(connectionId) => this.getUser(Number(connectionId))
|
|
6123
|
+
)
|
|
5906
6124
|
)
|
|
5907
6125
|
);
|
|
5908
|
-
|
|
6126
|
+
this.#userCache = /* @__PURE__ */ new Map();
|
|
6127
|
+
}
|
|
6128
|
+
// Shorthand for .signal.get()
|
|
6129
|
+
get() {
|
|
6130
|
+
return this.signal.get();
|
|
6131
|
+
}
|
|
6132
|
+
connectionIds() {
|
|
6133
|
+
return this.#internal.get().connections.keys();
|
|
5909
6134
|
}
|
|
5910
6135
|
clearOthers() {
|
|
5911
|
-
this.
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
6136
|
+
this.#internal.mutate((state) => {
|
|
6137
|
+
state.connections.clear();
|
|
6138
|
+
state.presences.clear();
|
|
6139
|
+
this.#userCache.clear();
|
|
6140
|
+
});
|
|
5915
6141
|
}
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
const conn =
|
|
5919
|
-
const presence =
|
|
6142
|
+
#_getUser(connectionId) {
|
|
6143
|
+
const state = this.#internal.get();
|
|
6144
|
+
const conn = state.connections.get(connectionId);
|
|
6145
|
+
const presence = state.presences.get(connectionId);
|
|
5920
6146
|
if (conn !== void 0 && presence !== void 0) {
|
|
5921
6147
|
return makeUser(conn, presence);
|
|
5922
6148
|
}
|
|
5923
6149
|
return void 0;
|
|
5924
6150
|
}
|
|
5925
6151
|
getUser(connectionId) {
|
|
5926
|
-
const cachedUser = this.
|
|
6152
|
+
const cachedUser = this.#userCache.get(connectionId);
|
|
5927
6153
|
if (cachedUser) {
|
|
5928
6154
|
return cachedUser;
|
|
5929
6155
|
}
|
|
5930
|
-
const computedUser = this
|
|
6156
|
+
const computedUser = this.#_getUser(connectionId);
|
|
5931
6157
|
if (computedUser) {
|
|
5932
|
-
this.
|
|
6158
|
+
this.#userCache.set(connectionId, computedUser);
|
|
5933
6159
|
return computedUser;
|
|
5934
6160
|
}
|
|
5935
6161
|
return void 0;
|
|
5936
6162
|
}
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
if (this._users.has(connectionId)) {
|
|
5940
|
-
this._users.delete(connectionId);
|
|
5941
|
-
}
|
|
5942
|
-
this.invalidate();
|
|
6163
|
+
#invalidateUser(connectionId) {
|
|
6164
|
+
this.#userCache.delete(connectionId);
|
|
5943
6165
|
}
|
|
5944
6166
|
/**
|
|
5945
6167
|
* Records a known connection. This records the connection ID and the
|
|
5946
6168
|
* associated metadata.
|
|
5947
6169
|
*/
|
|
5948
6170
|
setConnection(connectionId, metaUserId, metaUserInfo, scopes) {
|
|
5949
|
-
this.
|
|
5950
|
-
|
|
5951
|
-
freeze({
|
|
6171
|
+
this.#internal.mutate((state) => {
|
|
6172
|
+
state.connections.set(
|
|
5952
6173
|
connectionId,
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
6174
|
+
freeze({
|
|
6175
|
+
connectionId,
|
|
6176
|
+
id: metaUserId,
|
|
6177
|
+
info: metaUserInfo,
|
|
6178
|
+
scopes
|
|
6179
|
+
})
|
|
6180
|
+
);
|
|
6181
|
+
if (!state.presences.has(connectionId)) {
|
|
6182
|
+
return false;
|
|
6183
|
+
}
|
|
6184
|
+
return this.#invalidateUser(connectionId);
|
|
6185
|
+
});
|
|
5961
6186
|
}
|
|
5962
6187
|
/**
|
|
5963
6188
|
* Removes a known connectionId. Removes both the connection's metadata and
|
|
5964
6189
|
* the presence information.
|
|
5965
6190
|
*/
|
|
5966
6191
|
removeConnection(connectionId) {
|
|
5967
|
-
this.
|
|
5968
|
-
|
|
5969
|
-
|
|
6192
|
+
this.#internal.mutate((state) => {
|
|
6193
|
+
state.connections.delete(connectionId);
|
|
6194
|
+
state.presences.delete(connectionId);
|
|
6195
|
+
this.#invalidateUser(connectionId);
|
|
6196
|
+
});
|
|
5970
6197
|
}
|
|
5971
6198
|
/**
|
|
5972
6199
|
* Stores a new user from a full presence update. If the user already exists,
|
|
5973
6200
|
* its known presence data is overwritten.
|
|
5974
6201
|
*/
|
|
5975
6202
|
setOther(connectionId, presence) {
|
|
5976
|
-
this.
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
6203
|
+
this.#internal.mutate((state) => {
|
|
6204
|
+
state.presences.set(connectionId, freeze(compactObject(presence)));
|
|
6205
|
+
if (!state.connections.has(connectionId)) {
|
|
6206
|
+
return false;
|
|
6207
|
+
}
|
|
6208
|
+
return this.#invalidateUser(connectionId);
|
|
6209
|
+
});
|
|
5980
6210
|
}
|
|
5981
6211
|
/**
|
|
5982
6212
|
* Patches the presence data for an existing "other". If we don't know the
|
|
@@ -5984,38 +6214,18 @@ var OthersRef = class extends ImmutableRef {
|
|
|
5984
6214
|
* full .setOther() call first.
|
|
5985
6215
|
*/
|
|
5986
6216
|
patchOther(connectionId, patch) {
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
// src/refs/PatchableRef.ts
|
|
6000
|
-
var PatchableRef = class extends ImmutableRef {
|
|
6001
|
-
constructor(data) {
|
|
6002
|
-
super();
|
|
6003
|
-
this._data = freeze(compactObject(data));
|
|
6004
|
-
}
|
|
6005
|
-
/** @internal */
|
|
6006
|
-
_toImmutable() {
|
|
6007
|
-
return this._data;
|
|
6008
|
-
}
|
|
6009
|
-
/**
|
|
6010
|
-
* Patches the current object.
|
|
6011
|
-
*/
|
|
6012
|
-
patch(patch) {
|
|
6013
|
-
const oldData = this._data;
|
|
6014
|
-
const newData = merge(oldData, patch);
|
|
6015
|
-
if (oldData !== newData) {
|
|
6016
|
-
this._data = freeze(newData);
|
|
6017
|
-
this.invalidate();
|
|
6018
|
-
}
|
|
6217
|
+
this.#internal.mutate((state) => {
|
|
6218
|
+
const oldPresence = state.presences.get(connectionId);
|
|
6219
|
+
if (oldPresence === void 0) {
|
|
6220
|
+
return false;
|
|
6221
|
+
}
|
|
6222
|
+
const newPresence = merge(oldPresence, patch);
|
|
6223
|
+
if (oldPresence === newPresence) {
|
|
6224
|
+
return false;
|
|
6225
|
+
}
|
|
6226
|
+
state.presences.set(connectionId, freeze(newPresence));
|
|
6227
|
+
return this.#invalidateUser(connectionId);
|
|
6228
|
+
});
|
|
6019
6229
|
}
|
|
6020
6230
|
};
|
|
6021
6231
|
|
|
@@ -6092,10 +6302,10 @@ function createRoom(options, config) {
|
|
|
6092
6302
|
messages: [],
|
|
6093
6303
|
storageOperations: []
|
|
6094
6304
|
},
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
myPresence: new
|
|
6098
|
-
others: new
|
|
6305
|
+
staticSessionInfoSig: new Signal(null),
|
|
6306
|
+
dynamicSessionInfoSig: new Signal(null),
|
|
6307
|
+
myPresence: new PatchableSignal(initialPresence),
|
|
6308
|
+
others: new ManagedOthers(),
|
|
6099
6309
|
initialStorage,
|
|
6100
6310
|
idFactory: null,
|
|
6101
6311
|
// The Yjs provider associated to this room
|
|
@@ -6125,12 +6335,12 @@ function createRoom(options, config) {
|
|
|
6125
6335
|
lastTokenKey = tokenKey;
|
|
6126
6336
|
if (authValue.type === "secret") {
|
|
6127
6337
|
const token = authValue.token.parsed;
|
|
6128
|
-
context.
|
|
6338
|
+
context.staticSessionInfoSig.set({
|
|
6129
6339
|
userId: token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid,
|
|
6130
6340
|
userInfo: token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.info : token.ui
|
|
6131
6341
|
});
|
|
6132
6342
|
} else {
|
|
6133
|
-
context.
|
|
6343
|
+
context.staticSessionInfoSig.set({
|
|
6134
6344
|
userId: void 0,
|
|
6135
6345
|
userInfo: void 0
|
|
6136
6346
|
});
|
|
@@ -6177,7 +6387,7 @@ function createRoom(options, config) {
|
|
|
6177
6387
|
// Because context.me.current is a readonly object, we'll have to
|
|
6178
6388
|
// make a copy here. Otherwise, type errors happen later when
|
|
6179
6389
|
// "patching" my presence.
|
|
6180
|
-
{ ...context.myPresence.
|
|
6390
|
+
{ ...context.myPresence.get() }
|
|
6181
6391
|
)
|
|
6182
6392
|
};
|
|
6183
6393
|
if (_getStorage$ !== null) {
|
|
@@ -6246,7 +6456,7 @@ function createRoom(options, config) {
|
|
|
6246
6456
|
}
|
|
6247
6457
|
},
|
|
6248
6458
|
assertStorageIsWritable: () => {
|
|
6249
|
-
const scopes = _optionalChain([context, 'access', _129 => _129.
|
|
6459
|
+
const scopes = _optionalChain([context, 'access', _129 => _129.dynamicSessionInfoSig, 'access', _130 => _130.get, 'call', _131 => _131(), 'optionalAccess', _132 => _132.scopes]);
|
|
6250
6460
|
if (scopes === void 0) {
|
|
6251
6461
|
return;
|
|
6252
6462
|
}
|
|
@@ -6302,7 +6512,7 @@ function createRoom(options, config) {
|
|
|
6302
6512
|
}
|
|
6303
6513
|
function sendMessages(messages) {
|
|
6304
6514
|
const serializedPayload = JSON.stringify(messages);
|
|
6305
|
-
const nonce = _optionalChain([context, 'access',
|
|
6515
|
+
const nonce = _optionalChain([context, 'access', _133 => _133.dynamicSessionInfoSig, 'access', _134 => _134.get, 'call', _135 => _135(), 'optionalAccess', _136 => _136.nonce]);
|
|
6306
6516
|
if (config.unstable_fallbackToHTTP && nonce) {
|
|
6307
6517
|
const size = new TextEncoder().encode(serializedPayload).length;
|
|
6308
6518
|
if (size > MAX_SOCKET_MESSAGE_SIZE) {
|
|
@@ -6319,9 +6529,9 @@ function createRoom(options, config) {
|
|
|
6319
6529
|
}
|
|
6320
6530
|
managedSocket.send(serializedPayload);
|
|
6321
6531
|
}
|
|
6322
|
-
const self =
|
|
6323
|
-
context.
|
|
6324
|
-
context.
|
|
6532
|
+
const self = DerivedSignal.from(
|
|
6533
|
+
context.staticSessionInfoSig,
|
|
6534
|
+
context.dynamicSessionInfoSig,
|
|
6325
6535
|
context.myPresence,
|
|
6326
6536
|
(staticSession, dynamicSession, myPresence) => {
|
|
6327
6537
|
if (staticSession === null || dynamicSession === null) {
|
|
@@ -6341,7 +6551,7 @@ function createRoom(options, config) {
|
|
|
6341
6551
|
);
|
|
6342
6552
|
let _lastSelf;
|
|
6343
6553
|
function notifySelfChanged(batchedUpdatesWrapper) {
|
|
6344
|
-
const currSelf = self.
|
|
6554
|
+
const currSelf = self.get();
|
|
6345
6555
|
if (currSelf !== null && currSelf !== _lastSelf) {
|
|
6346
6556
|
batchedUpdatesWrapper(() => {
|
|
6347
6557
|
eventHub.self.notify(currSelf);
|
|
@@ -6349,7 +6559,7 @@ function createRoom(options, config) {
|
|
|
6349
6559
|
_lastSelf = currSelf;
|
|
6350
6560
|
}
|
|
6351
6561
|
}
|
|
6352
|
-
const selfAsTreeNode =
|
|
6562
|
+
const selfAsTreeNode = DerivedSignal.from(
|
|
6353
6563
|
self,
|
|
6354
6564
|
(me) => me !== null ? userToTreeNode("Me", me) : null
|
|
6355
6565
|
);
|
|
@@ -6362,7 +6572,7 @@ function createRoom(options, config) {
|
|
|
6362
6572
|
} else {
|
|
6363
6573
|
context.root = LiveObject._fromItems(message.items, pool);
|
|
6364
6574
|
}
|
|
6365
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
6575
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _137 => _137.get, 'call', _138 => _138(), 'optionalAccess', _139 => _139.canWrite]), () => ( true));
|
|
6366
6576
|
const stackSizeBefore = context.undoStack.length;
|
|
6367
6577
|
for (const key in context.initialStorage) {
|
|
6368
6578
|
if (context.root.get(key) === void 0) {
|
|
@@ -6408,14 +6618,14 @@ function createRoom(options, config) {
|
|
|
6408
6618
|
const othersUpdates = updates.others;
|
|
6409
6619
|
batchedUpdatesWrapper(() => {
|
|
6410
6620
|
if (othersUpdates !== void 0 && othersUpdates.length > 0) {
|
|
6411
|
-
const others = context.others.
|
|
6621
|
+
const others = context.others.get();
|
|
6412
6622
|
for (const event of othersUpdates) {
|
|
6413
6623
|
eventHub.others.notify({ ...event, others });
|
|
6414
6624
|
}
|
|
6415
6625
|
}
|
|
6416
6626
|
if (_nullishCoalesce(updates.presence, () => ( false))) {
|
|
6417
6627
|
notifySelfChanged(doNotBatchUpdates);
|
|
6418
|
-
eventHub.myPresence.notify(context.myPresence.
|
|
6628
|
+
eventHub.myPresence.notify(context.myPresence.get());
|
|
6419
6629
|
}
|
|
6420
6630
|
if (storageUpdates !== void 0 && storageUpdates.size > 0) {
|
|
6421
6631
|
const updates2 = Array.from(storageUpdates.values());
|
|
@@ -6425,7 +6635,7 @@ function createRoom(options, config) {
|
|
|
6425
6635
|
});
|
|
6426
6636
|
}
|
|
6427
6637
|
function getConnectionId() {
|
|
6428
|
-
const info = context.
|
|
6638
|
+
const info = context.dynamicSessionInfoSig.get();
|
|
6429
6639
|
if (info) {
|
|
6430
6640
|
return info.actor;
|
|
6431
6641
|
}
|
|
@@ -6454,7 +6664,7 @@ function createRoom(options, config) {
|
|
|
6454
6664
|
data: {}
|
|
6455
6665
|
};
|
|
6456
6666
|
for (const key in op.data) {
|
|
6457
|
-
reverse.data[key] = context.myPresence.
|
|
6667
|
+
reverse.data[key] = context.myPresence.get()[key];
|
|
6458
6668
|
}
|
|
6459
6669
|
context.myPresence.patch(op.data);
|
|
6460
6670
|
if (context.buffer.presenceUpdates === null) {
|
|
@@ -6563,11 +6773,11 @@ function createRoom(options, config) {
|
|
|
6563
6773
|
continue;
|
|
6564
6774
|
}
|
|
6565
6775
|
context.buffer.presenceUpdates.data[key] = overrideValue;
|
|
6566
|
-
oldValues[key] = context.myPresence.
|
|
6776
|
+
oldValues[key] = context.myPresence.get()[key];
|
|
6567
6777
|
}
|
|
6568
6778
|
context.myPresence.patch(patch);
|
|
6569
6779
|
if (context.activeBatch) {
|
|
6570
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
6780
|
+
if (_optionalChain([options2, 'optionalAccess', _140 => _140.addToHistory])) {
|
|
6571
6781
|
context.activeBatch.reverseOps.unshift({
|
|
6572
6782
|
type: "presence",
|
|
6573
6783
|
data: oldValues
|
|
@@ -6577,7 +6787,7 @@ function createRoom(options, config) {
|
|
|
6577
6787
|
} else {
|
|
6578
6788
|
flushNowOrSoon();
|
|
6579
6789
|
batchUpdates(() => {
|
|
6580
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
6790
|
+
if (_optionalChain([options2, 'optionalAccess', _141 => _141.addToHistory])) {
|
|
6581
6791
|
addToUndoStack(
|
|
6582
6792
|
[{ type: "presence", data: oldValues }],
|
|
6583
6793
|
doNotBatchUpdates
|
|
@@ -6618,7 +6828,7 @@ function createRoom(options, config) {
|
|
|
6618
6828
|
return null;
|
|
6619
6829
|
}
|
|
6620
6830
|
function onRoomStateMessage(message, batchedUpdatesWrapper) {
|
|
6621
|
-
context.
|
|
6831
|
+
context.dynamicSessionInfoSig.set({
|
|
6622
6832
|
actor: message.actor,
|
|
6623
6833
|
nonce: message.nonce,
|
|
6624
6834
|
scopes: message.scopes
|
|
@@ -6663,7 +6873,7 @@ function createRoom(options, config) {
|
|
|
6663
6873
|
);
|
|
6664
6874
|
context.buffer.messages.push({
|
|
6665
6875
|
type: 100 /* UPDATE_PRESENCE */,
|
|
6666
|
-
data: context.myPresence.
|
|
6876
|
+
data: context.myPresence.get(),
|
|
6667
6877
|
targetActor: message.actor
|
|
6668
6878
|
});
|
|
6669
6879
|
flushNowOrSoon();
|
|
@@ -6730,7 +6940,7 @@ function createRoom(options, config) {
|
|
|
6730
6940
|
break;
|
|
6731
6941
|
}
|
|
6732
6942
|
case 103 /* BROADCASTED_EVENT */: {
|
|
6733
|
-
const others = context.others.
|
|
6943
|
+
const others = context.others.get();
|
|
6734
6944
|
eventHub.customEvent.notify({
|
|
6735
6945
|
connectionId: message.actor,
|
|
6736
6946
|
user: message.actor < 0 ? null : _nullishCoalesce(others.find((u) => u.connectionId === message.actor), () => ( null)),
|
|
@@ -6775,7 +6985,7 @@ function createRoom(options, config) {
|
|
|
6775
6985
|
if (process.env.NODE_ENV !== "production") {
|
|
6776
6986
|
const traces = /* @__PURE__ */ new Set();
|
|
6777
6987
|
for (const opId of message.opIds) {
|
|
6778
|
-
const trace = _optionalChain([context, 'access',
|
|
6988
|
+
const trace = _optionalChain([context, 'access', _142 => _142.opStackTraces, 'optionalAccess', _143 => _143.get, 'call', _144 => _144(opId)]);
|
|
6779
6989
|
if (trace) {
|
|
6780
6990
|
traces.add(trace);
|
|
6781
6991
|
}
|
|
@@ -6874,11 +7084,12 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6874
7084
|
}
|
|
6875
7085
|
return messages;
|
|
6876
7086
|
}
|
|
6877
|
-
function updateYDoc(update, guid) {
|
|
7087
|
+
function updateYDoc(update, guid, isV2) {
|
|
6878
7088
|
const clientMsg = {
|
|
6879
7089
|
type: 301 /* UPDATE_YDOC */,
|
|
6880
7090
|
update,
|
|
6881
|
-
guid
|
|
7091
|
+
guid,
|
|
7092
|
+
v2: isV2
|
|
6882
7093
|
};
|
|
6883
7094
|
context.buffer.messages.push(clientMsg);
|
|
6884
7095
|
eventHub.ydoc.notify(clientMsg);
|
|
@@ -6909,7 +7120,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6909
7120
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
6910
7121
|
createOrUpdateRootFromMessage(message, doNotBatchUpdates);
|
|
6911
7122
|
applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
|
|
6912
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
7123
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _145 => _145()]);
|
|
6913
7124
|
notifyStorageStatus();
|
|
6914
7125
|
eventHub.storageDidLoad.notify();
|
|
6915
7126
|
}
|
|
@@ -6959,14 +7170,15 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6959
7170
|
root: nn(context.root)
|
|
6960
7171
|
};
|
|
6961
7172
|
}
|
|
6962
|
-
function fetchYDoc(vector, guid) {
|
|
7173
|
+
function fetchYDoc(vector, guid, isV2) {
|
|
6963
7174
|
if (!context.buffer.messages.find((m) => {
|
|
6964
|
-
return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid;
|
|
7175
|
+
return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid && m.v2 === isV2;
|
|
6965
7176
|
})) {
|
|
6966
7177
|
context.buffer.messages.push({
|
|
6967
7178
|
type: 300 /* FETCH_YDOC */,
|
|
6968
7179
|
vector,
|
|
6969
|
-
guid
|
|
7180
|
+
guid,
|
|
7181
|
+
v2: isV2
|
|
6970
7182
|
});
|
|
6971
7183
|
}
|
|
6972
7184
|
flushNowOrSoon();
|
|
@@ -7019,7 +7231,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7019
7231
|
context.undoStack.length = 0;
|
|
7020
7232
|
context.redoStack.length = 0;
|
|
7021
7233
|
}
|
|
7022
|
-
function
|
|
7234
|
+
function batch2(callback) {
|
|
7023
7235
|
if (context.activeBatch) {
|
|
7024
7236
|
return callback();
|
|
7025
7237
|
}
|
|
@@ -7086,7 +7298,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7086
7298
|
);
|
|
7087
7299
|
}
|
|
7088
7300
|
function isPresenceReady() {
|
|
7089
|
-
return self.
|
|
7301
|
+
return self.get() !== null;
|
|
7090
7302
|
}
|
|
7091
7303
|
async function waitUntilPresenceReady() {
|
|
7092
7304
|
while (!isPresenceReady()) {
|
|
@@ -7106,8 +7318,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7106
7318
|
await getStorage();
|
|
7107
7319
|
}
|
|
7108
7320
|
}
|
|
7109
|
-
const others_forDevTools =
|
|
7110
|
-
context.others,
|
|
7321
|
+
const others_forDevTools = DerivedSignal.from(
|
|
7322
|
+
context.others.signal,
|
|
7111
7323
|
(others) => others.map((other, index) => userToTreeNode(`Other ${index}`, other))
|
|
7112
7324
|
);
|
|
7113
7325
|
const events = {
|
|
@@ -7137,8 +7349,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7137
7349
|
async function getThreads(options2) {
|
|
7138
7350
|
return httpClient.getThreads({
|
|
7139
7351
|
roomId,
|
|
7140
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
7141
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
7352
|
+
query: _optionalChain([options2, 'optionalAccess', _146 => _146.query]),
|
|
7353
|
+
cursor: _optionalChain([options2, 'optionalAccess', _147 => _147.cursor])
|
|
7142
7354
|
});
|
|
7143
7355
|
}
|
|
7144
7356
|
async function getThread(threadId) {
|
|
@@ -7239,7 +7451,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7239
7451
|
function getNotificationSettings(options2) {
|
|
7240
7452
|
return httpClient.getNotificationSettings({
|
|
7241
7453
|
roomId,
|
|
7242
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
7454
|
+
signal: _optionalChain([options2, 'optionalAccess', _148 => _148.signal])
|
|
7243
7455
|
});
|
|
7244
7456
|
}
|
|
7245
7457
|
function updateNotificationSettings(settings) {
|
|
@@ -7261,7 +7473,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7261
7473
|
{
|
|
7262
7474
|
[kInternal]: {
|
|
7263
7475
|
get presenceBuffer() {
|
|
7264
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
7476
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _149 => _149.buffer, 'access', _150 => _150.presenceUpdates, 'optionalAccess', _151 => _151.data]), () => ( null)));
|
|
7265
7477
|
},
|
|
7266
7478
|
// prettier-ignore
|
|
7267
7479
|
get undoStack() {
|
|
@@ -7276,9 +7488,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7276
7488
|
return context.yjsProvider;
|
|
7277
7489
|
},
|
|
7278
7490
|
setYjsProvider(newProvider) {
|
|
7279
|
-
_optionalChain([context, 'access',
|
|
7491
|
+
_optionalChain([context, 'access', _152 => _152.yjsProvider, 'optionalAccess', _153 => _153.off, 'call', _154 => _154("status", yjsStatusDidChange)]);
|
|
7280
7492
|
context.yjsProvider = newProvider;
|
|
7281
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
7493
|
+
_optionalChain([newProvider, 'optionalAccess', _155 => _155.on, 'call', _156 => _156("status", yjsStatusDidChange)]);
|
|
7282
7494
|
context.yjsProviderDidChange.notify();
|
|
7283
7495
|
},
|
|
7284
7496
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -7297,8 +7509,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7297
7509
|
// create a version
|
|
7298
7510
|
createTextVersion,
|
|
7299
7511
|
// Support for the Liveblocks browser extension
|
|
7300
|
-
getSelf_forDevTools: () => selfAsTreeNode.
|
|
7301
|
-
getOthers_forDevTools: () => others_forDevTools.
|
|
7512
|
+
getSelf_forDevTools: () => selfAsTreeNode.get(),
|
|
7513
|
+
getOthers_forDevTools: () => others_forDevTools.get(),
|
|
7302
7514
|
// prettier-ignore
|
|
7303
7515
|
simulate: {
|
|
7304
7516
|
// These exist only for our E2E testing app
|
|
@@ -7314,7 +7526,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7314
7526
|
disconnect: () => managedSocket.disconnect(),
|
|
7315
7527
|
destroy: () => {
|
|
7316
7528
|
syncSourceForStorage.destroy();
|
|
7317
|
-
_optionalChain([context, 'access',
|
|
7529
|
+
_optionalChain([context, 'access', _157 => _157.yjsProvider, 'optionalAccess', _158 => _158.off, 'call', _159 => _159("status", yjsStatusDidChange)]);
|
|
7318
7530
|
syncSourceForYjs.destroy();
|
|
7319
7531
|
uninstallBgTabSpy();
|
|
7320
7532
|
managedSocket.destroy();
|
|
@@ -7324,7 +7536,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7324
7536
|
updateYDoc,
|
|
7325
7537
|
broadcastEvent,
|
|
7326
7538
|
// Storage
|
|
7327
|
-
batch,
|
|
7539
|
+
batch: batch2,
|
|
7328
7540
|
history: {
|
|
7329
7541
|
undo,
|
|
7330
7542
|
redo,
|
|
@@ -7345,10 +7557,10 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
7345
7557
|
events,
|
|
7346
7558
|
// Core
|
|
7347
7559
|
getStatus: () => managedSocket.getStatus(),
|
|
7348
|
-
getSelf: () => self.
|
|
7560
|
+
getSelf: () => self.get(),
|
|
7349
7561
|
// Presence
|
|
7350
|
-
getPresence: () => context.myPresence.
|
|
7351
|
-
getOthers: () => context.others.
|
|
7562
|
+
getPresence: () => context.myPresence.get(),
|
|
7563
|
+
getOthers: () => context.others.get(),
|
|
7352
7564
|
// Comments
|
|
7353
7565
|
getThreads,
|
|
7354
7566
|
getThreadsSince,
|
|
@@ -7452,7 +7664,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
7452
7664
|
}
|
|
7453
7665
|
if (isLiveNode(first)) {
|
|
7454
7666
|
const node = first;
|
|
7455
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
7667
|
+
if (_optionalChain([options, 'optionalAccess', _160 => _160.isDeep])) {
|
|
7456
7668
|
const storageCallback = second;
|
|
7457
7669
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
7458
7670
|
} else {
|
|
@@ -7531,8 +7743,8 @@ function createClient(options) {
|
|
|
7531
7743
|
const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
|
|
7532
7744
|
currentUserIdStore.set(() => userId);
|
|
7533
7745
|
});
|
|
7534
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
7535
|
-
_optionalChain([globalThis, 'access',
|
|
7746
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _161 => _161.polyfills, 'optionalAccess', _162 => _162.fetch]) || /* istanbul ignore next */
|
|
7747
|
+
_optionalChain([globalThis, 'access', _163 => _163.fetch, 'optionalAccess', _164 => _164.bind, 'call', _165 => _165(globalThis)]);
|
|
7536
7748
|
const httpClient = createApiClient({
|
|
7537
7749
|
baseUrl,
|
|
7538
7750
|
fetchPolyfill,
|
|
@@ -7583,12 +7795,12 @@ function createClient(options) {
|
|
|
7583
7795
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
7584
7796
|
roomId,
|
|
7585
7797
|
baseUrl,
|
|
7586
|
-
_optionalChain([clientOptions, 'access',
|
|
7798
|
+
_optionalChain([clientOptions, 'access', _166 => _166.polyfills, 'optionalAccess', _167 => _167.WebSocket])
|
|
7587
7799
|
),
|
|
7588
7800
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
7589
7801
|
})),
|
|
7590
7802
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
7591
|
-
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess',
|
|
7803
|
+
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _168 => _168.unstable_batchedUpdates]),
|
|
7592
7804
|
baseUrl,
|
|
7593
7805
|
unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
|
|
7594
7806
|
unstable_streamData: !!clientOptions.unstable_streamData,
|
|
@@ -7606,7 +7818,7 @@ function createClient(options) {
|
|
|
7606
7818
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
7607
7819
|
if (shouldConnect) {
|
|
7608
7820
|
if (typeof atob === "undefined") {
|
|
7609
|
-
if (_optionalChain([clientOptions, 'access',
|
|
7821
|
+
if (_optionalChain([clientOptions, 'access', _169 => _169.polyfills, 'optionalAccess', _170 => _170.atob]) === void 0) {
|
|
7610
7822
|
throw new Error(
|
|
7611
7823
|
"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"
|
|
7612
7824
|
);
|
|
@@ -7618,7 +7830,7 @@ function createClient(options) {
|
|
|
7618
7830
|
return leaseRoom(newRoomDetails);
|
|
7619
7831
|
}
|
|
7620
7832
|
function getRoom(roomId) {
|
|
7621
|
-
const room = _optionalChain([roomsById, 'access',
|
|
7833
|
+
const room = _optionalChain([roomsById, 'access', _171 => _171.get, 'call', _172 => _172(roomId), 'optionalAccess', _173 => _173.room]);
|
|
7622
7834
|
return room ? room : null;
|
|
7623
7835
|
}
|
|
7624
7836
|
function logout() {
|
|
@@ -7638,7 +7850,7 @@ function createClient(options) {
|
|
|
7638
7850
|
const batchedResolveUsers = new Batch(
|
|
7639
7851
|
async (batchedUserIds) => {
|
|
7640
7852
|
const userIds = batchedUserIds.flat();
|
|
7641
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
7853
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _174 => _174({ userIds })]);
|
|
7642
7854
|
warnIfNoResolveUsers();
|
|
7643
7855
|
return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
|
|
7644
7856
|
},
|
|
@@ -7656,7 +7868,7 @@ function createClient(options) {
|
|
|
7656
7868
|
const batchedResolveRoomsInfo = new Batch(
|
|
7657
7869
|
async (batchedRoomIds) => {
|
|
7658
7870
|
const roomIds = batchedRoomIds.flat();
|
|
7659
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
7871
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _175 => _175({ roomIds })]);
|
|
7660
7872
|
warnIfNoResolveRoomsInfo();
|
|
7661
7873
|
return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
|
|
7662
7874
|
},
|
|
@@ -7671,20 +7883,20 @@ function createClient(options) {
|
|
|
7671
7883
|
mentionSuggestionsCache.clear();
|
|
7672
7884
|
}
|
|
7673
7885
|
const syncStatusSources = [];
|
|
7674
|
-
const
|
|
7886
|
+
const syncStatusSignal = new Signal("synchronized");
|
|
7675
7887
|
function getSyncStatus() {
|
|
7676
|
-
const status =
|
|
7888
|
+
const status = syncStatusSignal.get();
|
|
7677
7889
|
return status === "synchronizing" ? status : "synchronized";
|
|
7678
7890
|
}
|
|
7679
7891
|
function recompute() {
|
|
7680
|
-
|
|
7681
|
-
syncStatusSources.some((src) => src.
|
|
7892
|
+
syncStatusSignal.set(
|
|
7893
|
+
syncStatusSources.some((src) => src.get() === "synchronizing") ? "synchronizing" : syncStatusSources.some((src) => src.get() === "has-local-changes") ? "has-local-changes" : "synchronized"
|
|
7682
7894
|
);
|
|
7683
7895
|
}
|
|
7684
7896
|
function createSyncSource() {
|
|
7685
|
-
const source = new
|
|
7897
|
+
const source = new Signal("synchronized");
|
|
7686
7898
|
syncStatusSources.push(source);
|
|
7687
|
-
const unsub = source.
|
|
7899
|
+
const unsub = source.subscribe(() => recompute());
|
|
7688
7900
|
function setSyncStatus(status) {
|
|
7689
7901
|
source.set(status);
|
|
7690
7902
|
}
|
|
@@ -7693,7 +7905,7 @@ function createClient(options) {
|
|
|
7693
7905
|
const index = syncStatusSources.findIndex((item) => item === source);
|
|
7694
7906
|
if (index > -1) {
|
|
7695
7907
|
const [ref] = syncStatusSources.splice(index, 1);
|
|
7696
|
-
const wasStillPending = ref.
|
|
7908
|
+
const wasStillPending = ref.get() !== "synchronized";
|
|
7697
7909
|
if (wasStillPending) {
|
|
7698
7910
|
recompute();
|
|
7699
7911
|
}
|
|
@@ -7703,12 +7915,12 @@ function createClient(options) {
|
|
|
7703
7915
|
}
|
|
7704
7916
|
{
|
|
7705
7917
|
const maybePreventClose = (e) => {
|
|
7706
|
-
if (clientOptions.preventUnsavedChanges &&
|
|
7918
|
+
if (clientOptions.preventUnsavedChanges && syncStatusSignal.get() !== "synchronized") {
|
|
7707
7919
|
e.preventDefault();
|
|
7708
7920
|
}
|
|
7709
7921
|
};
|
|
7710
7922
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
7711
|
-
_optionalChain([win, 'optionalAccess',
|
|
7923
|
+
_optionalChain([win, 'optionalAccess', _176 => _176.addEventListener, 'call', _177 => _177("beforeunload", maybePreventClose)]);
|
|
7712
7924
|
}
|
|
7713
7925
|
const client = Object.defineProperty(
|
|
7714
7926
|
{
|
|
@@ -7731,7 +7943,7 @@ function createClient(options) {
|
|
|
7731
7943
|
},
|
|
7732
7944
|
getSyncStatus,
|
|
7733
7945
|
events: {
|
|
7734
|
-
syncStatus:
|
|
7946
|
+
syncStatus: syncStatusSignal
|
|
7735
7947
|
},
|
|
7736
7948
|
// Internal
|
|
7737
7949
|
[kInternal]: {
|
|
@@ -7825,7 +8037,7 @@ var commentBodyElementsTypes = {
|
|
|
7825
8037
|
mention: "inline"
|
|
7826
8038
|
};
|
|
7827
8039
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
7828
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
8040
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _178 => _178.content])) {
|
|
7829
8041
|
return;
|
|
7830
8042
|
}
|
|
7831
8043
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -7835,13 +8047,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
7835
8047
|
for (const block of body.content) {
|
|
7836
8048
|
if (type === "all" || type === "block") {
|
|
7837
8049
|
if (guard(block)) {
|
|
7838
|
-
_optionalChain([visitor, 'optionalCall',
|
|
8050
|
+
_optionalChain([visitor, 'optionalCall', _179 => _179(block)]);
|
|
7839
8051
|
}
|
|
7840
8052
|
}
|
|
7841
8053
|
if (type === "all" || type === "inline") {
|
|
7842
8054
|
for (const inline of block.children) {
|
|
7843
8055
|
if (guard(inline)) {
|
|
7844
|
-
_optionalChain([visitor, 'optionalCall',
|
|
8056
|
+
_optionalChain([visitor, 'optionalCall', _180 => _180(inline)]);
|
|
7845
8057
|
}
|
|
7846
8058
|
}
|
|
7847
8059
|
}
|
|
@@ -7866,7 +8078,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
|
7866
8078
|
userIds
|
|
7867
8079
|
});
|
|
7868
8080
|
for (const [index, userId] of userIds.entries()) {
|
|
7869
|
-
const user = _optionalChain([users, 'optionalAccess',
|
|
8081
|
+
const user = _optionalChain([users, 'optionalAccess', _181 => _181[index]]);
|
|
7870
8082
|
if (user) {
|
|
7871
8083
|
resolvedUsers.set(userId, user);
|
|
7872
8084
|
}
|
|
@@ -7909,13 +8121,15 @@ function escapeHtml(value) {
|
|
|
7909
8121
|
);
|
|
7910
8122
|
}
|
|
7911
8123
|
var HtmlSafeString = class {
|
|
8124
|
+
#strings;
|
|
8125
|
+
#values;
|
|
7912
8126
|
constructor(strings, values) {
|
|
7913
|
-
this
|
|
7914
|
-
this
|
|
8127
|
+
this.#strings = strings;
|
|
8128
|
+
this.#values = values;
|
|
7915
8129
|
}
|
|
7916
8130
|
toString() {
|
|
7917
|
-
return this.
|
|
7918
|
-
return result + escapeHtml(nn(this
|
|
8131
|
+
return this.#strings.reduce((result, str, i) => {
|
|
8132
|
+
return result + escapeHtml(nn(this.#values[i - 1])) + str;
|
|
7919
8133
|
});
|
|
7920
8134
|
}
|
|
7921
8135
|
};
|
|
@@ -7963,13 +8177,15 @@ function escapeMarkdown(value) {
|
|
|
7963
8177
|
);
|
|
7964
8178
|
}
|
|
7965
8179
|
var MarkdownSafeString = class {
|
|
8180
|
+
#strings;
|
|
8181
|
+
#values;
|
|
7966
8182
|
constructor(strings, values) {
|
|
7967
|
-
this
|
|
7968
|
-
this
|
|
8183
|
+
this.#strings = strings;
|
|
8184
|
+
this.#values = values;
|
|
7969
8185
|
}
|
|
7970
8186
|
toString() {
|
|
7971
|
-
return this.
|
|
7972
|
-
return result + escapeMarkdown(nn(this
|
|
8187
|
+
return this.#strings.reduce((result, str, i) => {
|
|
8188
|
+
return result + escapeMarkdown(nn(this.#values[i - 1])) + str;
|
|
7973
8189
|
});
|
|
7974
8190
|
}
|
|
7975
8191
|
};
|
|
@@ -7989,7 +8205,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
7989
8205
|
text: ({ element }) => element.text,
|
|
7990
8206
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
7991
8207
|
mention: ({ element, user }) => {
|
|
7992
|
-
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
8208
|
+
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _182 => _182.name]), () => ( element.id))}`;
|
|
7993
8209
|
}
|
|
7994
8210
|
};
|
|
7995
8211
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -8019,7 +8235,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
8019
8235
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${_nullishCoalesce(element.text, () => ( element.url))}</a>`;
|
|
8020
8236
|
},
|
|
8021
8237
|
mention: ({ element, user }) => {
|
|
8022
|
-
return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
8238
|
+
return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _183 => _183.name]), () => ( element.id))}</span>`;
|
|
8023
8239
|
}
|
|
8024
8240
|
};
|
|
8025
8241
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -8049,19 +8265,19 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
8049
8265
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
8050
8266
|
},
|
|
8051
8267
|
mention: ({ element, user }) => {
|
|
8052
|
-
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
8268
|
+
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _184 => _184.name]), () => ( element.id))}`;
|
|
8053
8269
|
}
|
|
8054
8270
|
};
|
|
8055
8271
|
async function stringifyCommentBody(body, options) {
|
|
8056
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8057
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8272
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _185 => _185.format]), () => ( "plain"));
|
|
8273
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _186 => _186.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
8058
8274
|
const elements = {
|
|
8059
8275
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
8060
|
-
..._optionalChain([options, 'optionalAccess',
|
|
8276
|
+
..._optionalChain([options, 'optionalAccess', _187 => _187.elements])
|
|
8061
8277
|
};
|
|
8062
8278
|
const resolvedUsers = await resolveUsersInCommentBody(
|
|
8063
8279
|
body,
|
|
8064
|
-
_optionalChain([options, 'optionalAccess',
|
|
8280
|
+
_optionalChain([options, 'optionalAccess', _188 => _188.resolveUsers])
|
|
8065
8281
|
);
|
|
8066
8282
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
8067
8283
|
switch (block.type) {
|
|
@@ -8352,12 +8568,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
8352
8568
|
}
|
|
8353
8569
|
const newState = Object.assign({}, state);
|
|
8354
8570
|
for (const key in update.updates) {
|
|
8355
|
-
if (_optionalChain([update, 'access',
|
|
8571
|
+
if (_optionalChain([update, 'access', _189 => _189.updates, 'access', _190 => _190[key], 'optionalAccess', _191 => _191.type]) === "update") {
|
|
8356
8572
|
const val = update.node.get(key);
|
|
8357
8573
|
if (val !== void 0) {
|
|
8358
8574
|
newState[key] = lsonToJson(val);
|
|
8359
8575
|
}
|
|
8360
|
-
} else if (_optionalChain([update, 'access',
|
|
8576
|
+
} else if (_optionalChain([update, 'access', _192 => _192.updates, 'access', _193 => _193[key], 'optionalAccess', _194 => _194.type]) === "delete") {
|
|
8361
8577
|
delete newState[key];
|
|
8362
8578
|
}
|
|
8363
8579
|
}
|
|
@@ -8418,12 +8634,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
8418
8634
|
}
|
|
8419
8635
|
const newState = Object.assign({}, state);
|
|
8420
8636
|
for (const key in update.updates) {
|
|
8421
|
-
if (_optionalChain([update, 'access',
|
|
8637
|
+
if (_optionalChain([update, 'access', _195 => _195.updates, 'access', _196 => _196[key], 'optionalAccess', _197 => _197.type]) === "update") {
|
|
8422
8638
|
const value = update.node.get(key);
|
|
8423
8639
|
if (value !== void 0) {
|
|
8424
8640
|
newState[key] = lsonToJson(value);
|
|
8425
8641
|
}
|
|
8426
|
-
} else if (_optionalChain([update, 'access',
|
|
8642
|
+
} else if (_optionalChain([update, 'access', _198 => _198.updates, 'access', _199 => _199[key], 'optionalAccess', _200 => _200.type]) === "delete") {
|
|
8427
8643
|
delete newState[key];
|
|
8428
8644
|
}
|
|
8429
8645
|
}
|
|
@@ -8494,9 +8710,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
8494
8710
|
const startTime = performance.now();
|
|
8495
8711
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
8496
8712
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
8497
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8713
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _201 => _201.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
8498
8714
|
const context = {
|
|
8499
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
8715
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _202 => _202.visibilityState]) !== "hidden",
|
|
8500
8716
|
lastSuccessfulPollAt: startTime,
|
|
8501
8717
|
count: 0,
|
|
8502
8718
|
backoff: 0
|
|
@@ -8574,10 +8790,10 @@ function makePoller(callback, intervalMs, options) {
|
|
|
8574
8790
|
pollNowIfStale();
|
|
8575
8791
|
}
|
|
8576
8792
|
function onVisibilityChange() {
|
|
8577
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
8793
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _203 => _203.visibilityState]) !== "hidden");
|
|
8578
8794
|
}
|
|
8579
|
-
_optionalChain([doc, 'optionalAccess',
|
|
8580
|
-
_optionalChain([win, 'optionalAccess',
|
|
8795
|
+
_optionalChain([doc, 'optionalAccess', _204 => _204.addEventListener, 'call', _205 => _205("visibilitychange", onVisibilityChange)]);
|
|
8796
|
+
_optionalChain([win, 'optionalAccess', _206 => _206.addEventListener, 'call', _207 => _207("online", onVisibilityChange)]);
|
|
8581
8797
|
fsm.start();
|
|
8582
8798
|
return {
|
|
8583
8799
|
inc,
|
|
@@ -8642,9 +8858,11 @@ function bisectRight(arr, x, lt) {
|
|
|
8642
8858
|
return lo;
|
|
8643
8859
|
}
|
|
8644
8860
|
var SortedList = class _SortedList {
|
|
8861
|
+
#data;
|
|
8862
|
+
#lt;
|
|
8645
8863
|
constructor(alreadySortedList, lt) {
|
|
8646
|
-
this
|
|
8647
|
-
this
|
|
8864
|
+
this.#lt = lt;
|
|
8865
|
+
this.#data = alreadySortedList;
|
|
8648
8866
|
}
|
|
8649
8867
|
static from(arr, lt) {
|
|
8650
8868
|
const sorted = new _SortedList([], lt);
|
|
@@ -8660,14 +8878,14 @@ var SortedList = class _SortedList {
|
|
|
8660
8878
|
* Clones the sorted list to a new instance.
|
|
8661
8879
|
*/
|
|
8662
8880
|
clone() {
|
|
8663
|
-
return new _SortedList(this.
|
|
8881
|
+
return new _SortedList(this.#data.slice(), this.#lt);
|
|
8664
8882
|
}
|
|
8665
8883
|
/**
|
|
8666
8884
|
* Adds a new item to the sorted list, such that it remains sorted.
|
|
8667
8885
|
*/
|
|
8668
8886
|
add(value) {
|
|
8669
|
-
const idx = bisectRight(this
|
|
8670
|
-
this.
|
|
8887
|
+
const idx = bisectRight(this.#data, value, this.#lt);
|
|
8888
|
+
this.#data.splice(idx, 0, value);
|
|
8671
8889
|
}
|
|
8672
8890
|
/**
|
|
8673
8891
|
* Removes the given value from the sorted list, if it exists. The given
|
|
@@ -8675,25 +8893,25 @@ var SortedList = class _SortedList {
|
|
|
8675
8893
|
* removed if the element exists in the sorted list multiple times.
|
|
8676
8894
|
*/
|
|
8677
8895
|
remove(value) {
|
|
8678
|
-
const idx = this.
|
|
8896
|
+
const idx = this.#data.indexOf(value);
|
|
8679
8897
|
if (idx >= 0) {
|
|
8680
|
-
this.
|
|
8898
|
+
this.#data.splice(idx, 1);
|
|
8681
8899
|
return true;
|
|
8682
8900
|
}
|
|
8683
8901
|
return false;
|
|
8684
8902
|
}
|
|
8685
8903
|
get length() {
|
|
8686
|
-
return this.
|
|
8904
|
+
return this.#data.length;
|
|
8687
8905
|
}
|
|
8688
8906
|
*filter(predicate) {
|
|
8689
|
-
for (const item of this
|
|
8907
|
+
for (const item of this.#data) {
|
|
8690
8908
|
if (predicate(item)) {
|
|
8691
8909
|
yield item;
|
|
8692
8910
|
}
|
|
8693
8911
|
}
|
|
8694
8912
|
}
|
|
8695
8913
|
[Symbol.iterator]() {
|
|
8696
|
-
return this
|
|
8914
|
+
return this.#data[Symbol.iterator]();
|
|
8697
8915
|
}
|
|
8698
8916
|
};
|
|
8699
8917
|
|