@sovereignbase/convergent-replicated-list 1.3.6 → 1.3.7
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/README.md +208 -206
- package/dist/index.cjs +116 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +76 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -112,9 +112,19 @@ function rebuildLiveProjection(crListReplica) {
|
|
|
112
112
|
while (stack.length > 0) {
|
|
113
113
|
const frame = stack[stack.length - 1];
|
|
114
114
|
if (!frame.siblings) {
|
|
115
|
-
|
|
115
|
+
const childrenMapSibs = crListReplica.childrenMap.get(
|
|
116
116
|
frame.predecessorIdentifier
|
|
117
117
|
);
|
|
118
|
+
const runNextEntry = _optionalChain([crListReplica, 'access', _14 => _14.runNext, 'optionalAccess', _15 => _15.get, 'call', _16 => _16(
|
|
119
|
+
frame.predecessorIdentifier
|
|
120
|
+
)]);
|
|
121
|
+
if (childrenMapSibs && runNextEntry) {
|
|
122
|
+
frame.siblings = [...childrenMapSibs, runNextEntry];
|
|
123
|
+
} else if (runNextEntry) {
|
|
124
|
+
frame.siblings = [runNextEntry];
|
|
125
|
+
} else {
|
|
126
|
+
frame.siblings = childrenMapSibs;
|
|
127
|
+
}
|
|
118
128
|
if (!frame.siblings) {
|
|
119
129
|
void stack.pop();
|
|
120
130
|
continue;
|
|
@@ -186,7 +196,7 @@ function attachEntryToIndexes(crListReplica, linkedListEntry, deltaBuf) {
|
|
|
186
196
|
]);
|
|
187
197
|
}
|
|
188
198
|
if (deltaBuf && !Array.isArray(deltaBuf.values)) deltaBuf.values = [];
|
|
189
|
-
if (_optionalChain([deltaBuf, 'optionalAccess',
|
|
199
|
+
if (_optionalChain([deltaBuf, 'optionalAccess', _17 => _17.values]))
|
|
190
200
|
void deltaBuf.values.push({
|
|
191
201
|
uuidv7: linkedListEntry.uuidv7,
|
|
192
202
|
value: linkedListEntry.value,
|
|
@@ -198,9 +208,21 @@ function attachEntryToIndexes(crListReplica, linkedListEntry, deltaBuf) {
|
|
|
198
208
|
function detachEntryFromIndexes(crListReplica, linkedListEntry) {
|
|
199
209
|
void crListReplica.parentMap.delete(linkedListEntry.uuidv7);
|
|
200
210
|
const siblings = crListReplica.childrenMap.get(linkedListEntry.predecessor);
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
211
|
+
if (siblings) {
|
|
212
|
+
const index = siblings.indexOf(linkedListEntry);
|
|
213
|
+
if (index !== -1) void siblings.splice(index, 1);
|
|
214
|
+
}
|
|
215
|
+
if (crListReplica.runNext) {
|
|
216
|
+
if (crListReplica.runNext.get(linkedListEntry.predecessor) === linkedListEntry)
|
|
217
|
+
crListReplica.runNext.delete(linkedListEntry.predecessor);
|
|
218
|
+
const runSuccessor = crListReplica.runNext.get(linkedListEntry.uuidv7);
|
|
219
|
+
if (runSuccessor) {
|
|
220
|
+
crListReplica.runNext.delete(linkedListEntry.uuidv7);
|
|
221
|
+
const sibs = crListReplica.childrenMap.get(linkedListEntry.uuidv7);
|
|
222
|
+
if (sibs) sibs.push(runSuccessor);
|
|
223
|
+
else crListReplica.childrenMap.set(linkedListEntry.uuidv7, [runSuccessor]);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
204
226
|
}
|
|
205
227
|
|
|
206
228
|
// src/.helpers/deleteLiveEntry/index.ts
|
|
@@ -209,7 +231,7 @@ function deleteLiveEntry(crListReplica, linkedListEntry, deltaBuf) {
|
|
|
209
231
|
const next = linkedListEntry.next;
|
|
210
232
|
void crListReplica.tombstones.add(linkedListEntry.uuidv7);
|
|
211
233
|
if (deltaBuf && !Array.isArray(deltaBuf.tombstones)) deltaBuf.tombstones = [];
|
|
212
|
-
void _optionalChain([deltaBuf, 'optionalAccess',
|
|
234
|
+
void _optionalChain([deltaBuf, 'optionalAccess', _18 => _18.tombstones, 'optionalAccess', _19 => _19.push, 'call', _20 => _20(linkedListEntry.uuidv7)]);
|
|
213
235
|
if (prev) prev.next = next;
|
|
214
236
|
if (next) {
|
|
215
237
|
next.prev = prev;
|
|
@@ -254,7 +276,7 @@ function trySpliceInsertedParent(crListReplica, insertedEntries, reparentedEntri
|
|
|
254
276
|
return false;
|
|
255
277
|
const siblings = crListReplica.childrenMap.get(inserted.predecessor);
|
|
256
278
|
const children = crListReplica.childrenMap.get(inserted.uuidv7);
|
|
257
|
-
if (_optionalChain([siblings, 'optionalAccess',
|
|
279
|
+
if (_optionalChain([siblings, 'optionalAccess', _21 => _21.length]) !== 1 || siblings[0] !== inserted || _optionalChain([children, 'optionalAccess', _22 => _22.length]) !== 1 || children[0] !== moved)
|
|
258
280
|
return false;
|
|
259
281
|
const predecessor = inserted.predecessor === "\0" ? void 0 : crListReplica.parentMap.get(inserted.predecessor);
|
|
260
282
|
if (inserted.predecessor !== "\0" && !predecessor) return false;
|
|
@@ -284,14 +306,14 @@ function trySpliceReplacement(crListReplica, insertedEntries, reparentedEntries,
|
|
|
284
306
|
const predecessor = inserted.predecessor === "\0" ? void 0 : crListReplica.parentMap.get(inserted.predecessor);
|
|
285
307
|
if (inserted.predecessor !== "\0" && !predecessor) return false;
|
|
286
308
|
const siblings = crListReplica.childrenMap.get(inserted.predecessor);
|
|
287
|
-
if (_optionalChain([siblings, 'optionalAccess',
|
|
309
|
+
if (_optionalChain([siblings, 'optionalAccess', _23 => _23.length]) !== 1 || siblings[0] !== inserted) return false;
|
|
288
310
|
const reparented = reparentedEntries[0];
|
|
289
|
-
const next = _optionalChain([reparented, 'optionalAccess',
|
|
311
|
+
const next = _optionalChain([reparented, 'optionalAccess', _24 => _24.entry]);
|
|
290
312
|
if (next) {
|
|
291
313
|
const children = crListReplica.childrenMap.get(inserted.uuidv7);
|
|
292
|
-
if (next.predecessor !== inserted.uuidv7 || !crListReplica.tombstones.has(reparented.previousPredecessor) || _optionalChain([children, 'optionalAccess',
|
|
314
|
+
if (next.predecessor !== inserted.uuidv7 || !crListReplica.tombstones.has(reparented.previousPredecessor) || _optionalChain([children, 'optionalAccess', _25 => _25.length]) !== 1 || children[0] !== next || next.prev !== predecessor)
|
|
293
315
|
return false;
|
|
294
|
-
} else if (_optionalChain([crListReplica, 'access',
|
|
316
|
+
} else if (_optionalChain([crListReplica, 'access', _26 => _26.childrenMap, 'access', _27 => _27.get, 'call', _28 => _28(inserted.uuidv7), 'optionalAccess', _29 => _29.length])) {
|
|
295
317
|
return false;
|
|
296
318
|
}
|
|
297
319
|
if (predecessor) {
|
|
@@ -327,7 +349,7 @@ function trySpliceSiblingInsert(crListReplica, insertedEntries, reparentedEntrie
|
|
|
327
349
|
return false;
|
|
328
350
|
const inserted = insertedEntries[0];
|
|
329
351
|
if (inserted.predecessor === "\0") return false;
|
|
330
|
-
if (_optionalChain([crListReplica, 'access',
|
|
352
|
+
if (_optionalChain([crListReplica, 'access', _30 => _30.childrenMap, 'access', _31 => _31.get, 'call', _32 => _32(inserted.uuidv7), 'optionalAccess', _33 => _33.length])) return false;
|
|
331
353
|
const predecessor = crListReplica.parentMap.get(inserted.predecessor);
|
|
332
354
|
const siblings = crListReplica.childrenMap.get(inserted.predecessor);
|
|
333
355
|
if (!predecessor || !siblings || siblings.length < 2) return false;
|
|
@@ -338,8 +360,8 @@ function trySpliceSiblingInsert(crListReplica, insertedEntries, reparentedEntrie
|
|
|
338
360
|
if (lastSibling !== inserted && lastSibling.next) return false;
|
|
339
361
|
const previousSibling = siblings[siblingIndex - 1];
|
|
340
362
|
const nextSibling = siblings[siblingIndex + 1];
|
|
341
|
-
if (_optionalChain([previousSibling, 'optionalAccess',
|
|
342
|
-
if (_optionalChain([crListReplica, 'access',
|
|
363
|
+
if (_optionalChain([previousSibling, 'optionalAccess', _34 => _34.uuidv7])) {
|
|
364
|
+
if (_optionalChain([crListReplica, 'access', _35 => _35.childrenMap, 'access', _36 => _36.get, 'call', _37 => _37(previousSibling.uuidv7), 'optionalAccess', _38 => _38.length]))
|
|
343
365
|
return false;
|
|
344
366
|
if (previousSibling.next !== nextSibling) return false;
|
|
345
367
|
} else if (predecessor.next !== nextSibling) {
|
|
@@ -363,6 +385,13 @@ function trySpliceSiblingInsert(crListReplica, insertedEntries, reparentedEntrie
|
|
|
363
385
|
return true;
|
|
364
386
|
}
|
|
365
387
|
|
|
388
|
+
// src/.helpers/deriveRunUuid/index.ts
|
|
389
|
+
function deriveRunUuid(startUuid, offset) {
|
|
390
|
+
const randA = parseInt(startUuid.slice(15, 18), 16);
|
|
391
|
+
const newRandA = randA + offset & 4095;
|
|
392
|
+
return startUuid.slice(0, 15) + newRandA.toString(16).padStart(3, "0") + startUuid.slice(18);
|
|
393
|
+
}
|
|
394
|
+
|
|
366
395
|
// src/core/crud/create/index.ts
|
|
367
396
|
|
|
368
397
|
function __create(snapshot) {
|
|
@@ -394,11 +423,11 @@ function __create(snapshot) {
|
|
|
394
423
|
);
|
|
395
424
|
if (!linkedListEntry) continue;
|
|
396
425
|
void attachEntryToIndexes(crListReplica, linkedListEntry);
|
|
397
|
-
if (canUseLinearProjection && linkedListEntry.predecessor === (_nullishCoalesce(_optionalChain([previous, 'optionalAccess',
|
|
426
|
+
if (canUseLinearProjection && linkedListEntry.predecessor === (_nullishCoalesce(_optionalChain([previous, 'optionalAccess', _39 => _39.uuidv7]), () => ( "\0")))) {
|
|
398
427
|
linkedListEntry.index = crListReplica.parentMap.size - 1;
|
|
399
428
|
void linkEntryBetween(previous, linkedListEntry, void 0);
|
|
400
429
|
previous = linkedListEntry;
|
|
401
|
-
void _optionalChain([crListReplica, 'access',
|
|
430
|
+
void _optionalChain([crListReplica, 'access', _40 => _40.index, 'optionalAccess', _41 => _41.set, 'call', _42 => _42(linkedListEntry.index, linkedListEntry)]);
|
|
402
431
|
continue;
|
|
403
432
|
}
|
|
404
433
|
canUseLinearProjection = false;
|
|
@@ -417,8 +446,8 @@ function __create(snapshot) {
|
|
|
417
446
|
function __read(targetIndex, crListReplica) {
|
|
418
447
|
try {
|
|
419
448
|
void seekCursorToIndex(targetIndex, crListReplica);
|
|
420
|
-
return _optionalChain([crListReplica, 'access',
|
|
421
|
-
} catch (
|
|
449
|
+
return _optionalChain([crListReplica, 'access', _43 => _43.cursor, 'optionalAccess', _44 => _44.value]);
|
|
450
|
+
} catch (e2) {
|
|
422
451
|
return void 0;
|
|
423
452
|
}
|
|
424
453
|
}
|
|
@@ -437,6 +466,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
437
466
|
const change = {};
|
|
438
467
|
const delta = { values: [], tombstones: [] };
|
|
439
468
|
let displacedEntry;
|
|
469
|
+
const batchEntries = [];
|
|
440
470
|
for (const listValue of listValues) {
|
|
441
471
|
const v7 = _uuid.v7.call(void 0, );
|
|
442
472
|
const linkedListEntry = {
|
|
@@ -454,7 +484,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
454
484
|
crListReplica.cursor = linkedListEntry;
|
|
455
485
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
456
486
|
void attachEntryToIndexes(crListReplica, linkedListEntry, delta);
|
|
457
|
-
_optionalChain([crListReplica, 'access',
|
|
487
|
+
_optionalChain([crListReplica, 'access', _45 => _45.index, 'optionalAccess', _46 => _46.set, 'call', _47 => _47(linkedListEntry.index, linkedListEntry)]);
|
|
458
488
|
change[linkedListEntry.index] = linkedListEntry.value;
|
|
459
489
|
break;
|
|
460
490
|
}
|
|
@@ -470,7 +500,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
470
500
|
void attachEntryToIndexes(crListReplica, linkedListEntry, delta);
|
|
471
501
|
crListReplica.cursor = linkedListEntry;
|
|
472
502
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
473
|
-
void _optionalChain([crListReplica, 'access',
|
|
503
|
+
void _optionalChain([crListReplica, 'access', _48 => _48.index, 'optionalAccess', _49 => _49.set, 'call', _50 => _50(linkedListEntry.index, linkedListEntry)]);
|
|
474
504
|
change[linkedListEntry.index] = linkedListEntry.value;
|
|
475
505
|
break;
|
|
476
506
|
}
|
|
@@ -485,7 +515,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
485
515
|
linkedListEntry,
|
|
486
516
|
entryToOverwrite.next
|
|
487
517
|
);
|
|
488
|
-
if (_optionalChain([entryToOverwrite, 'access',
|
|
518
|
+
if (_optionalChain([entryToOverwrite, 'access', _51 => _51.next, 'optionalAccess', _52 => _52.predecessor]) === entryToOverwrite.uuidv7) {
|
|
489
519
|
const overwriteNext = entryToOverwrite.next;
|
|
490
520
|
const owSibs = crListReplica.childrenMap.get(
|
|
491
521
|
overwriteNext.predecessor
|
|
@@ -501,7 +531,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
501
531
|
crListReplica.childrenMap.set(linkedListEntry.uuidv7, [
|
|
502
532
|
overwriteNext
|
|
503
533
|
]);
|
|
504
|
-
_optionalChain([delta, 'access',
|
|
534
|
+
_optionalChain([delta, 'access', _53 => _53.values, 'optionalAccess', _54 => _54.push, 'call', _55 => _55({
|
|
505
535
|
uuidv7: overwriteNext.uuidv7,
|
|
506
536
|
value: overwriteNext.value,
|
|
507
537
|
predecessor: overwriteNext.predecessor
|
|
@@ -509,13 +539,13 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
509
539
|
}
|
|
510
540
|
void attachEntryToIndexes(crListReplica, linkedListEntry, delta);
|
|
511
541
|
void crListReplica.tombstones.add(entryToOverwrite.uuidv7);
|
|
512
|
-
void _optionalChain([delta, 'access',
|
|
542
|
+
void _optionalChain([delta, 'access', _56 => _56.tombstones, 'optionalAccess', _57 => _57.push, 'call', _58 => _58(entryToOverwrite.uuidv7)]);
|
|
513
543
|
void detachEntryFromIndexes(crListReplica, entryToOverwrite);
|
|
514
544
|
entryToOverwrite.next = void 0;
|
|
515
545
|
entryToOverwrite.prev = void 0;
|
|
516
546
|
crListReplica.cursor = linkedListEntry;
|
|
517
547
|
crListReplica.cursorIndex = actualIndex;
|
|
518
|
-
void _optionalChain([crListReplica, 'access',
|
|
548
|
+
void _optionalChain([crListReplica, 'access', _59 => _59.index, 'optionalAccess', _60 => _60.set, 'call', _61 => _61(linkedListEntry.index, linkedListEntry)]);
|
|
519
549
|
change[actualIndex] = linkedListEntry.value;
|
|
520
550
|
break;
|
|
521
551
|
}
|
|
@@ -524,7 +554,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
524
554
|
crListReplica.cursor = linkedListEntry;
|
|
525
555
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
526
556
|
void attachEntryToIndexes(crListReplica, linkedListEntry, delta);
|
|
527
|
-
void _optionalChain([crListReplica, 'access',
|
|
557
|
+
void _optionalChain([crListReplica, 'access', _62 => _62.index, 'optionalAccess', _63 => _63.set, 'call', _64 => _64(linkedListEntry.index, linkedListEntry)]);
|
|
528
558
|
change[linkedListEntry.index] = linkedListEntry.value;
|
|
529
559
|
break;
|
|
530
560
|
}
|
|
@@ -557,7 +587,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
557
587
|
if (crListReplica.index) crListReplica.index.clear();
|
|
558
588
|
else crListReplica.index = /* @__PURE__ */ new Map();
|
|
559
589
|
}
|
|
560
|
-
void _optionalChain([crListReplica, 'access',
|
|
590
|
+
void _optionalChain([crListReplica, 'access', _65 => _65.index, 'optionalAccess', _66 => _66.set, 'call', _67 => _67(linkedListEntry.index, linkedListEntry)]);
|
|
561
591
|
change[linkedListEntry.index] = linkedListEntry.value;
|
|
562
592
|
break;
|
|
563
593
|
}
|
|
@@ -566,7 +596,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
566
596
|
crListReplica.cursor = linkedListEntry;
|
|
567
597
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
568
598
|
void attachEntryToIndexes(crListReplica, linkedListEntry, delta);
|
|
569
|
-
void _optionalChain([crListReplica, 'access',
|
|
599
|
+
void _optionalChain([crListReplica, 'access', _68 => _68.index, 'optionalAccess', _69 => _69.set, 'call', _70 => _70(linkedListEntry.index, linkedListEntry)]);
|
|
570
600
|
change[linkedListEntry.index] = linkedListEntry.value;
|
|
571
601
|
mode = "after";
|
|
572
602
|
listIndex = linkedListEntry.index - 1;
|
|
@@ -577,7 +607,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
577
607
|
const actualIndex = _nullishCoalesce(crListReplica.cursorIndex, () => ( listIndex));
|
|
578
608
|
const prev = crListReplica.cursor.prev;
|
|
579
609
|
linkedListEntry.index = actualIndex;
|
|
580
|
-
linkedListEntry.predecessor = _nullishCoalesce(_optionalChain([prev, 'optionalAccess',
|
|
610
|
+
linkedListEntry.predecessor = _nullishCoalesce(_optionalChain([prev, 'optionalAccess', _71 => _71.uuidv7]), () => ( "\0"));
|
|
581
611
|
void linkEntryBetween(prev, linkedListEntry, crListReplica.cursor);
|
|
582
612
|
if (crListReplica.cursor.predecessor === linkedListEntry.predecessor) {
|
|
583
613
|
if (!displacedEntry) {
|
|
@@ -597,16 +627,43 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
597
627
|
crListReplica.cursorIndex = actualIndex;
|
|
598
628
|
if (crListReplica.index) crListReplica.index.clear();
|
|
599
629
|
else crListReplica.index = /* @__PURE__ */ new Map();
|
|
600
|
-
void _optionalChain([crListReplica, 'access',
|
|
630
|
+
void _optionalChain([crListReplica, 'access', _72 => _72.index, 'optionalAccess', _73 => _73.set, 'call', _74 => _74(linkedListEntry.index, linkedListEntry)]);
|
|
601
631
|
change[actualIndex] = linkedListEntry.value;
|
|
602
632
|
mode = "after";
|
|
603
633
|
listIndex = linkedListEntry.index - 1;
|
|
604
634
|
break;
|
|
605
635
|
}
|
|
606
636
|
}
|
|
637
|
+
batchEntries.push(linkedListEntry);
|
|
607
638
|
crListReplica.size = crListReplica.parentMap.size;
|
|
608
639
|
listIndex++;
|
|
609
640
|
}
|
|
641
|
+
if (batchEntries.length > 1) {
|
|
642
|
+
for (let k = 0; k + 1 < batchEntries.length; k++) {
|
|
643
|
+
const curr = batchEntries[k];
|
|
644
|
+
const next = batchEntries[k + 1];
|
|
645
|
+
if (next.predecessor !== curr.uuidv7) continue;
|
|
646
|
+
crListReplica.childrenMap.delete(curr.uuidv7);
|
|
647
|
+
if (!crListReplica.runNext) crListReplica.runNext = /* @__PURE__ */ new Map();
|
|
648
|
+
crListReplica.runNext.set(curr.uuidv7, next);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (batchEntries.length > 1 && delta.values && delta.values.length >= batchEntries.length) {
|
|
652
|
+
const first = batchEntries[0];
|
|
653
|
+
const last = batchEntries[batchEntries.length - 1];
|
|
654
|
+
if (deriveRunUuid(first.uuidv7, batchEntries.length - 1) === last.uuidv7) {
|
|
655
|
+
delta.values.splice(
|
|
656
|
+
delta.values.length - batchEntries.length,
|
|
657
|
+
batchEntries.length,
|
|
658
|
+
{
|
|
659
|
+
uuidv7: first.uuidv7,
|
|
660
|
+
value: first.value,
|
|
661
|
+
predecessor: first.predecessor,
|
|
662
|
+
tail: batchEntries.slice(1).map((e) => e.value)
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
610
667
|
if (displacedEntry) {
|
|
611
668
|
const sibs = crListReplica.childrenMap.get(displacedEntry.predecessor);
|
|
612
669
|
if (sibs) sibs.push(displacedEntry);
|
|
@@ -614,7 +671,7 @@ function __update(listIndex, listValues, crListReplica, mode) {
|
|
|
614
671
|
crListReplica.childrenMap.set(displacedEntry.predecessor, [
|
|
615
672
|
displacedEntry
|
|
616
673
|
]);
|
|
617
|
-
_optionalChain([delta, 'access',
|
|
674
|
+
_optionalChain([delta, 'access', _75 => _75.values, 'optionalAccess', _76 => _76.push, 'call', _77 => _77({
|
|
618
675
|
uuidv7: displacedEntry.uuidv7,
|
|
619
676
|
value: displacedEntry.value,
|
|
620
677
|
predecessor: displacedEntry.predecessor
|
|
@@ -637,7 +694,7 @@ function __delete(crListReplica, startIndex, endIndex) {
|
|
|
637
694
|
void seekCursorToIndex(listIndex, crListReplica);
|
|
638
695
|
if (!crListReplica.cursor) return false;
|
|
639
696
|
let current = crListReplica.cursor;
|
|
640
|
-
const predecessor = _nullishCoalesce(_optionalChain([current, 'access',
|
|
697
|
+
const predecessor = _nullishCoalesce(_optionalChain([current, 'access', _78 => _78.prev, 'optionalAccess', _79 => _79.uuidv7]), () => ( "\0"));
|
|
641
698
|
const deletedIds = /* @__PURE__ */ new Set();
|
|
642
699
|
let deleted = 0;
|
|
643
700
|
let currentIndex = _nullishCoalesce(crListReplica.cursorIndex, () => ( listIndex));
|
|
@@ -645,7 +702,7 @@ function __delete(crListReplica, startIndex, endIndex) {
|
|
|
645
702
|
const next = current.next;
|
|
646
703
|
change[currentIndex] = void 0;
|
|
647
704
|
void deletedIds.add(current.uuidv7);
|
|
648
|
-
void _optionalChain([crListReplica, 'access',
|
|
705
|
+
void _optionalChain([crListReplica, 'access', _80 => _80.index, 'optionalAccess', _81 => _81.delete, 'call', _82 => _82(currentIndex)]);
|
|
649
706
|
void deleteLiveEntry(crListReplica, current, delta);
|
|
650
707
|
current = next;
|
|
651
708
|
currentIndex++;
|
|
@@ -665,7 +722,7 @@ function __delete(crListReplica, startIndex, endIndex) {
|
|
|
665
722
|
void deleteLiveEntry(crListReplica, current, delta);
|
|
666
723
|
void linkEntryBetween(prev, replacement, next);
|
|
667
724
|
void attachEntryToIndexes(crListReplica, replacement, delta);
|
|
668
|
-
if (_optionalChain([next, 'optionalAccess',
|
|
725
|
+
if (_optionalChain([next, 'optionalAccess', _83 => _83.predecessor]) === current.uuidv7)
|
|
669
726
|
void moveEntryToPredecessor(
|
|
670
727
|
crListReplica,
|
|
671
728
|
next,
|
|
@@ -696,9 +753,20 @@ function __merge(crListReplica, crListDelta) {
|
|
|
696
753
|
const change = {};
|
|
697
754
|
let tailTombstoneMovedCursor = false;
|
|
698
755
|
let needsRelink = false;
|
|
699
|
-
|
|
756
|
+
const expandedValues = Object.hasOwn(crListDelta, "values") && Array.isArray(crListDelta.values) ? crListDelta.values.flatMap((entry) => {
|
|
757
|
+
if (!entry || !entry.tail || entry.tail.length === 0) return [entry];
|
|
758
|
+
return [
|
|
759
|
+
entry,
|
|
760
|
+
...entry.tail.map((value, i) => ({
|
|
761
|
+
uuidv7: deriveRunUuid(entry.uuidv7, i + 1),
|
|
762
|
+
value,
|
|
763
|
+
predecessor: deriveRunUuid(entry.uuidv7, i)
|
|
764
|
+
}))
|
|
765
|
+
];
|
|
766
|
+
}) : void 0;
|
|
767
|
+
if (_optionalChain([expandedValues, 'optionalAccess', _84 => _84.length]) === 1 && (!Object.hasOwn(crListDelta, "tombstones") || Array.isArray(crListDelta.tombstones) && crListDelta.tombstones.length === 0)) {
|
|
700
768
|
const linkedListEntry = materializeSnapshotEntry(
|
|
701
|
-
|
|
769
|
+
expandedValues[0],
|
|
702
770
|
crListReplica
|
|
703
771
|
);
|
|
704
772
|
if (!linkedListEntry) return false;
|
|
@@ -711,7 +779,7 @@ function __merge(crListReplica, crListDelta) {
|
|
|
711
779
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
712
780
|
void attachEntryToIndexes(crListReplica, linkedListEntry);
|
|
713
781
|
crListReplica.size = crListReplica.parentMap.size;
|
|
714
|
-
void _optionalChain([crListReplica, 'access',
|
|
782
|
+
void _optionalChain([crListReplica, 'access', _85 => _85.index, 'optionalAccess', _86 => _86.set, 'call', _87 => _87(linkedListEntry.index, linkedListEntry)]);
|
|
715
783
|
return { [linkedListEntry.index]: linkedListEntry.value };
|
|
716
784
|
}
|
|
717
785
|
}
|
|
@@ -725,19 +793,19 @@ function __merge(crListReplica, crListDelta) {
|
|
|
725
793
|
const wasTail = linkedListEntry.next === void 0;
|
|
726
794
|
const wasCursor = crListReplica.cursor === linkedListEntry;
|
|
727
795
|
void newTombsIndices.push(linkedListEntry.index);
|
|
728
|
-
void _optionalChain([crListReplica, 'access',
|
|
796
|
+
void _optionalChain([crListReplica, 'access', _88 => _88.index, 'optionalAccess', _89 => _89.delete, 'call', _90 => _90(linkedListEntry.index)]);
|
|
729
797
|
void deleteLiveEntry(crListReplica, linkedListEntry);
|
|
730
798
|
tailTombstoneMovedCursor = wasTail && wasCursor;
|
|
731
799
|
needsRelink = true;
|
|
732
800
|
}
|
|
733
801
|
}
|
|
734
802
|
}
|
|
735
|
-
if (!
|
|
803
|
+
if (!expandedValues || expandedValues.length === 0 && tailTombstoneMovedCursor) {
|
|
736
804
|
if (newTombsIndices.length === 0) return false;
|
|
737
805
|
if (newTombsIndices.length === 1 && tailTombstoneMovedCursor) {
|
|
738
806
|
if (crListReplica.cursor) {
|
|
739
807
|
crListReplica.cursorIndex = crListReplica.size - 1;
|
|
740
|
-
void _optionalChain([crListReplica, 'access',
|
|
808
|
+
void _optionalChain([crListReplica, 'access', _91 => _91.index, 'optionalAccess', _92 => _92.set, 'call', _93 => _93(
|
|
741
809
|
crListReplica.cursorIndex,
|
|
742
810
|
crListReplica.cursor
|
|
743
811
|
)]);
|
|
@@ -753,7 +821,7 @@ function __merge(crListReplica, crListDelta) {
|
|
|
753
821
|
}
|
|
754
822
|
return change;
|
|
755
823
|
}
|
|
756
|
-
for (const valueEntry of
|
|
824
|
+
for (const valueEntry of expandedValues) {
|
|
757
825
|
if (valueEntry === null || valueEntry === void 0) continue;
|
|
758
826
|
const existingEntry = crListReplica.parentMap.get(valueEntry.uuidv7);
|
|
759
827
|
if (existingEntry) {
|
|
@@ -784,7 +852,7 @@ function __merge(crListReplica, crListDelta) {
|
|
|
784
852
|
crListReplica.cursor = linkedListEntry;
|
|
785
853
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
786
854
|
crListReplica.size = crListReplica.parentMap.size;
|
|
787
|
-
void _optionalChain([crListReplica, 'access',
|
|
855
|
+
void _optionalChain([crListReplica, 'access', _94 => _94.index, 'optionalAccess', _95 => _95.set, 'call', _96 => _96(linkedListEntry.index, linkedListEntry)]);
|
|
788
856
|
} else {
|
|
789
857
|
needsRelink = true;
|
|
790
858
|
}
|
|
@@ -795,7 +863,7 @@ function __merge(crListReplica, crListDelta) {
|
|
|
795
863
|
crListReplica.cursor = linkedListEntry;
|
|
796
864
|
crListReplica.cursorIndex = linkedListEntry.index;
|
|
797
865
|
crListReplica.size = crListReplica.parentMap.size;
|
|
798
|
-
void _optionalChain([crListReplica, 'access',
|
|
866
|
+
void _optionalChain([crListReplica, 'access', _97 => _97.index, 'optionalAccess', _98 => _98.set, 'call', _99 => _99(linkedListEntry.index, linkedListEntry)]);
|
|
799
867
|
} else {
|
|
800
868
|
needsRelink = true;
|
|
801
869
|
}
|
|
@@ -1030,8 +1098,8 @@ var CRList = class {
|
|
|
1030
1098
|
* @param thisArg - Optional `this` value for the predicate.
|
|
1031
1099
|
*/
|
|
1032
1100
|
find(predicate, thisArg) {
|
|
1033
|
-
let linkedListEntry = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1034
|
-
while (_optionalChain([linkedListEntry, 'optionalAccess',
|
|
1101
|
+
let linkedListEntry = _nullishCoalesce(_optionalChain([this, 'access', _100 => _100.state, 'access', _101 => _101.index, 'optionalAccess', _102 => _102.get, 'call', _103 => _103(0)]), () => ( this.state.cursor));
|
|
1102
|
+
while (_optionalChain([linkedListEntry, 'optionalAccess', _104 => _104.prev])) linkedListEntry = linkedListEntry.prev;
|
|
1035
1103
|
let index = 0;
|
|
1036
1104
|
while (linkedListEntry) {
|
|
1037
1105
|
if (predicate.call(thisArg, linkedListEntry.value, index, this))
|
|
@@ -1141,8 +1209,8 @@ var CRList = class {
|
|
|
1141
1209
|
* Iterates over current live values in index order.
|
|
1142
1210
|
*/
|
|
1143
1211
|
*[Symbol.iterator]() {
|
|
1144
|
-
let linkedListEntry = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1145
|
-
while (_optionalChain([linkedListEntry, 'optionalAccess',
|
|
1212
|
+
let linkedListEntry = _nullishCoalesce(_optionalChain([this, 'access', _105 => _105.state, 'access', _106 => _106.index, 'optionalAccess', _107 => _107.get, 'call', _108 => _108(0)]), () => ( this.state.cursor));
|
|
1213
|
+
while (_optionalChain([linkedListEntry, 'optionalAccess', _109 => _109.prev])) linkedListEntry = linkedListEntry.prev;
|
|
1146
1214
|
while (linkedListEntry) {
|
|
1147
1215
|
yield linkedListEntry.value;
|
|
1148
1216
|
linkedListEntry = linkedListEntry.next;
|
|
@@ -1158,8 +1226,8 @@ var CRList = class {
|
|
|
1158
1226
|
* @param thisArg - Optional `this` value for the callback.
|
|
1159
1227
|
*/
|
|
1160
1228
|
forEach(callback, thisArg) {
|
|
1161
|
-
let linkedListEntry = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1162
|
-
while (_optionalChain([linkedListEntry, 'optionalAccess',
|
|
1229
|
+
let linkedListEntry = _nullishCoalesce(_optionalChain([this, 'access', _110 => _110.state, 'access', _111 => _111.index, 'optionalAccess', _112 => _112.get, 'call', _113 => _113(0)]), () => ( this.state.cursor));
|
|
1230
|
+
while (_optionalChain([linkedListEntry, 'optionalAccess', _114 => _114.prev])) linkedListEntry = linkedListEntry.prev;
|
|
1163
1231
|
let index = 0;
|
|
1164
1232
|
while (linkedListEntry) {
|
|
1165
1233
|
void callback.call(thisArg, linkedListEntry.value, index, this);
|