loro-crdt 0.15.4 → 0.16.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.
- package/dist/loro.d.ts +12 -9
- package/dist/loro.js +2 -2
- package/dist/loro.js.map +1 -1
- package/dist/loro.mjs +1 -1
- package/dist/loro.mjs.map +1 -1
- package/package.json +3 -2
- package/CHANGELOG.md +0 -983
- package/deno/.vscode/settings.json +0 -3
- package/deno/deno.json +0 -5
- package/deno/mod.ts +0 -1
- package/deno/test.ts +0 -13
- package/rollup.config.mjs +0 -37
- package/src/awareness.ts +0 -108
- package/src/index.ts +0 -567
- package/tsconfig.json +0 -106
- package/vite.config.ts +0 -12
package/src/index.ts
DELETED
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
export * from "loro-wasm";
|
|
2
|
-
import {
|
|
3
|
-
Container,
|
|
4
|
-
ContainerID,
|
|
5
|
-
Delta,
|
|
6
|
-
Loro,
|
|
7
|
-
LoroList,
|
|
8
|
-
LoroMap,
|
|
9
|
-
LoroText,
|
|
10
|
-
LoroTree,
|
|
11
|
-
OpId,
|
|
12
|
-
TreeID,
|
|
13
|
-
Value,
|
|
14
|
-
} from "loro-wasm";
|
|
15
|
-
export { Awareness } from "./awareness";
|
|
16
|
-
|
|
17
|
-
export type Frontiers = OpId[];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Represents a path to identify the exact location of an event's target.
|
|
21
|
-
* The path is composed of numbers (e.g., indices of a list container) strings
|
|
22
|
-
* (e.g., keys of a map container) and TreeID (the node of a tree container),
|
|
23
|
-
* indicating the absolute position of the event's source within a loro document.
|
|
24
|
-
*/
|
|
25
|
-
export type Path = (number | string | TreeID)[];
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A batch of events that created by a single `import`/`transaction`/`checkout`.
|
|
29
|
-
*
|
|
30
|
-
* @prop by - How the event is triggered.
|
|
31
|
-
* @prop origin - (Optional) Provides information about the origin of the event.
|
|
32
|
-
* @prop diff - Contains the differential information related to the event.
|
|
33
|
-
* @prop target - Identifies the container ID of the event's target.
|
|
34
|
-
* @prop path - Specifies the absolute path of the event's emitter, which can be an index of a list container or a key of a map container.
|
|
35
|
-
*/
|
|
36
|
-
export interface LoroEventBatch {
|
|
37
|
-
/**
|
|
38
|
-
* How the event is triggered.
|
|
39
|
-
*
|
|
40
|
-
* - `local`: The event is triggered by a local transaction.
|
|
41
|
-
* - `import`: The event is triggered by an import operation.
|
|
42
|
-
* - `checkout`: The event is triggered by a checkout operation.
|
|
43
|
-
*/
|
|
44
|
-
by: "local" | "import" | "checkout";
|
|
45
|
-
origin?: string;
|
|
46
|
-
/**
|
|
47
|
-
* The container ID of the current event receiver.
|
|
48
|
-
* It's undefined if the subscriber is on the root document.
|
|
49
|
-
*/
|
|
50
|
-
currentTarget?: ContainerID;
|
|
51
|
-
events: LoroEvent[];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The concrete event of Loro.
|
|
56
|
-
*/
|
|
57
|
-
export interface LoroEvent {
|
|
58
|
-
/**
|
|
59
|
-
* The container ID of the event's target.
|
|
60
|
-
*/
|
|
61
|
-
target: ContainerID;
|
|
62
|
-
diff: Diff;
|
|
63
|
-
/**
|
|
64
|
-
* The absolute path of the event's emitter, which can be an index of a list container or a key of a map container.
|
|
65
|
-
*/
|
|
66
|
-
path: Path;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type ListDiff = {
|
|
70
|
-
type: "list";
|
|
71
|
-
diff: Delta<(Value | Container)[]>[];
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type TextDiff = {
|
|
75
|
-
type: "text";
|
|
76
|
-
diff: Delta<string>[];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export type MapDiff = {
|
|
80
|
-
type: "map";
|
|
81
|
-
updated: Record<string, Value | Container | undefined>;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export type TreeDiffItem =
|
|
85
|
-
| { target: TreeID; action: "create"; parent: TreeID | undefined }
|
|
86
|
-
| { target: TreeID; action: "delete" }
|
|
87
|
-
| { target: TreeID; action: "move"; parent: TreeID | undefined };
|
|
88
|
-
|
|
89
|
-
export type TreeDiff = {
|
|
90
|
-
type: "tree";
|
|
91
|
-
diff: TreeDiffItem[];
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;
|
|
95
|
-
|
|
96
|
-
interface Listener {
|
|
97
|
-
(event: LoroEventBatch): void;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const CONTAINER_TYPES = ["Map", "Text", "List", "Tree"];
|
|
101
|
-
|
|
102
|
-
export function isContainerId(s: string): s is ContainerID {
|
|
103
|
-
return s.startsWith("cid:");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export { Loro };
|
|
107
|
-
|
|
108
|
-
/** Whether the value is a container.
|
|
109
|
-
*
|
|
110
|
-
* # Example
|
|
111
|
-
*
|
|
112
|
-
* ```ts
|
|
113
|
-
* const doc = new Loro();
|
|
114
|
-
* const map = doc.getMap("map");
|
|
115
|
-
* const list = doc.getList("list");
|
|
116
|
-
* const text = doc.getText("text");
|
|
117
|
-
* isContainer(map); // true
|
|
118
|
-
* isContainer(list); // true
|
|
119
|
-
* isContainer(text); // true
|
|
120
|
-
* isContainer(123); // false
|
|
121
|
-
* isContainer("123"); // false
|
|
122
|
-
* isContainer({}); // false
|
|
123
|
-
*/
|
|
124
|
-
export function isContainer(value: any): value is Container {
|
|
125
|
-
if (typeof value !== "object" || value == null) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const p = Object.getPrototypeOf(value);
|
|
130
|
-
if (p == null || typeof p !== "object" || typeof p["kind"] !== "function") {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return CONTAINER_TYPES.includes(value.kind());
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Get the type of a value that may be a container.
|
|
138
|
-
*
|
|
139
|
-
* # Example
|
|
140
|
-
*
|
|
141
|
-
* ```ts
|
|
142
|
-
* const doc = new Loro();
|
|
143
|
-
* const map = doc.getMap("map");
|
|
144
|
-
* const list = doc.getList("list");
|
|
145
|
-
* const text = doc.getText("text");
|
|
146
|
-
* getType(map); // "Map"
|
|
147
|
-
* getType(list); // "List"
|
|
148
|
-
* getType(text); // "Text"
|
|
149
|
-
* getType(123); // "Json"
|
|
150
|
-
* getType("123"); // "Json"
|
|
151
|
-
* getType({}); // "Json"
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export function getType<T>(
|
|
155
|
-
value: T,
|
|
156
|
-
): T extends LoroText ? "Text"
|
|
157
|
-
: T extends LoroMap<any> ? "Map"
|
|
158
|
-
: T extends LoroTree<any> ? "Tree"
|
|
159
|
-
: T extends LoroList<any> ? "List"
|
|
160
|
-
: "Json" {
|
|
161
|
-
if (isContainer(value)) {
|
|
162
|
-
return value.kind() as unknown as any;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return "Json" as any;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
declare module "loro-wasm" {
|
|
169
|
-
interface Loro {
|
|
170
|
-
subscribe(listener: Listener): number;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
interface Loro<
|
|
174
|
-
T extends Record<string, Container> = Record<string, Container>,
|
|
175
|
-
> {
|
|
176
|
-
/**
|
|
177
|
-
* Get a LoroMap by container id
|
|
178
|
-
*
|
|
179
|
-
* The object returned is a new js object each time because it need to cross
|
|
180
|
-
* the WASM boundary.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* import { Loro } from "loro-crdt";
|
|
185
|
-
*
|
|
186
|
-
* const doc = new Loro();
|
|
187
|
-
* const map = doc.getMap("map");
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
getMap<Key extends (keyof T) | ContainerID>(
|
|
191
|
-
name: Key,
|
|
192
|
-
): T[Key] extends LoroMap ? T[Key] : LoroMap;
|
|
193
|
-
/**
|
|
194
|
-
* Get a LoroList by container id
|
|
195
|
-
*
|
|
196
|
-
* The object returned is a new js object each time because it need to cross
|
|
197
|
-
* the WASM boundary.
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```ts
|
|
201
|
-
* import { Loro } from "loro-crdt";
|
|
202
|
-
*
|
|
203
|
-
* const doc = new Loro();
|
|
204
|
-
* const list = doc.getList("list");
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
getList<Key extends (keyof T) | ContainerID>(
|
|
208
|
-
name: Key,
|
|
209
|
-
): T[Key] extends LoroList ? T[Key] : LoroList;
|
|
210
|
-
/**
|
|
211
|
-
* Get a LoroMovableList by container id
|
|
212
|
-
*
|
|
213
|
-
* The object returned is a new js object each time because it need to cross
|
|
214
|
-
* the WASM boundary.
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* import { Loro } from "loro-crdt";
|
|
219
|
-
*
|
|
220
|
-
* const doc = new Loro();
|
|
221
|
-
* const list = doc.getList("list");
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
getMovableList<Key extends (keyof T) | ContainerID>(
|
|
225
|
-
name: Key,
|
|
226
|
-
): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;
|
|
227
|
-
/**
|
|
228
|
-
* Get a LoroTree by container id
|
|
229
|
-
*
|
|
230
|
-
* The object returned is a new js object each time because it need to cross
|
|
231
|
-
* the WASM boundary.
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```ts
|
|
235
|
-
* import { Loro } from "loro-crdt";
|
|
236
|
-
*
|
|
237
|
-
* const doc = new Loro();
|
|
238
|
-
* const tree = doc.getTree("tree");
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
getTree<Key extends (keyof T) | ContainerID>(
|
|
242
|
-
name: Key,
|
|
243
|
-
): T[Key] extends LoroTree ? T[Key] : LoroTree;
|
|
244
|
-
getText(key: string | ContainerID): LoroText;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
interface LoroList<T = unknown> {
|
|
248
|
-
new (): LoroList<T>;
|
|
249
|
-
/**
|
|
250
|
-
* Get elements of the list. If the value is a child container, the corresponding
|
|
251
|
-
* `Container` will be returned.
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```ts
|
|
255
|
-
* import { Loro } from "loro-crdt";
|
|
256
|
-
*
|
|
257
|
-
* const doc = new Loro();
|
|
258
|
-
* const list = doc.getList("list");
|
|
259
|
-
* list.insert(0, 100);
|
|
260
|
-
* list.insert(1, "foo");
|
|
261
|
-
* list.insert(2, true);
|
|
262
|
-
* list.insertContainer(3, new LoroText());
|
|
263
|
-
* console.log(list.value); // [100, "foo", true, LoroText];
|
|
264
|
-
* ```
|
|
265
|
-
*/
|
|
266
|
-
toArray(): T[];
|
|
267
|
-
/**
|
|
268
|
-
* Insert a container at the index.
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* ```ts
|
|
272
|
-
* import { Loro, LoroText } from "loro-crdt";
|
|
273
|
-
*
|
|
274
|
-
* const doc = new Loro();
|
|
275
|
-
* const list = doc.getList("list");
|
|
276
|
-
* list.insert(0, 100);
|
|
277
|
-
* const text = list.insertContainer(1, new LoroText());
|
|
278
|
-
* text.insert(0, "Hello");
|
|
279
|
-
* console.log(list.toJSON()); // [100, "Hello"];
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
insertContainer<C extends Container>(
|
|
283
|
-
pos: number,
|
|
284
|
-
child: C,
|
|
285
|
-
): T extends C ? T : C;
|
|
286
|
-
/**
|
|
287
|
-
* Get the value at the index. If the value is a container, the corresponding handler will be returned.
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* ```ts
|
|
291
|
-
* import { Loro } from "loro-crdt";
|
|
292
|
-
*
|
|
293
|
-
* const doc = new Loro();
|
|
294
|
-
* const list = doc.getList("list");
|
|
295
|
-
* list.insert(0, 100);
|
|
296
|
-
* console.log(list.get(0)); // 100
|
|
297
|
-
* console.log(list.get(1)); // undefined
|
|
298
|
-
* ```
|
|
299
|
-
*/
|
|
300
|
-
get(index: number): T;
|
|
301
|
-
/**
|
|
302
|
-
* Insert a value at index.
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* ```ts
|
|
306
|
-
* import { Loro } from "loro-crdt";
|
|
307
|
-
*
|
|
308
|
-
* const doc = new Loro();
|
|
309
|
-
* const list = doc.getList("list");
|
|
310
|
-
* list.insert(0, 100);
|
|
311
|
-
* list.insert(1, "foo");
|
|
312
|
-
* list.insert(2, true);
|
|
313
|
-
* console.log(list.value); // [100, "foo", true];
|
|
314
|
-
* ```
|
|
315
|
-
*/
|
|
316
|
-
insert<V extends T>(pos: number, value: Exclude<V, Container>): void;
|
|
317
|
-
delete(pos: number, len: number): void;
|
|
318
|
-
push<V extends T>(value: Exclude<V, Container>): void;
|
|
319
|
-
subscribe(listener: Listener): number;
|
|
320
|
-
getAttached(): undefined | LoroList<T>;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
interface LoroMovableList<T = unknown> {
|
|
324
|
-
new (): LoroMovableList<T>;
|
|
325
|
-
/**
|
|
326
|
-
* Get elements of the list. If the value is a child container, the corresponding
|
|
327
|
-
* `Container` will be returned.
|
|
328
|
-
*
|
|
329
|
-
* @example
|
|
330
|
-
* ```ts
|
|
331
|
-
* import { Loro, LoroText } from "loro-crdt";
|
|
332
|
-
*
|
|
333
|
-
* const doc = new Loro();
|
|
334
|
-
* const list = doc.getMovableList("list");
|
|
335
|
-
* list.insert(0, 100);
|
|
336
|
-
* list.insert(1, "foo");
|
|
337
|
-
* list.insert(2, true);
|
|
338
|
-
* list.insertContainer(3, new LoroText());
|
|
339
|
-
* console.log(list.value); // [100, "foo", true, LoroText];
|
|
340
|
-
* ```
|
|
341
|
-
*/
|
|
342
|
-
toArray(): T[];
|
|
343
|
-
/**
|
|
344
|
-
* Insert a container at the index.
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* ```ts
|
|
348
|
-
* import { Loro } from "loro-crdt";
|
|
349
|
-
*
|
|
350
|
-
* const doc = new Loro();
|
|
351
|
-
* const list = doc.getMovableList("list");
|
|
352
|
-
* list.insert(0, 100);
|
|
353
|
-
* const text = list.insertContainer(1, new LoroText());
|
|
354
|
-
* text.insert(0, "Hello");
|
|
355
|
-
* console.log(list.toJSON()); // [100, "Hello"];
|
|
356
|
-
* ```
|
|
357
|
-
*/
|
|
358
|
-
insertContainer<C extends Container>(
|
|
359
|
-
pos: number,
|
|
360
|
-
child: C,
|
|
361
|
-
): T extends C ? T : C;
|
|
362
|
-
/**
|
|
363
|
-
* Get the value at the index. If the value is a container, the corresponding handler will be returned.
|
|
364
|
-
*
|
|
365
|
-
* @example
|
|
366
|
-
* ```ts
|
|
367
|
-
* import { Loro } from "loro-crdt";
|
|
368
|
-
*
|
|
369
|
-
* const doc = new Loro();
|
|
370
|
-
* const list = doc.getMoableList("list");
|
|
371
|
-
* list.insert(0, 100);
|
|
372
|
-
* console.log(list.get(0)); // 100
|
|
373
|
-
* console.log(list.get(1)); // undefined
|
|
374
|
-
* ```
|
|
375
|
-
*/
|
|
376
|
-
get(index: number): T;
|
|
377
|
-
/**
|
|
378
|
-
* Insert a value at index.
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* ```ts
|
|
382
|
-
* import { Loro } from "loro-crdt";
|
|
383
|
-
*
|
|
384
|
-
* const doc = new Loro();
|
|
385
|
-
* const list = doc.getMovableList("list");
|
|
386
|
-
* list.insert(0, 100);
|
|
387
|
-
* list.insert(1, "foo");
|
|
388
|
-
* list.insert(2, true);
|
|
389
|
-
* console.log(list.value); // [100, "foo", true];
|
|
390
|
-
* ```
|
|
391
|
-
*/
|
|
392
|
-
insert<V extends T>(pos: number, value: Exclude<V, Container>): void;
|
|
393
|
-
delete(pos: number, len: number): void;
|
|
394
|
-
push<V extends T>(value: Exclude<V, Container>): void;
|
|
395
|
-
subscribe(listener: Listener): number;
|
|
396
|
-
getAttached(): undefined | LoroMovableList<T>;
|
|
397
|
-
/**
|
|
398
|
-
* Set the value at the given position.
|
|
399
|
-
*
|
|
400
|
-
* It's different from `delete` + `insert` that it will replace the value at the position.
|
|
401
|
-
*
|
|
402
|
-
* For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.
|
|
403
|
-
* If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.
|
|
404
|
-
*
|
|
405
|
-
* But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations
|
|
406
|
-
* and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.
|
|
407
|
-
*
|
|
408
|
-
* @example
|
|
409
|
-
* ```ts
|
|
410
|
-
* import { Loro } from "loro-crdt";
|
|
411
|
-
*
|
|
412
|
-
* const doc = new Loro();
|
|
413
|
-
* const list = doc.getList("list");
|
|
414
|
-
* list.insert(0, 100);
|
|
415
|
-
* list.insert(1, "foo");
|
|
416
|
-
* list.insert(2, true);
|
|
417
|
-
* list.set(1, "bar");
|
|
418
|
-
* console.log(list.value); // [100, "bar", true];
|
|
419
|
-
* ```
|
|
420
|
-
*/
|
|
421
|
-
set<V extends T>(pos: number, value: Exclude<V, Container>): void;
|
|
422
|
-
/**
|
|
423
|
-
* Set a container at the index.
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
* import { Loro } from "loro-crdt";
|
|
428
|
-
*
|
|
429
|
-
* const doc = new Loro();
|
|
430
|
-
* const list = doc.getMovableList("list");
|
|
431
|
-
* list.insert(0, 100);
|
|
432
|
-
* const text = list.setContainer(0, new LoroText());
|
|
433
|
-
* text.insert(0, "Hello");
|
|
434
|
-
* console.log(list.toJSON()); // ["Hello"];
|
|
435
|
-
* ```
|
|
436
|
-
*/
|
|
437
|
-
setContainer<C extends Container>(
|
|
438
|
-
pos: number,
|
|
439
|
-
child: C,
|
|
440
|
-
): T extends C ? T : C;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
interface LoroMap<
|
|
444
|
-
T extends Record<string, unknown> = Record<string, unknown>,
|
|
445
|
-
> {
|
|
446
|
-
new (): LoroMap<T>;
|
|
447
|
-
/**
|
|
448
|
-
* Get the value of the key. If the value is a child container, the corresponding
|
|
449
|
-
* `Container` will be returned.
|
|
450
|
-
*
|
|
451
|
-
* The object returned is a new js object each time because it need to cross
|
|
452
|
-
*
|
|
453
|
-
* @example
|
|
454
|
-
* ```ts
|
|
455
|
-
* import { Loro } from "loro-crdt";
|
|
456
|
-
*
|
|
457
|
-
* const doc = new Loro();
|
|
458
|
-
* const map = doc.getMap("map");
|
|
459
|
-
* map.set("foo", "bar");
|
|
460
|
-
* const bar = map.get("foo");
|
|
461
|
-
* ```
|
|
462
|
-
*/
|
|
463
|
-
getOrCreateContainer<C extends Container>(key: string, child: C): C;
|
|
464
|
-
/**
|
|
465
|
-
* Set the key with a container.
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* import { Loro } from "loro-crdt";
|
|
470
|
-
*
|
|
471
|
-
* const doc = new Loro();
|
|
472
|
-
* const map = doc.getMap("map");
|
|
473
|
-
* map.set("foo", "bar");
|
|
474
|
-
* const text = map.setContainer("text", new LoroText());
|
|
475
|
-
* const list = map.setContainer("list", new LoroText());
|
|
476
|
-
* ```
|
|
477
|
-
*/
|
|
478
|
-
setContainer<C extends Container, Key extends keyof T>(
|
|
479
|
-
key: Key,
|
|
480
|
-
child: C,
|
|
481
|
-
): NonNullableType<T[Key]> extends C ? NonNullableType<T[Key]> : C;
|
|
482
|
-
/**
|
|
483
|
-
* Get the value of the key. If the value is a child container, the corresponding
|
|
484
|
-
* `Container` will be returned.
|
|
485
|
-
*
|
|
486
|
-
* The object/value returned is a new js object/value each time because it need to cross
|
|
487
|
-
* the WASM boundary.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```ts
|
|
491
|
-
* import { Loro } from "loro-crdt";
|
|
492
|
-
*
|
|
493
|
-
* const doc = new Loro();
|
|
494
|
-
* const map = doc.getMap("map");
|
|
495
|
-
* map.set("foo", "bar");
|
|
496
|
-
* const bar = map.get("foo");
|
|
497
|
-
* ```
|
|
498
|
-
*/
|
|
499
|
-
get<Key extends keyof T>(key: Key): T[Key];
|
|
500
|
-
/**
|
|
501
|
-
* Set the key with the value.
|
|
502
|
-
*
|
|
503
|
-
* If the value of the key is exist, the old value will be updated.
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* ```ts
|
|
507
|
-
* import { Loro } from "loro-crdt";
|
|
508
|
-
*
|
|
509
|
-
* const doc = new Loro();
|
|
510
|
-
* const map = doc.getMap("map");
|
|
511
|
-
* map.set("foo", "bar");
|
|
512
|
-
* map.set("foo", "baz");
|
|
513
|
-
* ```
|
|
514
|
-
*/
|
|
515
|
-
set<Key extends keyof T, V extends T[Key]>(
|
|
516
|
-
key: Key,
|
|
517
|
-
value: Exclude<V, Container>,
|
|
518
|
-
): void;
|
|
519
|
-
delete(key: string): void;
|
|
520
|
-
subscribe(listener: Listener): number;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
interface LoroText {
|
|
524
|
-
new (): LoroText;
|
|
525
|
-
insert(pos: number, text: string): void;
|
|
526
|
-
delete(pos: number, len: number): void;
|
|
527
|
-
subscribe(listener: Listener): number;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
interface LoroTree<
|
|
531
|
-
T extends Record<string, unknown> = Record<string, unknown>,
|
|
532
|
-
> {
|
|
533
|
-
new (): LoroTree<T>;
|
|
534
|
-
createNode(parent: TreeID | undefined): LoroTreeNode<T>;
|
|
535
|
-
move(target: TreeID, parent: TreeID | undefined): void;
|
|
536
|
-
delete(target: TreeID): void;
|
|
537
|
-
has(target: TreeID): boolean;
|
|
538
|
-
getNodeByID(target: TreeID): LoroTreeNode;
|
|
539
|
-
subscribe(listener: Listener): number;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
interface LoroTreeNode<
|
|
543
|
-
T extends Record<string, unknown> = Record<string, unknown>,
|
|
544
|
-
> {
|
|
545
|
-
/**
|
|
546
|
-
* Get the associated metadata map container of a tree node.
|
|
547
|
-
*/
|
|
548
|
-
readonly data: LoroMap<T>;
|
|
549
|
-
createNode(): LoroTreeNode<T>;
|
|
550
|
-
setAsRoot(): void;
|
|
551
|
-
moveTo(parent: LoroTreeNode<T>): void;
|
|
552
|
-
parent(): LoroTreeNode<T> | undefined;
|
|
553
|
-
children(): Array<LoroTreeNode<T>>;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
interface AwarenessWasm<
|
|
557
|
-
T extends Value = Value,
|
|
558
|
-
> {
|
|
559
|
-
getState(peer: PeerID): T | undefined;
|
|
560
|
-
getTimestamp(peer: PeerID): number | undefined;
|
|
561
|
-
getAllStates(): Record<PeerID, T>;
|
|
562
|
-
setLocalState(value: T): void;
|
|
563
|
-
removeOutdated(): PeerID[];
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
type NonNullableType<T> = Exclude<T, null | undefined>;
|
package/tsconfig.json
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
/* Projects */
|
|
5
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
6
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
7
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
8
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
9
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
10
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
11
|
-
/* Language and Environment */
|
|
12
|
-
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
13
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
14
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
15
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
16
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
17
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
18
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
19
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
20
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
21
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
22
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
23
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
24
|
-
/* Modules */
|
|
25
|
-
"module": "commonjs" /* Specify what module code is generated. */,
|
|
26
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
27
|
-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
28
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
29
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
30
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
31
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
32
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
33
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
34
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
35
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
36
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
37
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
38
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
39
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
40
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
41
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
42
|
-
/* JavaScript Support */
|
|
43
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
44
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
45
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
46
|
-
/* Emit */
|
|
47
|
-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
48
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
49
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
50
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
51
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
52
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
53
|
-
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
|
54
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
55
|
-
"noEmit": true /* Disable emitting files from a compilation. */,
|
|
56
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
57
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
58
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
59
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
60
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
61
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
62
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
63
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
64
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
65
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
66
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
67
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
68
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
69
|
-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
70
|
-
/* Interop Constraints */
|
|
71
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
72
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
73
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
74
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
75
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
76
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
77
|
-
/* Type Checking */
|
|
78
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
79
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
80
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
81
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
82
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
83
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
84
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
85
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
86
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
87
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
88
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
89
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
90
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
91
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
92
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
93
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
94
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
95
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
96
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
97
|
-
/* Completeness */
|
|
98
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
99
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
100
|
-
},
|
|
101
|
-
"exclude": [
|
|
102
|
-
"node_modules",
|
|
103
|
-
"dist",
|
|
104
|
-
"deno"
|
|
105
|
-
]
|
|
106
|
-
}
|
package/vite.config.ts
DELETED