-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1197 lines (1149 loc) · 45.3 KB
/
index.html
File metadata and controls
1197 lines (1149 loc) · 45.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Convergent Replicated List (CR-List)</title>
<meta
name="description"
content="Specification and reference JavaScript binding for a convergent replicated list delta CRDT with UUIDv7 entry identities, predecessor ordering, tombstone acknowledgements, and garbage collection."
/>
<meta
name="keywords"
content="cr-list, convergent replicated list, crdt, uuidv7, predecessor ordering, delta, snapshot, acknowledgement, garbage collection, javascript, typescript"
/>
<meta name="author" content="Jori Lehtinen" />
<meta
name="robots"
content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1"
/>
<meta name="application-name" content="convergent-replicated-list" />
<link
rel="canonical"
href="https://sovereignbase.dev/convergent-replicated-list/"
/>
<link
rel="icon"
type="image/png"
href="https://sovereignbase.dev/sovereignbase_logo.png"
/>
<link
rel="apple-touch-icon"
href="https://sovereignbase.dev/sovereignbase_logo.png"
/>
<meta property="og:type" content="article" />
<meta property="og:locale" content="en_US" />
<meta property="og:site_name" content="Sovereignbase" />
<meta property="og:title" content="Convergent Replicated List (CR-List)" />
<meta
property="og:description"
content="Specification and reference JavaScript binding for a convergent replicated list delta CRDT with UUIDv7 entry identities, predecessor ordering, tombstone acknowledgements, and garbage collection."
/>
<meta
property="og:url"
content="https://sovereignbase.dev/convergent-replicated-list/"
/>
<meta
property="og:image"
content="https://sovereignbase.dev/sovereignbase_social_sharing_image.png"
/>
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta
property="og:image:alt"
content="Sovereignbase social sharing image for the CR-List specification."
/>
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Convergent Replicated List (CR-List)" />
<meta
name="twitter:description"
content="Specification and reference JavaScript binding for a convergent replicated list delta CRDT with UUIDv7 entry identities, predecessor ordering, tombstone acknowledgements, and garbage collection."
/>
<meta
name="twitter:image"
content="https://sovereignbase.dev/sovereignbase_social_sharing_image.png"
/>
<meta
name="twitter:image:alt"
content="Sovereignbase social sharing image for the CR-List specification."
/>
<meta name="twitter:creator" content="@jortsupetterson" />
<script
src="https://www.w3.org/Tools/respec/respec-w3c"
class="remove"
defer
></script>
<script class="remove">
var respecConfig = {
specStatus: 'unofficial',
shortName: 'convergent-replicated-list',
github: 'sovereignbase/convergent-replicated-list',
latestVersion: null,
edDraftURI: null,
editors: [
{ name: 'Jori Lehtinen', url: 'https://github.com/jortsupetterson' },
{
name: 'GPT-5.4',
url: 'https://openai.com/en-US/index/introducing-gpt-5-4/',
},
],
xref: 'web-platform',
lint: {
'informative-dfn': true,
'local-refs-exist': true,
'no-unused-dfns': true,
},
localBiblio: {
MARTIN_KLEPPMANN: {
title: 'CRDTs: The Hard Parts',
href: 'https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydra.html',
publisher: 'Martin Kleppmann',
date: '2020-06',
},
RFC9562: {
title: 'Universally Unique IDentifiers (UUIDs)',
href: 'https://www.rfc-editor.org/rfc/rfc9562',
publisher: 'IETF',
date: '2024-05',
},
INFRA: {
title: 'Infra',
href: 'https://infra.spec.whatwg.org/',
publisher: 'WhatWG',
date: '2026-03',
},
HTML: {
title: '2.7 Safe passing of structured data',
href: 'https://html.spec.whatwg.org/multipage/structured-data.html',
publisher: 'WhatWG',
date: '2026-04',
},
LINKED_LIST: {
title: 'linked list',
href: 'https://xlinux.nist.gov/dads/HTML/linkedList.html',
publisher: 'NIST',
date: '2022-01',
},
DOUBLY_LINKED_LIST: {
title: 'linked list',
href: 'https://xlinux.nist.gov/dads/HTML/doublyLinkedList.html',
publisher: 'NIST',
date: '2021-07',
},
},
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://sovereignbase.dev/convergent-replicated-list/#organization",
"name": "Sovereignbase",
"url": "https://github.com/sovereignbase",
"alternateName": ["@sovereignbase"],
"logo": {
"@type": "ImageObject",
"url": "https://sovereignbase.dev/sovereignbase_logo.png",
"width": 320,
"height": 320
},
"sameAs": [
"https://github.com/sovereignbase",
"https://jsr.io/@sovereignbase",
"https://www.npmjs.com/org/sovereignbase"
]
},
{
"@type": "Person",
"@id": "https://sovereignbase.dev/convergent-replicated-list/#author",
"name": "Jori Lehtinen",
"url": "https://github.com/jortsupetterson",
"alternateName": ["jortsupetterson", "@jortsupetterson"],
"sameAs": [
"https://github.com/jortsupetterson",
"https://www.npmjs.com/~jortsupetterson",
"https://jsr.io/user/ab186a13-a64f-429e-a757-927aa4fa6e6c",
"https://linkedin.com/in/jortsupetterson",
"https://x.com/jortsupetterson",
"https://www.youtube.com/@jortsupetterson"
]
},
{
"@type": "WebSite",
"@id": "https://sovereignbase.dev/convergent-replicated-list/#website",
"url": "https://sovereignbase.dev/convergent-replicated-list/",
"name": "convergent-replicated-list",
"inLanguage": "en",
"publisher": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#organization"
}
},
{
"@type": "SoftwareSourceCode",
"@id": "https://sovereignbase.dev/convergent-replicated-list/#software",
"name": "@sovereignbase/convergent-replicated-list",
"alternateName": ["convergent-replicated-list", "cr-list"],
"url": "https://sovereignbase.dev/convergent-replicated-list/",
"description": "Convergent replicated list delta CRDT with UUIDv7 entry identities, predecessor ordering, tombstone acknowledgements, and garbage collection.",
"codeRepository": "https://github.com/sovereignbase/convergent-replicated-list",
"license": "https://www.apache.org/licenses/LICENSE-2.0",
"programmingLanguage": ["TypeScript", "JavaScript"],
"runtimePlatform": [
"Node.js",
"Web Browser",
"Bun",
"Deno",
"Cloudflare Workers",
"Edge Runtime"
],
"keywords": [
"uuidv7",
"convergent",
"replicated",
"delta",
"crdt",
"convergent-replicated-list",
"cr-list",
"core",
"crud",
"mags"
],
"image": "https://sovereignbase.dev/sovereignbase_social_sharing_image.png",
"isAccessibleForFree": true,
"author": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#author"
},
"maintainer": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#organization"
},
"publisher": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#organization"
},
"sameAs": [
"https://jsr.io/@sovereignbase/convergent-replicated-list/",
"https://www.npmjs.com/package/@sovereignbase/convergent-replicated-list"
]
},
{
"@type": "TechArticle",
"@id": "https://sovereignbase.dev/convergent-replicated-list/#specification",
"headline": "Convergent Replicated List (CR-List)",
"name": "Convergent Replicated List (CR-List)",
"url": "https://sovereignbase.dev/convergent-replicated-list/",
"description": "Specification and reference JavaScript binding for a convergent replicated list delta CRDT with UUIDv7 entry identities, predecessor ordering, tombstone acknowledgements, and garbage collection.",
"inLanguage": "en",
"isPartOf": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#website"
},
"mainEntityOfPage": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#webpage"
},
"about": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#software"
},
"author": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#author"
},
"publisher": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#organization"
},
"image": {
"@type": "ImageObject",
"url": "https://sovereignbase.dev/sovereignbase_social_sharing_image.png",
"width": 1200,
"height": 630
}
},
{
"@type": "WebPage",
"@id": "https://sovereignbase.dev/convergent-replicated-list/#webpage",
"url": "https://sovereignbase.dev/convergent-replicated-list/",
"name": "Convergent Replicated List (CR-List)",
"description": "Specification and reference JavaScript binding for a convergent replicated list delta CRDT with UUIDv7 entry identities, predecessor ordering, tombstone acknowledgements, and garbage collection.",
"inLanguage": "en",
"isPartOf": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#website"
},
"about": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#software"
},
"author": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#author"
},
"publisher": {
"@id": "https://sovereignbase.dev/convergent-replicated-list/#organization"
},
"primaryImageOfPage": {
"@type": "ImageObject",
"url": "https://sovereignbase.dev/sovereignbase_social_sharing_image.png",
"width": 1200,
"height": 630
},
"relatedLink": [
"https://github.com/sovereignbase",
"https://jsr.io/@sovereignbase",
"https://www.npmjs.com/org/sovereignbase",
"https://github.com/sovereignbase/convergent-replicated-list",
"https://jsr.io/@sovereignbase/convergent-replicated-list/",
"https://www.npmjs.com/package/@sovereignbase/convergent-replicated-list",
"https://github.com/jortsupetterson",
"https://www.npmjs.com/~jortsupetterson",
"https://jsr.io/user/ab186a13-a64f-429e-a757-927aa4fa6e6c",
"https://linkedin.com/in/jortsupetterson",
"https://x.com/jortsupetterson",
"https://www.youtube.com/@jortsupetterson"
]
}
]
}
</script>
</head>
<body>
<section id="abstract">
<p>
This document defines Convergent Replicated List (CR-List), a delta CRDT
for an ordered sequence of entries. Each index resolves to a single
visible value. Every update is assigned a UUIDv7, and deletions are
tracked as a list of UUIDv7 identifiers.
</p>
<p>
The specification defines the data structure, merge rules, snapshot and
delta formats, garbage-collection rules, acknowledgement formats, and
one conforming JavaScript binding.
</p>
</section>
<section id="sotd">
<p>
CR-List is designed to serve as a core for use-case-optimized CRDT
interfaces, such as text or arrays.
</p>
<p>
This specification is maintained alongside a reference implementation.
</p>
<p>To use the reference implementation see:</p>
<ul>
<li>
<a
href="https://www.npmjs.com/package/@sovereignbase/convergent-replicated-list"
>NPM Registry
</a>
</li>
<li>
<a href="https://jsr.io/@sovereignbase/convergent-replicated-list"
>JSR Registry
</a>
</li>
</ul>
<p>Inspired by [[MARTIN_KLEPPMANN]].</p>
</section>
<section id="conformance">
<p>
Unless otherwise stated, data-structure and algorithm terms such as
<em>list</em>, <em>map</em>, <em>struct</em>, <em>parameters</em>,
<em>variables</em>, and <em>iterate</em> are used with the meanings
defined by Infra [[INFRA]].
</p>
<p>
A conforming implementation MUST preserve the replica convergence and
deletion semantics defined by the algorithms in this specification.
</p>
</section>
<section>
<h2>Terminology</h2>
<p>
A <dfn>CR-List replica</dfn> is one independently mutable instance of
the data structure.
</p>
<p>
A <dfn>UUIDv7 identifier</dfn> is an identifier that is a valid UUID
version 7 as defined by [[RFC9562]].
</p>
<p>
a <dfn>linked list</dfn> is a list implemented by each item having a
link to the next item. [[LINKED_LIST]].
</p>
<p>
a <dfn>doubly linked list</dfn> is a variant of a <a>linked list</a> in
which each item has a link to the previous item as well as the next.
[[DOUBLY_LINKED_LIST]].
</p>
<p>
a <dfn>serializable object</dfn> is an object that supports
serialization and later deserialization as defined by [[HTML]].
</p>
<p>
A <dfn>predecessor identifier</dfn> is an <a>UUIDv7 identifier</a> or
the root sentinel <code>'\0'</code> pointing to what <a>list value</a> a
<a>list value</a> comes after.
</p>
<p>
A <dfn>list index</dfn> is the position of a <a>list value</a>, starting
at 0 and ending at the <a>list length</a>, in the resolved conflict-free
ordering of a <a>CR-List replica</a>.
</p>
<p>
A <dfn>list value</dfn> is the consumer defined payload presently
selected for a given <a>list index</a>.
</p>
<p>
The <dfn>list length</dfn> is the number of <a>list value</a>(s) in a
<a>CR-List replica</a>.
</p>
<p>
A <dfn>replica state</dfn> is a struct consisting of
<a>replica values</a> and <a>replica tombstones</a> tracked by
<a>CR-List replica</a>.
</p>
<p>
The <dfn>replica values</dfn> is the set of 0 or more
<a>values entry</a>(s) tracked by <a>replica state</a>.
</p>
<p>
A <dfn>values entry</dfn> is a struct consisting of a
<a>UUIDv7 Identifier</a>, <a>list value</a>, and
<a>predecessor identifier</a> tracked by <a>replica values</a>. A
conforming runtime MAY additionally project those same entries into a
local <a>doubly linked list</a> by tracking members such as
<code>prev</code>, <code>next</code>, and <code>index</code>.
</p>
<p>
The <dfn>replica tombstones</dfn> is a list of 0 or more overwritten
<a>tombstones entry</a>(s) tracked by <a>replica state</a>.
</p>
<p>
A <dfn>tombstones entry</dfn> is a <a>UUIDv7 identifier</a> representing
a deleted <a>list value</a> tracked by <a>replica tombstones</a>.
</p>
<p>
An <dfn>acknowledgement</dfn> is a serializable string containing the
current <a>acknowledgement frontier</a> of a single
<a>CR-List replica</a>.
</p>
<p>
An <dfn>acknowledgement frontier</dfn> is the largest
<a>tombstones entry</a> presently retained by
<a>replica tombstones</a> under lexicographic comparison.
</p>
<p>
A <dfn>snapshot</dfn> is a detached structured-clone-compatible object
presentation of a <a>replica state</a>.
</p>
<p>
A <dfn>delta</dfn> is a partial <a>snapshot</a> containing only the
entries a <a>CR-List replica</a> wishes to share.
</p>
</section>
<section id="core-model">
<h2>Core Model</h2>
<p>
A <a>CR-List replica</a> stores live <a>values entry</a>(s) indexed by
their <a>UUIDv7 identifier</a>, groups them by
<a>predecessor identifier</a>, and stores deleted identifiers in
<a>replica tombstones</a>. The visible ordered list is a deterministic
projection derived from that state.
</p>
<p>
To resolve the visible projection, a conforming implementation ignores
every live candidate whose own <a>UUIDv7 identifier</a> is listed in
<a>replica tombstones</a>. It then clears every live entry's
<code>prev</code> and <code>next</code> members, sorts the live
sibling-bucket keys lexicographically by <a>predecessor identifier</a>,
and resolves those buckets in repeated passes. A bucket is resolvable
when its predecessor is the root predecessor <code>'\0'</code>, when its
predecessor is not presently found in live state, or when its
predecessor has already been linked into the visible projection.
</p>
<p>
Within a resolved bucket, siblings sharing the same
<a>predecessor identifier</a> are sorted lexicographically by UUIDv7 and
linked immediately after their visible predecessor, if any, otherwise at
the current visible tail. After all resolvable buckets have been linked,
the implementation walks to the visible tail and then back toward the
head, assigning descending indexes so that the final head-to-tail
visible order is zero-based and starts at 0.
</p>
<p>
Reads and local mutations MAY reuse a mutable cursor into that linked
list. This gives best-case O(1) local access when the cursor is already
at or near the target index and worst-case O(n) access when a full walk
of the visible list is required.
</p>
<p>
A snapshot or delta input MAY contain malformed or unknown members. A
conforming implementation processes only the known top-level members and
ignores entries that do not successfully parse.
</p>
</section>
<section>
<h2>Data Structure</h2>
<p>
The same logical replica can be viewed through three useful
representations: the detached structured-clone snapshot used for
transport and storage, one possible runtime projection used internally
by a binding, and the final consumer-facing visible sequence.
</p>
<section>
<h3>Snapshot</h3>
<pre
class="json"
data-include="./examples/snapshot.json"
data-include-format="text"
></pre>
</section>
<section>
<h3>Runtime</h3>
<pre
class="js"
data-include="./examples/runtime.js"
data-include-format="text"
></pre>
</section>
<section>
<h3>Consumer</h3>
<pre
class="json"
data-include="./examples/consumer.json"
data-include-format="text"
></pre>
</section>
</section>
<section>
<h2>Core Algorithms</h2>
<section>
<h3>CRUD</h3>
<section>
<h4>Create</h4>
<ol class="algorithm">
<li>
Let the result be a new empty <a>CR-List replica</a> whose
<a>replica values</a> and <a>replica tombstones</a> are empty.
</li>
<li>
If the supplied snapshot is not a record, then return the result.
</li>
<li>
If snapshot has an own <code>tombstones</code> member whose value
is a list, then for each listed item:
<ol>
<li>
If the item is not a valid <a>UUIDv7 identifier</a>, continue.
</li>
<li>
If the result already retains that
<a>tombstones entry</a>, continue.
</li>
<li>Add the item to <a>replica tombstones</a>.</li>
</ol>
</li>
<li>
If snapshot does not have an own <code>values</code> member whose
value is a list, then return the result.
</li>
<li>
For each listed candidate value entry, run the
<a>transform a snapshot entry to a state entry</a> algorithm. If
transforming fails, continue.
</li>
<li>
For each successfully minted <a>values entry</a>, add it to the
live UUID index and to the bucket keyed by its
<a>predecessor identifier</a>.
</li>
<li>
Clear all live <code>prev</code> and <code>next</code> members.
</li>
<li>
Sort the bucket keys lexicographically by
<a>predecessor identifier</a>.
</li>
<li>
For each bucket key in sorted order, if its bucket is resolvable,
sort its siblings lexicographically by UUIDv7 and link them into
the visible <a>doubly linked list</a>.
</li>
<li>
If at least one new bucket was resolved in that pass, repeat the
previous step.
</li>
<li>
Walk to the visible tail and then back toward the head, assigning
descending indexes so that the final visible head-to-tail order is
zero-based and starts at 0.
</li>
<li>Return the result.</li>
</ol>
</section>
<section>
<h4>Read</h4>
<ol class="algorithm">
<li>
If the supplied <a>list index</a> is out of bounds, then return
<code>undefined</code>.
</li>
<li>
Walk the current visible <a>doubly linked list</a> using the local
cursor until the target index is reached.
</li>
<li>
Return a detached structured clone of the visible
<a>list value</a> at that index.
</li>
</ol>
</section>
<section>
<h4>Update</h4>
<ol class="algorithm">
<li>
If the supplied <a>list index</a> is less than 0 or greater than
the current <a>list length</a>, then fail.
</li>
<li>If the supplied values input is not a list, then fail.</li>
<li>
If the supplied values input is empty, then return no change.
</li>
<li>
For each supplied value, attempt to copy it with
<code>structuredClone</code>. If copying fails, then fail.
</li>
<li>
For each copied value, mint a fresh <a>UUIDv7 identifier</a> for
the inserted visible entry.
</li>
<li>
If the mode is <code>after</code>, insert the copied values in the
given order after the target index. If the target index equals the
current <a>list length</a>, append at the tail.
</li>
<li>
If the mode is <code>before</code>, insert the copied values in
the given order before the target index.
</li>
<li>
If the mode is <code>overwrite</code>, replace the visible range
beginning at the target index and extending for the number of
supplied values. If the visible list ends first, append the
remaining copied values at the tail.
</li>
<li>
Any visible entries replaced by overwrite MUST become new
<a>tombstones entry</a>(s).
</li>
<li>
Return a <a>delta</a> describing the inserted values and the new
tombstones, together with a visible change patch.
</li>
</ol>
</section>
<section>
<h4>Delete</h4>
<ol class="algorithm">
<li>
Let the effective start index be the supplied start index, or 0 if
it was omitted.
</li>
<li>
Let the effective end index be the supplied end index, or the
current <a>list length</a> if it was omitted.
</li>
<li>If the effective range is invalid, then fail.</li>
<li>If the effective range is empty, then return no change.</li>
<li>
Delete each visible entry in the range
<code>[startIndex, endIndex)</code>.
</li>
<li>
Add each deleted entry's <a>UUIDv7 identifier</a> to
<a>replica tombstones</a>.
</li>
<li>
Return a <a>delta</a> containing the new tombstones together with
a visible change patch that marks the deleted indexes as
<code>undefined</code>.
</li>
</ol>
</section>
</section>
<section>
<h3>MAGS</h3>
<section>
<h4>Merge</h4>
<ol class="algorithm">
<li>
If the supplied candidate is not a record, then return no change.
</li>
<li>
If the candidate has an own <code>tombstones</code> member whose
value is a list, then for each listed item:
<ol>
<li>
If the item is not a valid <a>UUIDv7 identifier</a>, continue.
</li>
<li>
If the local replica already retains that
<a>tombstones entry</a>, continue.
</li>
<li>Add the tombstone to local tombstone state.</li>
<li>
If a matching live entry exists, remove it from the visible
projection and mark the merge as requiring relinking.
</li>
</ol>
</li>
<li>
If the candidate does not have an own <code>values</code> member
whose value is a list, then return the tombstone-only change, if
any.
</li>
<li>
For each listed candidate value entry:
<ol>
<li>
If the candidate is not a record, does not expose
<code>uuidv7</code>, <code>value</code>, and
<code>predecessor</code> members, or its
<code>uuidv7</code> or <code>predecessor</code> member is not
valid, continue.
</li>
<li>
If the local replica already tombstones the candidate
<code>uuidv7</code>, continue.
</li>
<li>
If a live entry with the same <a>UUIDv7 identifier</a>
already exists locally, adopt the incoming
<a>predecessor identifier</a> only when it is
lexicographically greater than the local predecessor
identifier; otherwise ignore the incoming entry. Then continue
to the next listed candidate value entry.
</li>
<li>
Run the
<a>transform a snapshot entry to a state entry</a> algorithm.
If it returns failure, continue.
</li>
<li>
Add the minted incoming entry to the live UUID index and to
the bucket keyed by its <a>predecessor identifier</a>.
</li>
</ol>
</li>
<li>
If every accepted incoming entry can be attached as a simple tail
append, the implementation MAY update the visible projection
incrementally and skip the next three steps.
</li>
<li>
Otherwise, clear all live <code>prev</code> and
<code>next</code> members.
</li>
<li>
Otherwise, resolve predecessor buckets using the same sorted-pass
bucket-resolution procedure defined in
<a href="#core-model">Core Model</a>.
</li>
<li>
Otherwise, assign visible indexes so that the final head-to-tail
order is zero-based and starts at 0.
</li>
<li>
Return the minimal visible change patch, or no change if nothing
was adopted.
</li>
</ol>
</section>
<section>
<h4>Acknowledge</h4>
<ol class="algorithm">
<li>
If the local replica retains no <a>tombstones entry</a>, then
return no <a>acknowledgement</a>.
</li>
<li>
Iterate the retained tombstones and keep the lexicographically
greatest tombstone seen so far.
</li>
<li>
Return that greatest tombstone as the replica's
<a>acknowledgement</a>.
</li>
</ol>
</section>
<section>
<h4>Garbage Collect</h4>
<ol class="algorithm">
<li>
If the supplied list of <a>acknowledgement</a>(s) is empty, then
return.
</li>
<li>Sort the supplied acknowledgements lexicographically.</li>
<li>
Let the safe collection boundary be the smallest supplied
acknowledgement that is a valid <a>UUIDv7 identifier</a>.
</li>
<li>
Remove every retained <a>tombstones entry</a> less than or equal
to that safe collection boundary.
</li>
</ol>
<p class="note">
This algorithm is only safe when the caller supplies
<a>acknowledgement</a>(s) covering every replica whose future
convergence must still be preserved. Supplying only a partial
frontier set is caller misuse and does not guarantee that an offline
replica can later catch up from deltas alone.
</p>
</section>
<section>
<h4>Snapshot</h4>
<ol class="algorithm">
<li>
For each current live entry, run the
<a>transform a state entry to a snapshot entry</a> algorithm.
</li>
<li>
Assemble the transformed live entries into the snapshot's
<code>values</code> list.
</li>
<li>
Assemble all retained <a>replica tombstones</a> into the
snapshot's <code>tombstones</code> list.
</li>
<li>Return the resulting <a>snapshot</a>.</li>
</ol>
</section>
</section>
</section>
<section>
<h2>Reference JavaScript Binding</h2>
<p>
This section defines one conforming JavaScript binding for the model
above.
</p>
<section>
<h3>API Summary</h3>
<pre class="idl">
callback CRListForEachCallback = undefined (any value, unsigned long index, CRList list);
[Exposed=*]
interface CRList {
constructor(optional object snapshot = {});
readonly attribute unsigned long size;
undefined append(any value, optional unsigned long afterIndex);
undefined prepend(any value, optional unsigned long beforeIndex);
undefined remove(unsigned long index);
undefined merge(optional object delta = {});
undefined acknowledge();
undefined garbageCollect(sequence<DOMString> frontiers);
undefined snapshot();
undefined addEventListener(
DOMString type,
EventListener? listener,
optional (AddEventListenerOptions or boolean) options = {}
);
undefined removeEventListener(
DOMString type,
EventListener? listener,
optional (EventListenerOptions or boolean) options = {}
);
undefined forEach(CRListForEachCallback callback, optional any thisArg);
object toJSON();
stringifier DOMString ();
iterable<any>;
};
dictionary CRListSnapshotValueEntry {
required DOMString uuidv7;
required any value;
required DOMString predecessor;
};
dictionary CRListSnapshot {
required sequence<CRListSnapshotValueEntry> values;
required sequence<DOMString> tombstones;
};
dictionary CRListDelta {
sequence<CRListSnapshotValueEntry> values;
sequence<DOMString> tombstones;
};
</pre>
<p>
The binding additionally exposes numeric property access through a
JavaScript <code>Proxy</code>. Reading <code>list[i]</code> returns a
detached copy of the visible value at index <var>i</var>. Writing
<code>list[i] = value</code> performs an overwrite-style local
mutation, and <code>delete list[i]</code> removes one visible entry.
</p>
<p>
The constructor and <a data-link-for="CRList">merge()</a> methods are
typed as taking generic objects in the coarse Web IDL summary above so
that the IDL matches the permissive JavaScript ingress behavior. The
expected object shapes are <code>CRListSnapshot</code> and
<code>CRListDelta</code> as defined by the dictionaries above.
</p>
<p>
The root predecessor is represented by the null character
<code>'\0'</code>, which serializes to <code>"\u0000"</code> in JSON.
</p>
<p>
When the current <a>snapshot</a> is JSON-compatible,
<code>JSON.stringify(list)</code> serializes the binding through that
snapshot. <code>for...of</code> iterates detached copies of the
current visible values in index order, and
<code>toString()</code> attempts to return the JSON string form of the
current snapshot.
</p>
</section>
<section>
<h3>Errors</h3>
<p>
The JavaScript binding throws <code>CRListError</code> with a string
<code>code</code> attribute for local API misuse.
</p>
<dl>
<dt><code>VALUE_NOT_CLONEABLE</code></dt>
<dd>
Thrown when a local update receives a value that is not supported by
<code>structuredClone</code>.
</dd>
<dt><code>INDEX_OUT_OF_BOUNDS</code></dt>
<dd>
Thrown when a local indexed mutation targets an invalid live range.
</dd>
<dt><code>LIST_EMPTY</code></dt>
<dd>
Thrown when a local indexed operation requires a live entry but the
visible list is empty.
</dd>
<dt><code>UPDATE_EXPECTED_AN_ARRAY</code></dt>
<dd>
Thrown by the core update algorithm when its value input is not a
list.
</dd>
<dt><code>LIST_INTEGRITY_VIOLATION</code></dt>
<dd>
Thrown when snapshot serialization detects impossible internal list
state.
</dd>
</dl>
</section>
<section>
<h3>Events</h3>
<p>
The JavaScript binding maintains an internal
<code>EventTarget</code> object as defined by DOM [[DOM]].
</p>
<p>
The binding forwards addEventListener() and removeEventListener() to
that internal event target. Local mutations and merges dispatch
synthetic events through the same target.
</p>
<p>
The JavaScript binding defines four synthetic event types. Each is a
<code>CustomEvent</code> object whose <code>detail</code> attribute is
initialized as described below [[DOM]].
</p>
<dl>
<dt><dfn>delta event</dfn></dt>
<dd>
A <code>CustomEvent</code> whose <code>detail</code> is a
<a>delta</a>. The binding dispatches this event for local visible
mutations that produce gossip material.
</dd>
<dt><dfn>change event</dfn></dt>
<dd>
A <code>CustomEvent</code> whose <code>detail</code> is a sparse
visible patch: inserted or overwritten indexes map to their visible
values, and deleted indexes map to <code>undefined</code>.
</dd>
<dt><dfn>ack event</dfn></dt>
<dd>
A <code>CustomEvent</code> whose <code>detail</code> is the current
<a>acknowledgement frontier</a> produced when
<a data-link-for="CRList">acknowledge()</a> is invoked.
</dd>
<dt><dfn>snapshot event</dfn></dt>
<dd>
A <code>CustomEvent</code> whose <code>detail</code> is the full
current snapshot produced when
<a data-link-for="CRList">snapshot()</a>
is invoked.
</dd>
</dl>