loro-crdt 0.13.1 → 0.14.1

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.
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const src_1 = require("../src");
5
+ (0, vitest_1.describe)("event", () => {
6
+ (0, vitest_1.it)("target", async () => {
7
+ const loro = new src_1.Loro();
8
+ let lastEvent;
9
+ loro.subscribe((event) => {
10
+ (0, vitest_1.expect)(event.by).toBe("local");
11
+ lastEvent = event;
12
+ });
13
+ const text = loro.getText("text");
14
+ const id = text.id;
15
+ text.insert(0, "123");
16
+ loro.commit();
17
+ await oneMs();
18
+ (0, vitest_1.expect)(lastEvent?.events[0].target).toEqual(id);
19
+ });
20
+ (0, vitest_1.it)("path", async () => {
21
+ const loro = new src_1.Loro();
22
+ let lastEvent;
23
+ loro.subscribe((event) => {
24
+ lastEvent = event;
25
+ });
26
+ const map = loro.getMap("map");
27
+ const subMap = map.setContainer("sub", new src_1.LoroMap());
28
+ subMap.set("0", "1");
29
+ loro.commit();
30
+ await oneMs();
31
+ (0, vitest_1.expect)(lastEvent?.events[1].path).toStrictEqual(["map", "sub"]);
32
+ const list = subMap.setContainer("list", new src_1.LoroList());
33
+ list.insert(0, "2");
34
+ const text = list.insertContainer(1, new src_1.LoroText());
35
+ loro.commit();
36
+ await oneMs();
37
+ text.insert(0, "3");
38
+ loro.commit();
39
+ await oneMs();
40
+ (0, vitest_1.expect)(lastEvent?.events[0].path).toStrictEqual(["map", "sub", "list", 1]);
41
+ });
42
+ (0, vitest_1.it)("text diff", async () => {
43
+ const loro = new src_1.Loro();
44
+ let lastEvent;
45
+ loro.subscribe((event) => {
46
+ lastEvent = event;
47
+ });
48
+ const text = loro.getText("t");
49
+ text.insert(0, "3");
50
+ loro.commit();
51
+ await oneMs();
52
+ (0, vitest_1.expect)(lastEvent?.events[0].diff).toStrictEqual({
53
+ type: "text",
54
+ diff: [{ insert: "3" }],
55
+ });
56
+ text.insert(1, "12");
57
+ loro.commit();
58
+ await oneMs();
59
+ (0, vitest_1.expect)(lastEvent?.events[0].diff).toStrictEqual({
60
+ type: "text",
61
+ diff: [{ retain: 1 }, { insert: "12" }],
62
+ });
63
+ });
64
+ (0, vitest_1.it)("list diff", async () => {
65
+ const loro = new src_1.Loro();
66
+ let lastEvent;
67
+ loro.subscribe((event) => {
68
+ lastEvent = event;
69
+ });
70
+ const text = loro.getList("l");
71
+ text.insert(0, "3");
72
+ loro.commit();
73
+ await oneMs();
74
+ (0, vitest_1.expect)(lastEvent?.events[0].diff).toStrictEqual({
75
+ type: "list",
76
+ diff: [{ insert: ["3"] }],
77
+ });
78
+ text.insert(1, "12");
79
+ loro.commit();
80
+ await oneMs();
81
+ (0, vitest_1.expect)(lastEvent?.events[0].diff).toStrictEqual({
82
+ type: "list",
83
+ diff: [{ retain: 1 }, { insert: ["12"] }],
84
+ });
85
+ });
86
+ (0, vitest_1.it)("map diff", async () => {
87
+ const loro = new src_1.Loro();
88
+ let lastEvent;
89
+ loro.subscribe((event) => {
90
+ lastEvent = event;
91
+ });
92
+ const map = loro.getMap("m");
93
+ map.set("0", "3");
94
+ map.set("1", "2");
95
+ loro.commit();
96
+ await oneMs();
97
+ (0, vitest_1.expect)(lastEvent?.events[0].diff).toStrictEqual({
98
+ type: "map",
99
+ updated: {
100
+ "0": "3",
101
+ "1": "2",
102
+ },
103
+ });
104
+ map.set("0", "0");
105
+ map.set("1", "1");
106
+ loro.commit();
107
+ await oneMs();
108
+ (0, vitest_1.expect)(lastEvent?.events[0].diff).toStrictEqual({
109
+ type: "map",
110
+ updated: {
111
+ "0": "0",
112
+ "1": "1",
113
+ },
114
+ });
115
+ });
116
+ (0, vitest_1.it)("tree", async () => {
117
+ const loro = new src_1.Loro();
118
+ let lastEvent;
119
+ loro.subscribe((event) => {
120
+ lastEvent = event;
121
+ });
122
+ const tree = loro.getTree("tree");
123
+ const id = tree.id;
124
+ tree.createNode();
125
+ loro.commit();
126
+ await oneMs();
127
+ (0, vitest_1.expect)(lastEvent?.events[0].target).toEqual(id);
128
+ });
129
+ (0, vitest_1.describe)("subscribe container events", () => {
130
+ (0, vitest_1.it)("text", async () => {
131
+ const loro = new src_1.Loro();
132
+ const text = loro.getText("text");
133
+ let ran = 0;
134
+ const sub = text.subscribe(loro, (event) => {
135
+ if (!ran) {
136
+ (0, vitest_1.expect)(event.events[0].diff.diff).toStrictEqual([
137
+ { insert: "123" },
138
+ ]);
139
+ }
140
+ ran += 1;
141
+ for (const containerDiff of event.events) {
142
+ (0, vitest_1.expect)(containerDiff.target).toBe(text.id);
143
+ }
144
+ });
145
+ text.insert(0, "123");
146
+ loro.commit();
147
+ await oneMs();
148
+ text.insert(1, "456");
149
+ loro.commit();
150
+ await oneMs();
151
+ (0, vitest_1.expect)(ran).toBeTruthy();
152
+ // subscribeOnce test
153
+ (0, vitest_1.expect)(text.toString()).toEqual("145623");
154
+ // unsubscribe
155
+ const oldRan = ran;
156
+ text.unsubscribe(loro, sub);
157
+ text.insert(0, "789");
158
+ loro.commit();
159
+ await oneMs();
160
+ (0, vitest_1.expect)(ran).toBe(oldRan);
161
+ });
162
+ (0, vitest_1.it)("map subscribe deep", async () => {
163
+ const loro = new src_1.Loro();
164
+ const map = loro.getMap("map");
165
+ let times = 0;
166
+ const sub = map.subscribe(loro, (event) => {
167
+ times += 1;
168
+ });
169
+ const subMap = map.setContainer("sub", new src_1.LoroMap());
170
+ loro.commit();
171
+ await oneMs();
172
+ (0, vitest_1.expect)(times).toBe(1);
173
+ const text = subMap.setContainer("k", new src_1.LoroText());
174
+ loro.commit();
175
+ await oneMs();
176
+ (0, vitest_1.expect)(times).toBe(2);
177
+ text.insert(0, "123");
178
+ loro.commit();
179
+ await oneMs();
180
+ (0, vitest_1.expect)(times).toBe(3);
181
+ // unsubscribe
182
+ loro.unsubscribe(sub);
183
+ text.insert(0, "123");
184
+ loro.commit();
185
+ await oneMs();
186
+ (0, vitest_1.expect)(times).toBe(3);
187
+ });
188
+ (0, vitest_1.it)("list subscribe deep", async () => {
189
+ const loro = new src_1.Loro();
190
+ const list = loro.getList("list");
191
+ let times = 0;
192
+ const sub = list.subscribe(loro, (_) => {
193
+ times += 1;
194
+ });
195
+ const text = list.insertContainer(0, new src_1.LoroText());
196
+ loro.commit();
197
+ await oneMs();
198
+ (0, vitest_1.expect)(times).toBe(1);
199
+ text.insert(0, "123");
200
+ await oneMs();
201
+ loro.commit();
202
+ await oneMs();
203
+ (0, vitest_1.expect)(times).toBe(2);
204
+ // unsubscribe
205
+ loro.unsubscribe(sub);
206
+ text.insert(0, "123");
207
+ loro.commit();
208
+ await oneMs();
209
+ (0, vitest_1.expect)(times).toBe(2);
210
+ });
211
+ });
212
+ (0, vitest_1.describe)("text event length should be utf16", () => {
213
+ (0, vitest_1.it)("test", async () => {
214
+ const loro = new src_1.Loro();
215
+ const text = loro.getText("text");
216
+ let string = "";
217
+ text.subscribe(loro, (event) => {
218
+ for (const containerDiff of event.events) {
219
+ const diff = containerDiff.diff;
220
+ (0, vitest_1.expect)(diff.type).toBe("text");
221
+ if (diff.type === "text") {
222
+ let newString = "";
223
+ let pos = 0;
224
+ for (const delta of diff.diff) {
225
+ if (delta.retain != null) {
226
+ newString += string.slice(pos, pos + delta.retain);
227
+ pos += delta.retain;
228
+ }
229
+ else if (delta.insert != null) {
230
+ newString += delta.insert;
231
+ }
232
+ else {
233
+ pos += delta.delete;
234
+ }
235
+ }
236
+ string = newString + string.slice(pos);
237
+ }
238
+ }
239
+ });
240
+ text.insert(0, "你好");
241
+ loro.commit();
242
+ await oneMs();
243
+ (0, vitest_1.expect)(text.toString()).toBe(string);
244
+ text.insert(1, "世界");
245
+ loro.commit();
246
+ await oneMs();
247
+ (0, vitest_1.expect)(text.toString()).toBe(string);
248
+ text.insert(2, "👍");
249
+ loro.commit();
250
+ await oneMs();
251
+ (0, vitest_1.expect)(text.toString()).toBe(string);
252
+ text.insert(2, "♪(^∇^*)");
253
+ loro.commit();
254
+ await oneMs();
255
+ (0, vitest_1.expect)(text.toString()).toBe(string);
256
+ });
257
+ });
258
+ (0, vitest_1.describe)("handler in event", () => {
259
+ (0, vitest_1.it)("test", async () => {
260
+ const loro = new src_1.Loro();
261
+ const list = loro.getList("list");
262
+ let first = true;
263
+ loro.subscribe((e) => {
264
+ if (first) {
265
+ const diff = e.events[0].diff.diff;
266
+ const text = diff[0].insert[0];
267
+ text.insert(0, "abc");
268
+ first = false;
269
+ }
270
+ });
271
+ list.insertContainer(0, new src_1.LoroText());
272
+ loro.commit();
273
+ await oneMs();
274
+ (0, vitest_1.expect)(loro.toJson().list[0]).toBe("abc");
275
+ });
276
+ });
277
+ (0, vitest_1.it)("diff can contain containers", async () => {
278
+ const doc = new src_1.Loro();
279
+ const list = doc.getList("list");
280
+ let ran = false;
281
+ doc.subscribe((event) => {
282
+ if (event.events[0].diff.type === "list") {
283
+ for (const item of event.events[0].diff.diff) {
284
+ const t = item.insert[0];
285
+ (0, vitest_1.expect)(t.toString()).toBe("Hello");
286
+ (0, vitest_1.expect)(item.insert?.length).toBe(2);
287
+ (0, vitest_1.expect)((0, src_1.getType)(item.insert[0])).toBe("Text");
288
+ (0, vitest_1.expect)((0, src_1.getType)(item.insert[1])).toBe("Map");
289
+ }
290
+ ran = true;
291
+ }
292
+ });
293
+ list.insertContainer(0, new src_1.LoroMap());
294
+ const t = list.insertContainer(0, new src_1.LoroText());
295
+ t.insert(0, "He");
296
+ t.insert(2, "llo");
297
+ doc.commit();
298
+ await new Promise((resolve) => setTimeout(resolve, 1));
299
+ (0, vitest_1.expect)(ran).toBeTruthy();
300
+ });
301
+ (0, vitest_1.it)("remote event", async () => {
302
+ const doc = new src_1.Loro();
303
+ const list = doc.getList("list");
304
+ list.insert(0, 123);
305
+ {
306
+ const doc2 = new src_1.Loro();
307
+ let triggered = false;
308
+ doc2.subscribe((event) => {
309
+ (0, vitest_1.expect)(event.by).toBe("import");
310
+ triggered = true;
311
+ });
312
+ doc2.import(doc.exportFrom());
313
+ await oneMs();
314
+ (0, vitest_1.expect)(triggered).toBeTruthy();
315
+ }
316
+ {
317
+ const doc2 = new src_1.Loro();
318
+ let triggered = false;
319
+ doc2.subscribe((event) => {
320
+ (0, vitest_1.expect)(event.by).toBe("import");
321
+ triggered = true;
322
+ });
323
+ doc2.import(doc.exportSnapshot());
324
+ await oneMs();
325
+ (0, vitest_1.expect)(triggered).toBeTruthy();
326
+ }
327
+ });
328
+ (0, vitest_1.it)("checkout event", async () => {
329
+ const doc = new src_1.Loro();
330
+ const list = doc.getList("list");
331
+ list.insert(0, 123);
332
+ doc.commit();
333
+ let triggered = false;
334
+ doc.subscribe((e) => {
335
+ (0, vitest_1.expect)(e.by).toBe("checkout");
336
+ triggered = true;
337
+ });
338
+ doc.checkout([]);
339
+ await oneMs();
340
+ (0, vitest_1.expect)(triggered).toBeTruthy();
341
+ });
342
+ });
343
+ function oneMs() {
344
+ return new Promise((r) => setTimeout(r));
345
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const src_1 = require("../src");
5
+ (0, vitest_1.it)("#211", () => {
6
+ const loro1 = new src_1.Loro();
7
+ loro1.setPeerId(0n);
8
+ const text1 = loro1.getText("text");
9
+ const loro2 = new src_1.Loro();
10
+ loro2.setPeerId(1n);
11
+ const text2 = loro2.getText("text");
12
+ console.log("[1] Insert T to #0");
13
+ text1.insert(0, "T");
14
+ loro1.commit();
15
+ show(text1, loro1, text2, loro2);
16
+ console.log("[2] Synchronize");
17
+ loro1.import(loro2.exportFrom(loro1.version()));
18
+ loro2.import(loro1.exportFrom(loro2.version()));
19
+ show(text1, loro1, text2, loro2);
20
+ const frontiers1After2 = loro1.frontiers();
21
+ const frontiers2After2 = loro2.frontiers();
22
+ console.log("[3] Append A to #0");
23
+ text1.insert(1, "A");
24
+ loro1.commit();
25
+ show(text1, loro1, text2, loro2);
26
+ console.log("[4] Append B to #1");
27
+ text2.insert(1, "B");
28
+ loro2.commit();
29
+ show(text1, loro1, text2, loro2);
30
+ console.log("[5] Play back to the frontiers after 2");
31
+ loro1.checkout(frontiers1After2);
32
+ loro2.checkout(frontiers2After2);
33
+ show(text1, loro1, text2, loro2);
34
+ console.log("[6] Check both to the latest");
35
+ loro1.checkoutToLatest();
36
+ loro2.checkoutToLatest();
37
+ show(text1, loro1, text2, loro2);
38
+ const frontiers1Before7 = loro1.frontiers();
39
+ const frontiers2Before7 = loro2.frontiers();
40
+ console.log("[7] Append B to #1");
41
+ text2.insert(2, "B");
42
+ loro2.commit();
43
+ show(text1, loro1, text2, loro2);
44
+ console.log("[8] Play back to the frontiers before 7");
45
+ console.log("----------------------------------------------------------");
46
+ loro1.checkout(frontiers1Before7);
47
+ console.log("----------------------------------------------------------");
48
+ loro2.checkout(frontiers2Before7);
49
+ show(text1, loro1, text2, loro2);
50
+ });
51
+ function show(text1, loro1, text2, loro2) {
52
+ console.log(` #0 has content: ${JSON.stringify(text1.toString())}`);
53
+ console.log(` #0 has frontiers: ${showFrontiers(loro1.frontiers())}`);
54
+ console.log(` #1 has content: ${JSON.stringify(text2.toString())}`);
55
+ console.log(` #1 has frontiers: ${showFrontiers(loro2.frontiers())}`);
56
+ }
57
+ function showFrontiers(frontiers) {
58
+ return frontiers.map((x) => `${x.peer}@${x.counter}`).join(";");
59
+ }
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const src_1 = require("../src");
5
+ const vitest_2 = require("vitest");
6
+ function assertEquals(a, b) {
7
+ (0, vitest_1.expect)(a).toStrictEqual(b);
8
+ }
9
+ (0, vitest_1.describe)("transaction", () => {
10
+ (0, vitest_1.it)("transaction", async () => {
11
+ const loro = new src_1.Loro();
12
+ const text = loro.getText("text");
13
+ let count = 0;
14
+ const sub = loro.subscribe(() => {
15
+ count += 1;
16
+ loro.unsubscribe(sub);
17
+ });
18
+ (0, vitest_1.expect)(count).toBe(0);
19
+ text.insert(0, "hello world");
20
+ (0, vitest_1.expect)(count).toBe(0);
21
+ text.insert(0, "hello world");
22
+ assertEquals(count, 0);
23
+ loro.commit();
24
+ await one_ms();
25
+ assertEquals(count, 1);
26
+ });
27
+ (0, vitest_1.it)("transaction origin", async () => {
28
+ const loro = new src_1.Loro();
29
+ const text = loro.getText("text");
30
+ let count = 0;
31
+ const sub = loro.subscribe((event) => {
32
+ count += 1;
33
+ loro.unsubscribe(sub);
34
+ assertEquals(event.origin, "origin");
35
+ });
36
+ assertEquals(count, 0);
37
+ text.insert(0, "hello world");
38
+ assertEquals(count, 0);
39
+ text.insert(0, "hello world");
40
+ assertEquals(count, 0);
41
+ loro.commit("origin");
42
+ await one_ms();
43
+ assertEquals(count, 1);
44
+ });
45
+ });
46
+ (0, vitest_1.describe)("subscribe", () => {
47
+ (0, vitest_1.it)("subscribe_lock", async () => {
48
+ const loro = new src_1.Loro();
49
+ const text = loro.getText("text");
50
+ const list = loro.getList("list");
51
+ let count = 0;
52
+ let i = 1;
53
+ const sub = loro.subscribe(() => {
54
+ if (i > 0) {
55
+ list.insert(0, i);
56
+ loro.commit();
57
+ i--;
58
+ }
59
+ count += 1;
60
+ });
61
+ text.insert(0, "hello world");
62
+ loro.commit();
63
+ await one_ms();
64
+ assertEquals(count, 2);
65
+ text.insert(0, "hello world");
66
+ loro.commit();
67
+ await one_ms();
68
+ assertEquals(count, 3);
69
+ loro.unsubscribe(sub);
70
+ text.insert(0, "hello world");
71
+ loro.commit();
72
+ await one_ms();
73
+ assertEquals(count, 3);
74
+ });
75
+ (0, vitest_1.it)("subscribe_lock2", async () => {
76
+ const loro = new src_1.Loro();
77
+ const text = loro.getText("text");
78
+ let count = 0;
79
+ const sub = loro.subscribe(() => {
80
+ count += 1;
81
+ loro.unsubscribe(sub);
82
+ });
83
+ assertEquals(count, 0);
84
+ text.insert(0, "hello world");
85
+ loro.commit();
86
+ await one_ms();
87
+ assertEquals(count, 1);
88
+ text.insert(0, "hello world");
89
+ loro.commit();
90
+ await one_ms();
91
+ assertEquals(count, 1);
92
+ });
93
+ (0, vitest_1.it)("subscribe", async () => {
94
+ const loro = new src_1.Loro();
95
+ const text = loro.getText("text");
96
+ let count = 0;
97
+ const sub = loro.subscribe(() => {
98
+ count += 1;
99
+ });
100
+ text.insert(0, "hello world");
101
+ loro.commit();
102
+ await one_ms();
103
+ assertEquals(count, 1);
104
+ text.insert(0, "hello world");
105
+ loro.commit();
106
+ await one_ms();
107
+ assertEquals(count, 2);
108
+ loro.unsubscribe(sub);
109
+ text.insert(0, "hello world");
110
+ loro.commit();
111
+ await one_ms();
112
+ assertEquals(count, 2);
113
+ });
114
+ });
115
+ (0, vitest_1.describe)("sync", () => {
116
+ (0, vitest_1.it)("two insert at beginning", async () => {
117
+ const a = new src_1.Loro();
118
+ const b = new src_1.Loro();
119
+ let a_version = undefined;
120
+ let b_version = undefined;
121
+ a.subscribe((e) => {
122
+ if (e.by == "local") {
123
+ const exported = a.exportFrom(a_version);
124
+ b.import(exported);
125
+ a_version = a.version();
126
+ }
127
+ });
128
+ b.subscribe((e) => {
129
+ if (e.by == "local") {
130
+ const exported = b.exportFrom(b_version);
131
+ a.import(exported);
132
+ b_version = b.version();
133
+ }
134
+ });
135
+ const aText = a.getText("text");
136
+ const bText = b.getText("text");
137
+ aText.insert(0, "abc");
138
+ a.commit();
139
+ await one_ms();
140
+ assertEquals(aText.toString(), bText.toString());
141
+ });
142
+ (0, vitest_1.it)("sync", () => {
143
+ const loro = new src_1.Loro();
144
+ const text = loro.getText("text");
145
+ text.insert(0, "hello world");
146
+ const loro_bk = new src_1.Loro();
147
+ loro_bk.import(loro.exportFrom(undefined));
148
+ assertEquals(loro_bk.toJson(), loro.toJson());
149
+ const text_bk = loro_bk.getText("text");
150
+ assertEquals(text_bk.toString(), "hello world");
151
+ text_bk.insert(0, "a ");
152
+ loro.import(loro_bk.exportFrom(undefined));
153
+ assertEquals(text.toString(), "a hello world");
154
+ const map = loro.getMap("map");
155
+ map.set("key", "value");
156
+ });
157
+ });
158
+ (0, vitest_1.describe)("wasm", () => {
159
+ const loro = new src_1.Loro();
160
+ const a = loro.getText("ha");
161
+ a.insert(0, "hello world");
162
+ a.delete(6, 5);
163
+ a.insert(6, "everyone");
164
+ loro.commit();
165
+ const b = loro.getMap("ha");
166
+ b.set("ab", 123);
167
+ loro.commit();
168
+ const bText = b.setContainer("hh", new src_1.LoroText());
169
+ loro.commit();
170
+ (0, vitest_1.it)("map get", () => {
171
+ assertEquals(b.get("ab"), 123);
172
+ });
173
+ (0, vitest_1.it)("getValueDeep", () => {
174
+ bText.insert(0, "hello world Text");
175
+ assertEquals(b.toJson(), { ab: 123, hh: "hello world Text" });
176
+ });
177
+ (0, vitest_1.it)("get container by id", () => {
178
+ const id = b.id;
179
+ const b2 = loro.getContainerById(id);
180
+ assertEquals(b2.toJson(), b.toJson());
181
+ assertEquals(b2.id, id);
182
+ b2.set("0", 12);
183
+ assertEquals(b2.toJson(), b.toJson());
184
+ });
185
+ });
186
+ (0, vitest_1.describe)("type", () => {
187
+ (0, vitest_1.it)("test map type", () => {
188
+ const loro = new src_1.Loro();
189
+ const map = loro.getTypedMap("map");
190
+ const v = map.getTyped(loro, "name");
191
+ (0, vitest_2.expectTypeOf)(v).toEqualTypeOf();
192
+ });
193
+ (0, vitest_1.it)("test recursive map type", () => {
194
+ const loro = new src_1.Loro();
195
+ const map = loro.getTypedMap("map");
196
+ map.setContainer("map", new src_1.LoroMap());
197
+ const subMap = map.getTyped(loro, "map");
198
+ const name = subMap.getTyped(loro, "name");
199
+ (0, vitest_2.expectTypeOf)(name).toEqualTypeOf();
200
+ });
201
+ (0, vitest_1.it)("works for list type", () => {
202
+ const loro = new src_1.Loro();
203
+ const list = loro.getTypedList("list");
204
+ list.insertTyped(0, "123");
205
+ list.insertTyped(1, 123);
206
+ const v0 = list.getTyped(loro, 0);
207
+ (0, vitest_2.expectTypeOf)(v0).toEqualTypeOf();
208
+ const v1 = list.getTyped(loro, 1);
209
+ (0, vitest_2.expectTypeOf)(v1).toEqualTypeOf();
210
+ });
211
+ (0, vitest_1.it)("test binary type", () => {
212
+ // const loro = new Loro<{ list: LoroList<[string, number]> }>();
213
+ // const list = loro.getTypedList("list");
214
+ // console.dir((list as any).__proto__);
215
+ // list.insertTyped(0, new Uint8Array(10));
216
+ // const v0 = list.getTyped(loro, 0);
217
+ // expectTypeOf(v0).toEqualTypeOf<Uint8Array>();
218
+ });
219
+ });
220
+ (0, vitest_1.describe)("tree", () => {
221
+ const loro = new src_1.Loro();
222
+ const tree = loro.getTree("root");
223
+ (0, vitest_1.it)("create", () => {
224
+ const root = tree.createNode();
225
+ const child = root.createNode();
226
+ assertEquals(child.parent().id, root.id);
227
+ });
228
+ (0, vitest_1.it)("move", () => {
229
+ const root = tree.createNode();
230
+ const child = root.createNode();
231
+ const child2 = root.createNode();
232
+ assertEquals(child2.parent().id, root.id);
233
+ child2.moveTo(child);
234
+ assertEquals(child2.parent().id, child.id);
235
+ assertEquals(child.children()[0].id, child2.id);
236
+ });
237
+ (0, vitest_1.it)("meta", () => {
238
+ const root = tree.createNode();
239
+ root.data.set("a", 123);
240
+ assertEquals(root.data.get("a"), 123);
241
+ });
242
+ });
243
+ function one_ms() {
244
+ return new Promise((resolve) => setTimeout(resolve, 1));
245
+ }