loro-crdt 0.2.5

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,3 @@
1
+ {
2
+ "deno.enable": false
3
+ }
package/dist/loro.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { ContainerID, PrelimList, PrelimMap, PrelimText } from 'loro-wasm';
2
+ export { ContainerID, ContainerType, Loro, LoroList, LoroMap, LoroText, PrelimList, PrelimMap, PrelimText, Transaction, setPanicHook } from 'loro-wasm';
3
+
4
+ type Value = ContainerID | string | number | null | {
5
+ [key: string]: Value;
6
+ } | Value[];
7
+ type Prelim = PrelimList | PrelimMap | PrelimText;
8
+ type Path = (number | string)[];
9
+ type Delta<T> = {
10
+ type: "insert";
11
+ value: T;
12
+ } | {
13
+ type: "delete";
14
+ len: number;
15
+ } | {
16
+ type: "retain";
17
+ len: number;
18
+ };
19
+ type ListDiff = {
20
+ type: "list";
21
+ diff: Delta<Value[]>[];
22
+ };
23
+ type TextDiff = {
24
+ type: "text";
25
+ diff: Delta<string>[];
26
+ };
27
+ type MapDIff = {
28
+ type: "map";
29
+ diff: {
30
+ added: Record<string, Value>;
31
+ deleted: Record<string, Value>;
32
+ updated: Record<string, {
33
+ old: Value;
34
+ new: Value;
35
+ }>;
36
+ };
37
+ };
38
+ type Diff = ListDiff | TextDiff | MapDIff;
39
+ interface LoroEvent {
40
+ local: boolean;
41
+ origin?: string;
42
+ diff: Diff[];
43
+ target: ContainerID;
44
+ path: Path;
45
+ }
46
+ interface Listener {
47
+ (event: LoroEvent): void;
48
+ }
49
+ declare function isContainerId(s: string): s is ContainerID;
50
+
51
+ declare module "loro-wasm" {
52
+ interface Loro {
53
+ subscribe(listener: Listener): number;
54
+ transact(f: (tx: Transaction) => void, origin?: string): void;
55
+ }
56
+ interface LoroList {
57
+ insertContainer(txn: Transaction | Loro, pos: number, container: "Map"): LoroMap;
58
+ insertContainer(txn: Transaction | Loro, pos: number, container: "List"): LoroList;
59
+ insertContainer(txn: Transaction | Loro, pos: number, container: "Text"): LoroText;
60
+ insertContainer(txn: Transaction | Loro, pos: number, container: string): never;
61
+ get(index: number): Value;
62
+ insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void;
63
+ delete(txn: Transaction | Loro, pos: number, len: number): void;
64
+ subscribe(txn: Transaction | Loro, listener: Listener): number;
65
+ subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
66
+ subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
67
+ }
68
+ interface LoroMap {
69
+ insertContainer(txn: Transaction | Loro, key: string, container_type: "Map"): LoroMap;
70
+ insertContainer(txn: Transaction | Loro, key: string, container_type: "List"): LoroList;
71
+ insertContainer(txn: Transaction | Loro, key: string, container_type: "Text"): LoroText;
72
+ insertContainer(txn: Transaction | Loro, key: string, container_type: string): never;
73
+ get(key: string): Value;
74
+ set(txn: Transaction | Loro, key: string, value: Value | Prelim): void;
75
+ delete(txn: Transaction | Loro, key: string): void;
76
+ subscribe(txn: Transaction | Loro, listener: Listener): number;
77
+ subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
78
+ subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
79
+ }
80
+ interface LoroText {
81
+ insert(txn: Transaction | Loro, pos: number, text: string): void;
82
+ delete(txn: Transaction | Loro, pos: number, len: number): void;
83
+ subscribe(txn: Transaction | Loro, listener: Listener): number;
84
+ subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
85
+ subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
86
+ }
87
+ }
88
+
89
+ export { Delta, Diff, ListDiff, LoroEvent, MapDIff, Path, Prelim, TextDiff, Value, isContainerId };
package/dist/loro.js ADDED
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ var loroWasm = require('loro-wasm');
4
+
5
+ loroWasm.Loro.prototype.transact = function(cb, origin) {
6
+ this.__raw__transactionWithOrigin(origin, (txn) => {
7
+ try {
8
+ cb(txn);
9
+ } finally {
10
+ txn.commit();
11
+ txn.free();
12
+ }
13
+ });
14
+ };
15
+ loroWasm.LoroText.prototype.insert = function(txn, pos, text) {
16
+ if (txn instanceof loroWasm.Loro) {
17
+ this.__loro_insert(txn, pos, text);
18
+ } else {
19
+ this.__txn_insert(txn, pos, text);
20
+ }
21
+ };
22
+ loroWasm.LoroText.prototype.delete = function(txn, pos, len) {
23
+ if (txn instanceof loroWasm.Loro) {
24
+ this.__loro_delete(txn, pos, len);
25
+ } else {
26
+ this.__txn_delete(txn, pos, len);
27
+ }
28
+ };
29
+ loroWasm.LoroList.prototype.insert = function(txn, pos, len) {
30
+ if (txn instanceof loroWasm.Loro) {
31
+ this.__loro_insert(txn, pos, len);
32
+ } else {
33
+ this.__txn_insert(txn, pos, len);
34
+ }
35
+ };
36
+ loroWasm.LoroList.prototype.delete = function(txn, pos, len) {
37
+ if (txn instanceof loroWasm.Loro) {
38
+ this.__loro_delete(txn, pos, len);
39
+ } else {
40
+ this.__txn_delete(txn, pos, len);
41
+ }
42
+ };
43
+ loroWasm.LoroMap.prototype.set = function(txn, key, value) {
44
+ if (txn instanceof loroWasm.Loro) {
45
+ this.__loro_insert(txn, key, value);
46
+ } else {
47
+ this.__txn_insert(txn, key, value);
48
+ }
49
+ };
50
+ loroWasm.LoroMap.prototype.delete = function(txn, key) {
51
+ if (txn instanceof loroWasm.Loro) {
52
+ this.__loro_delete(txn, key);
53
+ } else {
54
+ this.__txn_delete(txn, key);
55
+ }
56
+ };
57
+ const CONTAINER_TYPES = ["Map", "Text", "List"];
58
+ function isContainerId(s) {
59
+ try {
60
+ if (s.startsWith("/")) {
61
+ const [_, type] = s.slice(1).split(":");
62
+ if (!CONTAINER_TYPES.includes(type)) {
63
+ return false;
64
+ }
65
+ } else {
66
+ const [id, type] = s.split(":");
67
+ if (!CONTAINER_TYPES.includes(type)) {
68
+ return false;
69
+ }
70
+ const [counter, client] = id.split("@");
71
+ Number.parseInt(counter);
72
+ Number.parseInt(client);
73
+ }
74
+ return true;
75
+ } catch (e) {
76
+ return false;
77
+ }
78
+ }
79
+
80
+ Object.defineProperty(exports, 'Loro', {
81
+ enumerable: true,
82
+ get: function () { return loroWasm.Loro; }
83
+ });
84
+ Object.defineProperty(exports, 'LoroList', {
85
+ enumerable: true,
86
+ get: function () { return loroWasm.LoroList; }
87
+ });
88
+ Object.defineProperty(exports, 'LoroMap', {
89
+ enumerable: true,
90
+ get: function () { return loroWasm.LoroMap; }
91
+ });
92
+ Object.defineProperty(exports, 'LoroText', {
93
+ enumerable: true,
94
+ get: function () { return loroWasm.LoroText; }
95
+ });
96
+ Object.defineProperty(exports, 'PrelimList', {
97
+ enumerable: true,
98
+ get: function () { return loroWasm.PrelimList; }
99
+ });
100
+ Object.defineProperty(exports, 'PrelimMap', {
101
+ enumerable: true,
102
+ get: function () { return loroWasm.PrelimMap; }
103
+ });
104
+ Object.defineProperty(exports, 'PrelimText', {
105
+ enumerable: true,
106
+ get: function () { return loroWasm.PrelimText; }
107
+ });
108
+ Object.defineProperty(exports, 'Transaction', {
109
+ enumerable: true,
110
+ get: function () { return loroWasm.Transaction; }
111
+ });
112
+ Object.defineProperty(exports, 'setPanicHook', {
113
+ enumerable: true,
114
+ get: function () { return loroWasm.setPanicHook; }
115
+ });
116
+ exports.isContainerId = isContainerId;
117
+ //# sourceMappingURL=loro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loro.js","sources":["../src/index.ts"],"sourcesContent":["export {\n LoroList,\n LoroMap,\n LoroText,\n PrelimList,\n PrelimMap,\n PrelimText,\n setPanicHook,\n Transaction,\n} from \"loro-wasm\";\nimport { PrelimMap } from \"loro-wasm\";\nimport { PrelimText } from \"loro-wasm\";\nimport { PrelimList } from \"loro-wasm\";\nimport {\n ContainerID,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n Transaction,\n} from \"loro-wasm\";\n\nexport type { ContainerID, ContainerType } from \"loro-wasm\";\n\nLoro.prototype.transact = function (cb, origin) {\n this.__raw__transactionWithOrigin(origin, (txn: Transaction) => {\n try {\n cb(txn);\n } finally {\n txn.commit();\n txn.free();\n }\n });\n};\n\nLoroText.prototype.insert = function (txn, pos, text) {\n if (txn instanceof Loro) {\n this.__loro_insert(txn, pos, text);\n } else {\n this.__txn_insert(txn, pos, text);\n }\n};\n\nLoroText.prototype.delete = function (txn, pos, len) {\n if (txn instanceof Loro) {\n this.__loro_delete(txn, pos, len);\n } else {\n this.__txn_delete(txn, pos, len);\n }\n};\n\nLoroList.prototype.insert = function (txn, pos, len) {\n if (txn instanceof Loro) {\n this.__loro_insert(txn, pos, len);\n } else {\n this.__txn_insert(txn, pos, len);\n }\n};\n\nLoroList.prototype.delete = function (txn, pos, len) {\n if (txn instanceof Loro) {\n this.__loro_delete(txn, pos, len);\n } else {\n this.__txn_delete(txn, pos, len);\n }\n};\n\nLoroMap.prototype.set = function (txn, key, value) {\n if (txn instanceof Loro) {\n this.__loro_insert(txn, key, value);\n } else {\n this.__txn_insert(txn, key, value);\n }\n};\n\nLoroMap.prototype.delete = function (txn, key) {\n if (txn instanceof Loro) {\n this.__loro_delete(txn, key);\n } else {\n this.__txn_delete(txn, key);\n }\n};\n\nexport type Value =\n | ContainerID\n | string\n | number\n | null\n | { [key: string]: Value }\n | Value[];\n\nexport type Prelim = PrelimList | PrelimMap | PrelimText;\n\nexport type Path = (number | string)[];\nexport type Delta<T> = {\n type: \"insert\";\n value: T;\n} | {\n type: \"delete\";\n len: number;\n} | {\n type: \"retain\";\n len: number;\n};\n\nexport type ListDiff = {\n type: \"list\";\n diff: Delta<Value[]>[];\n};\n\nexport type TextDiff = {\n type: \"text\";\n diff: Delta<string>[];\n};\n\nexport type MapDIff = {\n type: \"map\";\n diff: {\n added: Record<string, Value>;\n deleted: Record<string, Value>;\n updated: Record<string, {\n old: Value;\n new: Value;\n }>;\n };\n};\n\nexport type Diff = ListDiff | TextDiff | MapDIff;\n\nexport interface LoroEvent {\n local: boolean;\n origin?: string;\n diff: Diff[];\n target: ContainerID;\n path: Path;\n}\n\ninterface Listener {\n (event: LoroEvent): void;\n}\n\nconst CONTAINER_TYPES = [\"Map\", \"Text\", \"List\"];\n\nexport function isContainerId(s: string): s is ContainerID {\n try {\n if (s.startsWith(\"/\")) {\n const [_, type] = s.slice(1).split(\":\");\n if (!CONTAINER_TYPES.includes(type)) {\n return false;\n }\n } else {\n const [id, type] = s.split(\":\");\n if (!CONTAINER_TYPES.includes(type)) {\n return false;\n }\n\n const [counter, client] = id.split(\"@\");\n Number.parseInt(counter);\n Number.parseInt(client);\n }\n\n return true;\n } catch (e) {\n return false;\n }\n}\n\nexport { Loro };\n\ndeclare module \"loro-wasm\" {\n interface Loro {\n subscribe(listener: Listener): number;\n transact(f: (tx: Transaction) => void, origin?: string): void;\n }\n\n interface LoroList {\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: \"Map\",\n ): LoroMap;\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: \"List\",\n ): LoroList;\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: \"Text\",\n ): LoroText;\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: string,\n ): never;\n\n get(index: number): Value;\n insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void;\n delete(txn: Transaction | Loro, pos: number, len: number): void;\n subscribe(txn: Transaction | Loro, listener: Listener): number;\n subscribeDeep(txn: Transaction | Loro, listener: Listener): number;\n subscribeOnce(txn: Transaction | Loro, listener: Listener): number;\n }\n\n interface LoroMap {\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: \"Map\",\n ): LoroMap;\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: \"List\",\n ): LoroList;\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: \"Text\",\n ): LoroText;\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: string,\n ): never;\n\n get(key: string): Value;\n set(txn: Transaction | Loro, key: string, value: Value | Prelim): void;\n delete(txn: Transaction | Loro, key: string): void;\n subscribe(txn: Transaction | Loro, listener: Listener): number;\n subscribeDeep(txn: Transaction | Loro, listener: Listener): number;\n subscribeOnce(txn: Transaction | Loro, listener: Listener): number;\n }\n\n interface LoroText {\n insert(txn: Transaction | Loro, pos: number, text: string): void;\n delete(txn: Transaction | Loro, pos: number, len: number): void;\n subscribe(txn: Transaction | Loro, listener: Listener): number;\n subscribeDeep(txn: Transaction | Loro, listener: Listener): number;\n subscribeOnce(txn: Transaction | Loro, listener: Listener): number;\n }\n}\n"],"names":["Loro","LoroText","LoroList","LoroMap"],"mappings":";;;;AAwBAA,aAAA,CAAK,SAAU,CAAA,QAAA,GAAW,SAAU,EAAA,EAAI,MAAQ,EAAA;AAC9C,EAAK,IAAA,CAAA,4BAAA,CAA6B,MAAQ,EAAA,CAAC,GAAqB,KAAA;AAC9D,IAAI,IAAA;AACF,MAAA,EAAA,CAAG,GAAG,CAAA,CAAA;AAAA,KACN,SAAA;AACA,MAAA,GAAA,CAAI,MAAO,EAAA,CAAA;AACX,MAAA,GAAA,CAAI,IAAK,EAAA,CAAA;AAAA,KACX;AAAA,GACD,CAAA,CAAA;AACH,CAAA,CAAA;AAEAC,iBAAAA,CAAS,SAAU,CAAA,MAAA,GAAS,SAAU,GAAA,EAAK,KAAK,IAAM,EAAA;AACpD,EAAA,IAAI,eAAeD,aAAM,EAAA;AACvB,IAAK,IAAA,CAAA,aAAA,CAAc,GAAK,EAAA,GAAA,EAAK,IAAI,CAAA,CAAA;AAAA,GAC5B,MAAA;AACL,IAAK,IAAA,CAAA,YAAA,CAAa,GAAK,EAAA,GAAA,EAAK,IAAI,CAAA,CAAA;AAAA,GAClC;AACF,CAAA,CAAA;AAEAC,iBAAAA,CAAS,SAAU,CAAA,MAAA,GAAS,SAAU,GAAA,EAAK,KAAK,GAAK,EAAA;AACnD,EAAA,IAAI,eAAeD,aAAM,EAAA;AACvB,IAAK,IAAA,CAAA,aAAA,CAAc,GAAK,EAAA,GAAA,EAAK,GAAG,CAAA,CAAA;AAAA,GAC3B,MA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imText, Transaction, setPanicHook } from 'loro-wasm';
3
+
4
+ Loro.prototype.transact = function(cb, origin) {
5
+ this.__raw__transactionWithOrigin(origin, (txn) => {
6
+ try {
7
+ cb(txn);
8
+ } finally {
9
+ txn.commit();
10
+ txn.free();
11
+ }
12
+ });
13
+ };
14
+ LoroText.prototype.insert = function(txn, pos, text) {
15
+ if (txn instanceof Loro) {
16
+ this.__loro_insert(txn, pos, text);
17
+ } else {
18
+ this.__txn_insert(txn, pos, text);
19
+ }
20
+ };
21
+ LoroText.prototype.delete = function(txn, pos, len) {
22
+ if (txn instanceof Loro) {
23
+ this.__loro_delete(txn, pos, len);
24
+ } else {
25
+ this.__txn_delete(txn, pos, len);
26
+ }
27
+ };
28
+ LoroList.prototype.insert = function(txn, pos, len) {
29
+ if (txn instanceof Loro) {
30
+ this.__loro_insert(txn, pos, len);
31
+ } else {
32
+ this.__txn_insert(txn, pos, len);
33
+ }
34
+ };
35
+ LoroList.prototype.delete = function(txn, pos, len) {
36
+ if (txn instanceof Loro) {
37
+ this.__loro_delete(txn, pos, len);
38
+ } else {
39
+ this.__txn_delete(txn, pos, len);
40
+ }
41
+ };
42
+ LoroMap.prototype.set = function(txn, key, value) {
43
+ if (txn instanceof Loro) {
44
+ this.__loro_insert(txn, key, value);
45
+ } else {
46
+ this.__txn_insert(txn, key, value);
47
+ }
48
+ };
49
+ LoroMap.prototype.delete = function(txn, key) {
50
+ if (txn instanceof Loro) {
51
+ this.__loro_delete(txn, key);
52
+ } else {
53
+ this.__txn_delete(txn, key);
54
+ }
55
+ };
56
+ const CONTAINER_TYPES = ["Map", "Text", "List"];
57
+ function isContainerId(s) {
58
+ try {
59
+ if (s.startsWith("/")) {
60
+ const [_, type] = s.slice(1).split(":");
61
+ if (!CONTAINER_TYPES.includes(type)) {
62
+ return false;
63
+ }
64
+ } else {
65
+ const [id, type] = s.split(":");
66
+ if (!CONTAINER_TYPES.includes(type)) {
67
+ return false;
68
+ }
69
+ const [counter, client] = id.split("@");
70
+ Number.parseInt(counter);
71
+ Number.parseInt(client);
72
+ }
73
+ return true;
74
+ } catch (e) {
75
+ return false;
76
+ }
77
+ }
78
+
79
+ export { isContainerId };
80
+ //# sourceMappingURL=loro.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loro.mjs","sources":["../src/index.ts"],"sourcesContent":["export {\n LoroList,\n LoroMap,\n LoroText,\n PrelimList,\n PrelimMap,\n PrelimText,\n setPanicHook,\n Transaction,\n} from \"loro-wasm\";\nimport { PrelimMap } from \"loro-wasm\";\nimport { PrelimText } from \"loro-wasm\";\nimport { PrelimList } from \"loro-wasm\";\nimport {\n ContainerID,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n Transaction,\n} from \"loro-wasm\";\n\nexport type { ContainerID, ContainerType } from \"loro-wasm\";\n\nLoro.prototype.transact = function (cb, origin) {\n this.__raw__transactionWithOrigin(origin, (txn: Transaction) => {\n try {\n cb(txn);\n } finally {\n txn.commit();\n txn.free();\n }\n });\n};\n\nLoroText.prototype.insert = function (txn, pos, text) {\n if (txn instanceof Loro) {\n this.__loro_insert(txn, pos, text);\n } else {\n this.__txn_insert(txn, pos, text);\n }\n};\n\nLoroText.prototype.delete = function (txn, pos, len) {\n if (txn instanceof Loro) {\n this.__loro_delete(txn, pos, len);\n } else {\n this.__txn_delete(txn, pos, len);\n }\n};\n\nLoroList.prototype.insert = function (txn, pos, len) {\n if (txn instanceof Loro) {\n this.__loro_insert(txn, pos, len);\n } else {\n this.__txn_insert(txn, pos, len);\n }\n};\n\nLoroList.prototype.delete = function (txn, pos, len) {\n if (txn instanceof Loro) {\n this.__loro_delete(txn, pos, len);\n } else {\n this.__txn_delete(txn, pos, len);\n }\n};\n\nLoroMap.prototype.set = function (txn, key, value) {\n if (txn instanceof Loro) {\n this.__loro_insert(txn, key, value);\n } else {\n this.__txn_insert(txn, key, value);\n }\n};\n\nLoroMap.prototype.delete = function (txn, key) {\n if (txn instanceof Loro) {\n this.__loro_delete(txn, key);\n } else {\n this.__txn_delete(txn, key);\n }\n};\n\nexport type Value =\n | ContainerID\n | string\n | number\n | null\n | { [key: string]: Value }\n | Value[];\n\nexport type Prelim = PrelimList | PrelimMap | PrelimText;\n\nexport type Path = (number | string)[];\nexport type Delta<T> = {\n type: \"insert\";\n value: T;\n} | {\n type: \"delete\";\n len: number;\n} | {\n type: \"retain\";\n len: number;\n};\n\nexport type ListDiff = {\n type: \"list\";\n diff: Delta<Value[]>[];\n};\n\nexport type TextDiff = {\n type: \"text\";\n diff: Delta<string>[];\n};\n\nexport type MapDIff = {\n type: \"map\";\n diff: {\n added: Record<string, Value>;\n deleted: Record<string, Value>;\n updated: Record<string, {\n old: Value;\n new: Value;\n }>;\n };\n};\n\nexport type Diff = ListDiff | TextDiff | MapDIff;\n\nexport interface LoroEvent {\n local: boolean;\n origin?: string;\n diff: Diff[];\n target: ContainerID;\n path: Path;\n}\n\ninterface Listener {\n (event: LoroEvent): void;\n}\n\nconst CONTAINER_TYPES = [\"Map\", \"Text\", \"List\"];\n\nexport function isContainerId(s: string): s is ContainerID {\n try {\n if (s.startsWith(\"/\")) {\n const [_, type] = s.slice(1).split(\":\");\n if (!CONTAINER_TYPES.includes(type)) {\n return false;\n }\n } else {\n const [id, type] = s.split(\":\");\n if (!CONTAINER_TYPES.includes(type)) {\n return false;\n }\n\n const [counter, client] = id.split(\"@\");\n Number.parseInt(counter);\n Number.parseInt(client);\n }\n\n return true;\n } catch (e) {\n return false;\n }\n}\n\nexport { Loro };\n\ndeclare module \"loro-wasm\" {\n interface Loro {\n subscribe(listener: Listener): number;\n transact(f: (tx: Transaction) => void, origin?: string): void;\n }\n\n interface LoroList {\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: \"Map\",\n ): LoroMap;\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: \"List\",\n ): LoroList;\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: \"Text\",\n ): LoroText;\n insertContainer(\n txn: Transaction | Loro,\n pos: number,\n container: string,\n ): never;\n\n get(index: number): Value;\n insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void;\n delete(txn: Transaction | Loro, pos: number, len: number): void;\n subscribe(txn: Transaction | Loro, listener: Listener): number;\n subscribeDeep(txn: Transaction | Loro, listener: Listener): number;\n subscribeOnce(txn: Transaction | Loro, listener: Listener): number;\n }\n\n interface LoroMap {\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: \"Map\",\n ): LoroMap;\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: \"List\",\n ): LoroList;\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: \"Text\",\n ): LoroText;\n insertContainer(\n txn: Transaction | Loro,\n key: string,\n container_type: string,\n ): never;\n\n get(key: string): Value;\n set(txn: Transaction | Loro, key: string, value: Value | Prelim): void;\n delete(txn: Transaction | Loro, key: string): void;\n subscribe(txn: Transaction | Loro, listener: Listener): number;\n subscribeDeep(txn: Transaction | Loro, listener: Listener): number;\n subscribeOnce(txn: Transaction | Loro, listener: Listener): number;\n }\n\n interface LoroText {\n insert(txn: Transaction | Loro, pos: number, text: string): void;\n delete(txn: Transaction | Loro, pos: number, len: number): void;\n subscribe(txn: Transaction | Loro, listener: Listener): number;\n subscribeDeep(txn: Transaction | Loro, listener: Listener): number;\n subscribeOnce(txn: Transaction | Loro, listener: Listener): number;\n }\n}\n"],"names":["LoroText","LoroList","LoroMap"],"mappings":";;;AAwBA,IAAA,CAAK,SAAU,CAAA,QAAA,GAAW,SAAU,EAAA,EAAI,MAAQ,EAAA;AAC9C,EAAK,IAAA,CAAA,4BAAA,CAA6B,MAAQ,EAAA,CAAC,GAAqB,KAAA;AAC9D,IAAI,IAAA;AACF,MAAA,EAAA,CAAG,GAAG,CAAA,CAAA;AAAA,KACN,SAAA;AACA,MAAA,GAAA,CAAI,MAAO,EAAA,CAAA;AACX,MAAA,GAAA,CAAI,IAAK,EAAA,CAAA;AAAA,KACX;AAAA,GACD,CAAA,CAAA;AACH,CAA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G,EAAA;AACnC,QAAO,OAAA,KAAA,CAAA;AAAA,OACT;AAEA,MAAA,MAAM,CAAC,OAAS,EAAA,MAAM,CAAI,GAAA,EAAA,CAAG,MAAM,GAAG,CAAA,CAAA;AACtC,MAAA,MAAA,CAAO,SAAS,OAAO,CAAA,CAAA;AACvB,MAAA,MAAA,CAAO,SAAS,MAAM,CAAA,CAAA;AAAA,KACxB;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,WACA,CAAP,EAAA;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF;;;;"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "loro-crdt",
3
+ "version": "0.2.5",
4
+ "description": "",
5
+ "main": "dist/loro.js",
6
+ "module": "dist/loro.mjs",
7
+ "typings": "dist/loro.d.ts",
8
+ "scripts": {
9
+ "build": "rollup -c",
10
+ "watch": "rollup -c -w",
11
+ "test": "vitest run"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "loro-wasm": "workspace"
17
+ },
18
+ "devDependencies": {
19
+ "@rollup/plugin-node-resolve": "^15.0.1",
20
+ "esbuild": "^0.17.12",
21
+ "rollup": "^3.20.1",
22
+ "rollup-plugin-dts": "^5.3.0",
23
+ "rollup-plugin-esbuild": "^5.0.0",
24
+ "typescript": "^5.0.2",
25
+ "vite": "^4.2.1",
26
+ "vite-plugin-wasm": "^3.2.2",
27
+ "vitest": "^0.29.7"
28
+ }
29
+ }
@@ -0,0 +1,37 @@
1
+ import { defineConfig } from "rollup";
2
+ import dts from "rollup-plugin-dts";
3
+ import esbuild from "rollup-plugin-esbuild";
4
+ import packageJson from "./package.json" assert { type: "json" };
5
+
6
+ const name = packageJson.main.replace(/\.js$/, "");
7
+
8
+ const bundle = (config) => ({
9
+ ...config,
10
+ input: "src/index.ts",
11
+ external: (id) => !/^[./]/.test(id),
12
+ });
13
+
14
+ export default defineConfig([
15
+ bundle({
16
+ plugins: [esbuild()],
17
+ output: [
18
+ {
19
+ file: `${name}.js`,
20
+ format: "cjs",
21
+ sourcemap: true,
22
+ },
23
+ {
24
+ file: `${name}.mjs`,
25
+ format: "es",
26
+ sourcemap: true,
27
+ },
28
+ ],
29
+ }),
30
+ bundle({
31
+ plugins: [dts()],
32
+ output: {
33
+ file: `${name}.d.ts`,
34
+ format: "es",
35
+ },
36
+ }),
37
+ ]);
package/src/index.ts ADDED
@@ -0,0 +1,243 @@
1
+ export {
2
+ LoroList,
3
+ LoroMap,
4
+ LoroText,
5
+ PrelimList,
6
+ PrelimMap,
7
+ PrelimText,
8
+ setPanicHook,
9
+ Transaction,
10
+ } from "loro-wasm";
11
+ import { PrelimMap } from "loro-wasm";
12
+ import { PrelimText } from "loro-wasm";
13
+ import { PrelimList } from "loro-wasm";
14
+ import {
15
+ ContainerID,
16
+ Loro,
17
+ LoroList,
18
+ LoroMap,
19
+ LoroText,
20
+ Transaction,
21
+ } from "loro-wasm";
22
+
23
+ export type { ContainerID, ContainerType } from "loro-wasm";
24
+
25
+ Loro.prototype.transact = function (cb, origin) {
26
+ this.__raw__transactionWithOrigin(origin, (txn: Transaction) => {
27
+ try {
28
+ cb(txn);
29
+ } finally {
30
+ txn.commit();
31
+ txn.free();
32
+ }
33
+ });
34
+ };
35
+
36
+ LoroText.prototype.insert = function (txn, pos, text) {
37
+ if (txn instanceof Loro) {
38
+ this.__loro_insert(txn, pos, text);
39
+ } else {
40
+ this.__txn_insert(txn, pos, text);
41
+ }
42
+ };
43
+
44
+ LoroText.prototype.delete = function (txn, pos, len) {
45
+ if (txn instanceof Loro) {
46
+ this.__loro_delete(txn, pos, len);
47
+ } else {
48
+ this.__txn_delete(txn, pos, len);
49
+ }
50
+ };
51
+
52
+ LoroList.prototype.insert = function (txn, pos, len) {
53
+ if (txn instanceof Loro) {
54
+ this.__loro_insert(txn, pos, len);
55
+ } else {
56
+ this.__txn_insert(txn, pos, len);
57
+ }
58
+ };
59
+
60
+ LoroList.prototype.delete = function (txn, pos, len) {
61
+ if (txn instanceof Loro) {
62
+ this.__loro_delete(txn, pos, len);
63
+ } else {
64
+ this.__txn_delete(txn, pos, len);
65
+ }
66
+ };
67
+
68
+ LoroMap.prototype.set = function (txn, key, value) {
69
+ if (txn instanceof Loro) {
70
+ this.__loro_insert(txn, key, value);
71
+ } else {
72
+ this.__txn_insert(txn, key, value);
73
+ }
74
+ };
75
+
76
+ LoroMap.prototype.delete = function (txn, key) {
77
+ if (txn instanceof Loro) {
78
+ this.__loro_delete(txn, key);
79
+ } else {
80
+ this.__txn_delete(txn, key);
81
+ }
82
+ };
83
+
84
+ export type Value =
85
+ | ContainerID
86
+ | string
87
+ | number
88
+ | null
89
+ | { [key: string]: Value }
90
+ | Value[];
91
+
92
+ export type Prelim = PrelimList | PrelimMap | PrelimText;
93
+
94
+ export type Path = (number | string)[];
95
+ export type Delta<T> = {
96
+ type: "insert";
97
+ value: T;
98
+ } | {
99
+ type: "delete";
100
+ len: number;
101
+ } | {
102
+ type: "retain";
103
+ len: number;
104
+ };
105
+
106
+ export type ListDiff = {
107
+ type: "list";
108
+ diff: Delta<Value[]>[];
109
+ };
110
+
111
+ export type TextDiff = {
112
+ type: "text";
113
+ diff: Delta<string>[];
114
+ };
115
+
116
+ export type MapDiff = {
117
+ type: "map";
118
+ diff: {
119
+ added: Record<string, Value>;
120
+ deleted: Record<string, Value>;
121
+ updated: Record<string, {
122
+ old: Value;
123
+ new: Value;
124
+ }>;
125
+ };
126
+ };
127
+
128
+ export type Diff = ListDiff | TextDiff | MapDiff;
129
+
130
+ export interface LoroEvent {
131
+ local: boolean;
132
+ origin?: string;
133
+ diff: Diff;
134
+ target: ContainerID;
135
+ path: Path;
136
+ }
137
+
138
+ interface Listener {
139
+ (event: LoroEvent): void;
140
+ }
141
+
142
+ const CONTAINER_TYPES = ["Map", "Text", "List"];
143
+
144
+ export function isContainerId(s: string): s is ContainerID {
145
+ try {
146
+ if (s.startsWith("/")) {
147
+ const [_, type] = s.slice(1).split(":");
148
+ if (!CONTAINER_TYPES.includes(type)) {
149
+ return false;
150
+ }
151
+ } else {
152
+ const [id, type] = s.split(":");
153
+ if (!CONTAINER_TYPES.includes(type)) {
154
+ return false;
155
+ }
156
+
157
+ const [counter, client] = id.split("@");
158
+ Number.parseInt(counter);
159
+ Number.parseInt(client);
160
+ }
161
+
162
+ return true;
163
+ } catch (e) {
164
+ return false;
165
+ }
166
+ }
167
+
168
+ export { Loro };
169
+
170
+ declare module "loro-wasm" {
171
+ interface Loro {
172
+ subscribe(listener: Listener): number;
173
+ transact(f: (tx: Transaction) => void, origin?: string): void;
174
+ }
175
+
176
+ interface LoroList {
177
+ insertContainer(
178
+ txn: Transaction | Loro,
179
+ pos: number,
180
+ container: "Map",
181
+ ): LoroMap;
182
+ insertContainer(
183
+ txn: Transaction | Loro,
184
+ pos: number,
185
+ container: "List",
186
+ ): LoroList;
187
+ insertContainer(
188
+ txn: Transaction | Loro,
189
+ pos: number,
190
+ container: "Text",
191
+ ): LoroText;
192
+ insertContainer(
193
+ txn: Transaction | Loro,
194
+ pos: number,
195
+ container: string,
196
+ ): never;
197
+
198
+ get(index: number): Value;
199
+ insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void;
200
+ delete(txn: Transaction | Loro, pos: number, len: number): void;
201
+ subscribe(txn: Transaction | Loro, listener: Listener): number;
202
+ subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
203
+ subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
204
+ }
205
+
206
+ interface LoroMap {
207
+ insertContainer(
208
+ txn: Transaction | Loro,
209
+ key: string,
210
+ container_type: "Map",
211
+ ): LoroMap;
212
+ insertContainer(
213
+ txn: Transaction | Loro,
214
+ key: string,
215
+ container_type: "List",
216
+ ): LoroList;
217
+ insertContainer(
218
+ txn: Transaction | Loro,
219
+ key: string,
220
+ container_type: "Text",
221
+ ): LoroText;
222
+ insertContainer(
223
+ txn: Transaction | Loro,
224
+ key: string,
225
+ container_type: string,
226
+ ): never;
227
+
228
+ get(key: string): Value;
229
+ set(txn: Transaction | Loro, key: string, value: Value | Prelim): void;
230
+ delete(txn: Transaction | Loro, key: string): void;
231
+ subscribe(txn: Transaction | Loro, listener: Listener): number;
232
+ subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
233
+ subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
234
+ }
235
+
236
+ interface LoroText {
237
+ insert(txn: Transaction | Loro, pos: number, text: string): void;
238
+ delete(txn: Transaction | Loro, pos: number, len: number): void;
239
+ subscribe(txn: Transaction | Loro, listener: Listener): number;
240
+ subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
241
+ subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
242
+ }
243
+ }
@@ -0,0 +1,261 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ Delta,
4
+ ListDiff,
5
+ Loro,
6
+ LoroEvent,
7
+ MapDiff as MapDiff,
8
+ TextDiff,
9
+ } from "../src";
10
+
11
+ describe("event", () => {
12
+ it("target", async () => {
13
+ const loro = new Loro();
14
+ let lastEvent: undefined | LoroEvent;
15
+ loro.subscribe((event) => {
16
+ lastEvent = event;
17
+ });
18
+ const text = loro.getText("text");
19
+ const id = text.id;
20
+ text.insert(loro, 0, "123");
21
+ await zeroMs();
22
+ expect(lastEvent?.target).toEqual(id);
23
+ });
24
+
25
+ it("path", async () => {
26
+ const loro = new Loro();
27
+ let lastEvent: undefined | LoroEvent;
28
+ loro.subscribe((event) => {
29
+ lastEvent = event;
30
+ });
31
+ const map = loro.getMap("map");
32
+ const subMap = map.insertContainer(loro, "sub", "Map");
33
+ subMap.set(loro, "0", "1");
34
+ await zeroMs();
35
+ expect(lastEvent?.path).toStrictEqual(["map", "sub"]);
36
+ const list = subMap.insertContainer(loro, "list", "List");
37
+ list.insert(loro, 0, "2");
38
+ const text = list.insertContainer(loro, 1, "Text");
39
+ await zeroMs();
40
+ text.insert(loro, 0, "3");
41
+ await zeroMs();
42
+ expect(lastEvent?.path).toStrictEqual(["map", "sub", "list", 1]);
43
+ });
44
+
45
+ it("text diff", async () => {
46
+ const loro = new Loro();
47
+ let lastEvent: undefined | LoroEvent;
48
+ loro.subscribe((event) => {
49
+ lastEvent = event;
50
+ });
51
+ const text = loro.getText("t");
52
+ text.insert(loro, 0, "3");
53
+ await zeroMs();
54
+ expect(lastEvent?.diff).toStrictEqual(
55
+ { type: "text", diff: [{ type: "insert", value: "3" }] } as TextDiff,
56
+ );
57
+ text.insert(loro, 1, "12");
58
+ await zeroMs();
59
+ expect(lastEvent?.diff).toStrictEqual(
60
+ {
61
+ type: "text",
62
+ diff: [{ type: "retain", len: 1 }, { type: "insert", value: "12" }],
63
+ } as TextDiff,
64
+ );
65
+ });
66
+
67
+ it("list diff", async () => {
68
+ const loro = new Loro();
69
+ let lastEvent: undefined | LoroEvent;
70
+ loro.subscribe((event) => {
71
+ lastEvent = event;
72
+ });
73
+ const text = loro.getList("l");
74
+ text.insert(loro, 0, "3");
75
+ await zeroMs();
76
+ expect(lastEvent?.diff).toStrictEqual(
77
+ { type: "list", diff: [{ type: "insert", value: ["3"] }] } as ListDiff,
78
+ );
79
+ text.insert(loro, 1, "12");
80
+ await zeroMs();
81
+ expect(lastEvent?.diff).toStrictEqual(
82
+ {
83
+ type: "list",
84
+ diff: [{ type: "retain", len: 1 }, { type: "insert", value: ["12"] }],
85
+ } as ListDiff,
86
+ );
87
+ });
88
+
89
+ it("map diff", async () => {
90
+ const loro = new Loro();
91
+ let lastEvent: undefined | LoroEvent;
92
+ loro.subscribe((event) => {
93
+ lastEvent = event;
94
+ });
95
+ const map = loro.getMap("m");
96
+ loro.transact((tx) => {
97
+ map.set(tx, "0", "3");
98
+ map.set(tx, "1", "2");
99
+ });
100
+ await zeroMs();
101
+ expect(lastEvent?.diff).toStrictEqual(
102
+ {
103
+ type: "map",
104
+ diff: {
105
+ added: {
106
+ "0": "3",
107
+ "1": "2",
108
+ },
109
+ deleted: {},
110
+ updated: {},
111
+ },
112
+ } as MapDiff,
113
+ );
114
+ loro.transact((tx) => {
115
+ map.set(tx, "0", "0");
116
+ map.set(tx, "1", "1");
117
+ });
118
+ await zeroMs();
119
+ expect(lastEvent?.diff).toStrictEqual(
120
+ {
121
+ type: "map",
122
+ diff: {
123
+ added: {},
124
+ updated: {
125
+ "0": { old: "3", new: "0" },
126
+ "1": { old: "2", new: "1" },
127
+ },
128
+ deleted: {},
129
+ },
130
+ } as MapDiff,
131
+ );
132
+ });
133
+
134
+ describe("subscribe container events", () => {
135
+ it("text", async () => {
136
+ const loro = new Loro();
137
+ const text = loro.getText("text");
138
+ let ran = 0;
139
+ let oneTimeRan = 0;
140
+ text.subscribeOnce(loro, (_) => {
141
+ oneTimeRan += 1;
142
+ });
143
+ const sub = text.subscribe(loro, (event) => {
144
+ if (!ran) {
145
+ expect(event.diff.diff).toStrictEqual(
146
+ [{ type: "insert", "value": "123" }] as Delta<string>[],
147
+ );
148
+ }
149
+ ran += 1;
150
+ expect(event.target).toBe(text.id);
151
+ });
152
+ text.insert(loro, 0, "123");
153
+ text.insert(loro, 1, "456");
154
+ await zeroMs();
155
+ expect(ran).toBeTruthy();
156
+ // subscribeOnce test
157
+ expect(oneTimeRan).toBe(1);
158
+ expect(text.toString()).toEqual("145623");
159
+
160
+ // unsubscribe
161
+ const oldRan = ran;
162
+ text.unsubscribe(loro, sub);
163
+ text.insert(loro, 0, "789");
164
+ expect(ran).toBe(oldRan);
165
+ });
166
+
167
+ it("map subscribe deep", async () => {
168
+ const loro = new Loro();
169
+ const map = loro.getMap("map");
170
+ let times = 0;
171
+ const sub = map.subscribeDeep(loro, (event) => {
172
+ times += 1;
173
+ });
174
+
175
+ const subMap = map.insertContainer(loro, "sub", "Map");
176
+ await zeroMs();
177
+ expect(times).toBe(1);
178
+ const text = subMap.insertContainer(loro, "k", "Text");
179
+ await zeroMs();
180
+ expect(times).toBe(2);
181
+ text.insert(loro, 0, "123");
182
+ await zeroMs();
183
+ expect(times).toBe(3);
184
+
185
+ // unsubscribe
186
+ map.unsubscribe(loro, sub);
187
+ text.insert(loro, 0, "123");
188
+ await zeroMs();
189
+ expect(times).toBe(3);
190
+ });
191
+
192
+ it("list subscribe deep", async () => {
193
+ const loro = new Loro();
194
+ const list = loro.getList("list");
195
+ let times = 0;
196
+ const sub = list.subscribeDeep(loro, (_) => {
197
+ times += 1;
198
+ });
199
+
200
+ const text = list.insertContainer(loro, 0, "Text");
201
+ await zeroMs();
202
+ expect(times).toBe(1);
203
+ text.insert(loro, 0, "123");
204
+ await zeroMs();
205
+ expect(times).toBe(2);
206
+
207
+ // unsubscribe
208
+ list.unsubscribe(loro, sub);
209
+ text.insert(loro, 0, "123");
210
+ await zeroMs();
211
+ expect(times).toBe(2);
212
+ });
213
+ });
214
+
215
+ describe("text event length should be utf16", () => {
216
+ it("test", async () => {
217
+ const loro = new Loro();
218
+ const text = loro.getText("text");
219
+ let string = "";
220
+ text.subscribe(loro, (event) => {
221
+ const diff = event.diff;
222
+ expect(diff.type).toBe("text");
223
+ if (diff.type === "text") {
224
+ let newString = "";
225
+ let pos = 0;
226
+ for (const delta of diff.diff) {
227
+ if (delta.type === "retain") {
228
+ pos += delta.len;
229
+ newString += string.slice(0, pos);
230
+ } else if (delta.type === "insert") {
231
+ newString += delta.value;
232
+ } else {
233
+ pos += delta.len;
234
+ }
235
+ }
236
+
237
+ string = newString + string.slice(pos);
238
+ }
239
+ });
240
+ text.insert(loro, 0, "你好");
241
+ await zeroMs();
242
+ expect(text.toString()).toBe(string);
243
+
244
+ text.insert(loro, 1, "世界");
245
+ await zeroMs();
246
+ expect(text.toString()).toBe(string);
247
+
248
+ text.insert(loro, 2, "👍");
249
+ await zeroMs();
250
+ expect(text.toString()).toBe(string);
251
+
252
+ text.insert(loro, 4, "♪(^∇^*)");
253
+ await zeroMs();
254
+ expect(text.toString()).toBe(string);
255
+ });
256
+ });
257
+ });
258
+
259
+ function zeroMs(): Promise<void> {
260
+ return new Promise((r) => setTimeout(r));
261
+ }
@@ -0,0 +1,30 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ Delta,
4
+ ListDiff,
5
+ Loro,
6
+ LoroEvent,
7
+ MapDiff as MapDiff,
8
+ TextDiff,
9
+ } from "../src";
10
+
11
+ describe("Frontiers", () => {
12
+ it("two clients", () => {
13
+ const doc = new Loro();
14
+ const text = doc.getText("text");
15
+ text.insert(doc, 0, "0");
16
+ const v0 = doc.frontiers();
17
+ const docB = new Loro();
18
+ docB.import(doc.exportFrom());
19
+ expect(docB.cmpFrontiers(v0)).toBe(0);
20
+ text.insert(doc, 1, "0");
21
+ expect(docB.cmpFrontiers(doc.frontiers())).toBe(-1);
22
+ const textB = docB.getText("text");
23
+ textB.insert(docB, 0, "0");
24
+ expect(docB.cmpFrontiers(doc.frontiers())).toBe(-1);
25
+ docB.import(doc.exportFrom());
26
+ expect(docB.cmpFrontiers(doc.frontiers())).toBe(1);
27
+ doc.import(docB.exportFrom());
28
+ expect(docB.cmpFrontiers(doc.frontiers())).toBe(0);
29
+ });
30
+ });
@@ -0,0 +1,262 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ Delta,
4
+ ListDiff,
5
+ Loro,
6
+ LoroEvent,
7
+ LoroMap,
8
+ MapDiff as MapDiff,
9
+ PrelimList,
10
+ PrelimMap,
11
+ PrelimText,
12
+ TextDiff,
13
+ Transaction,
14
+ } from "../src";
15
+
16
+ function assertEquals(a: any, b: any) {
17
+ expect(a).toStrictEqual(b);
18
+ }
19
+
20
+ describe("transaction", () => {
21
+ it("transaction", async () => {
22
+ const loro = new Loro();
23
+ const text = loro.getText("text");
24
+ let count = 0;
25
+ const sub = loro.subscribe(() => {
26
+ count += 1;
27
+ loro.unsubscribe(sub);
28
+ });
29
+ loro.transact((txn: Transaction) => {
30
+ expect(count).toBe(0);
31
+ text.insert(txn, 0, "hello world");
32
+ expect(count).toBe(0);
33
+ text.insert(txn, 0, "hello world");
34
+ assertEquals(count, 0);
35
+ });
36
+ await one_ms();
37
+ assertEquals(count, 1);
38
+ });
39
+
40
+ it("transaction origin", async () => {
41
+ const loro = new Loro();
42
+ const text = loro.getText("text");
43
+ let count = 0;
44
+ const sub = loro.subscribe((event: { origin: string }) => {
45
+ count += 1;
46
+ loro.unsubscribe(sub);
47
+ assertEquals(event.origin, "origin");
48
+ });
49
+ loro.transact((txn: Transaction) => {
50
+ assertEquals(count, 0);
51
+ text.insert(txn, 0, "hello world");
52
+ assertEquals(count, 0);
53
+ text.insert(txn, 0, "hello world");
54
+ assertEquals(count, 0);
55
+ }, "origin");
56
+ await one_ms();
57
+ assertEquals(count, 1);
58
+ });
59
+ });
60
+
61
+ describe("subscribe", () => {
62
+ it("subscribe_lock", async () => {
63
+ const loro = new Loro();
64
+ const text = loro.getText("text");
65
+ const list = loro.getList("list");
66
+ let count = 0;
67
+ let i = 1;
68
+ const sub = loro.subscribe(() => {
69
+ if (i > 0) {
70
+ list.insert(loro, 0, i);
71
+ i--;
72
+ }
73
+ count += 1;
74
+ });
75
+ text.insert(loro, 0, "hello world");
76
+ await one_ms();
77
+ assertEquals(count, 2);
78
+ text.insert(loro, 0, "hello world");
79
+ await one_ms();
80
+ assertEquals(count, 3);
81
+ loro.unsubscribe(sub);
82
+ text.insert(loro, 0, "hello world");
83
+ await one_ms();
84
+ assertEquals(count, 3);
85
+ });
86
+
87
+ it("subscribe_lock2", async () => {
88
+ const loro = new Loro();
89
+ const text = loro.getText("text");
90
+ let count = 0;
91
+ const sub = loro.subscribe(() => {
92
+ count += 1;
93
+ loro.unsubscribe(sub);
94
+ });
95
+ assertEquals(count, 0);
96
+ text.insert(loro, 0, "hello world");
97
+ await one_ms();
98
+ assertEquals(count, 1);
99
+ text.insert(loro, 0, "hello world");
100
+ assertEquals(count, 1);
101
+ });
102
+
103
+ it("subscribe", async () => {
104
+ const loro = new Loro();
105
+ const text = loro.getText("text");
106
+ let count = 0;
107
+ const sub = loro.subscribe(() => {
108
+ count += 1;
109
+ });
110
+ text.insert(loro, 0, "hello world");
111
+ await one_ms();
112
+ assertEquals(count, 1);
113
+ text.insert(loro, 0, "hello world");
114
+ await one_ms();
115
+ assertEquals(count, 2);
116
+ loro.unsubscribe(sub);
117
+ text.insert(loro, 0, "hello world");
118
+ await one_ms();
119
+ assertEquals(count, 2);
120
+ });
121
+ });
122
+
123
+ describe("sync", () => {
124
+ it("two insert at beginning", async () => {
125
+ const a = new Loro();
126
+ const b = new Loro();
127
+ let a_version: undefined | Uint8Array = undefined;
128
+ let b_version: undefined | Uint8Array = undefined;
129
+ a.subscribe((e: { local: boolean }) => {
130
+ if (e.local) {
131
+ const exported = a.exportFrom(a_version);
132
+ b.import(exported);
133
+ a_version = a.version();
134
+ }
135
+ });
136
+ b.subscribe((e: { local: boolean }) => {
137
+ if (e.local) {
138
+ const exported = b.exportFrom(b_version);
139
+ a.import(exported);
140
+ b_version = b.version();
141
+ }
142
+ });
143
+ const aText = a.getText("text");
144
+ const bText = b.getText("text");
145
+ aText.insert(a, 0, "abc");
146
+ await one_ms();
147
+ assertEquals(aText.toString(), bText.toString());
148
+ });
149
+
150
+ it("sync", () => {
151
+ const loro = new Loro();
152
+ const text = loro.getText("text");
153
+ text.insert(loro, 0, "hello world");
154
+ const loro_bk = new Loro();
155
+ loro_bk.import(loro.exportFrom(undefined));
156
+ assertEquals(loro_bk.toJson(), loro.toJson());
157
+ const text_bk = loro_bk.getText("text");
158
+ assertEquals(text_bk.toString(), "hello world");
159
+ text_bk.insert(loro_bk, 0, "a ");
160
+ loro.import(loro_bk.exportFrom(undefined));
161
+ assertEquals(text.toString(), "a hello world");
162
+ const map = loro.getMap("map");
163
+ map.set(loro, "key", "value");
164
+ });
165
+ });
166
+
167
+ describe("prelim", () => {
168
+ it("test prelim", async (t) => {
169
+ const loro = new Loro();
170
+ const map = loro.getMap("map");
171
+ const list = loro.getList("list");
172
+ const prelim_text = new PrelimText(undefined);
173
+ const prelim_map = new PrelimMap({ a: 1, b: 2 });
174
+ const prelim_list = new PrelimList([1, "2", { a: 4 }]);
175
+
176
+ it("prelim text", () => {
177
+ prelim_text.insert(0, "hello world");
178
+ assertEquals(prelim_text.value, "hello world");
179
+ prelim_text.delete(6, 5);
180
+ prelim_text.insert(6, "everyone");
181
+ assertEquals(prelim_text.value, "hello everyone");
182
+ });
183
+
184
+ it("prelim map", () => {
185
+ prelim_map.set("ab", 123);
186
+ assertEquals(prelim_map.value, { a: 1, b: 2, ab: 123 });
187
+ prelim_map.delete("b");
188
+ assertEquals(prelim_map.value, { a: 1, ab: 123 });
189
+ });
190
+
191
+ it("prelim list", () => {
192
+ prelim_list.insert(0, 0);
193
+ assertEquals(prelim_list.value, [0, 1, "2", { a: 4 }]);
194
+ prelim_list.delete(1, 2);
195
+ assertEquals(prelim_list.value, [0, { a: 4 }]);
196
+ });
197
+
198
+ it("prelim map integrate", () => {
199
+ map.set(loro, "text", prelim_text);
200
+ map.set(loro, "map", prelim_map);
201
+ map.set(loro, "list", prelim_list);
202
+ assertEquals(map.getValueDeep(loro), {
203
+ text: "hello everyone",
204
+ map: { a: 1, ab: 123 },
205
+ list: [0, { a: 4 }],
206
+ });
207
+ });
208
+
209
+ it("prelim list integrate", () => {
210
+ const prelim_text = new PrelimText("ttt");
211
+ const prelim_map = new PrelimMap({ a: 1, b: 2 });
212
+ const prelim_list = new PrelimList([1, "2", { a: 4 }]);
213
+ list.insert(loro, 0, prelim_text);
214
+ list.insert(loro, 1, prelim_map);
215
+ list.insert(loro, 2, prelim_list);
216
+ assertEquals(list.getValueDeep(loro), ["ttt", { a: 1, b: 2 }, [1, "2", {
217
+ a: 4,
218
+ }]]);
219
+ });
220
+ });
221
+ });
222
+
223
+ describe("wasm", () => {
224
+ const loro = new Loro();
225
+ const a = loro.getText("ha");
226
+ a.insert(loro, 0, "hello world");
227
+ a.delete(loro, 6, 5);
228
+ a.insert(loro, 6, "everyone");
229
+ const b = loro.getMap("ha");
230
+ b.set(loro, "ab", 123);
231
+
232
+ const bText = b.insertContainer(loro, "hh", "Text");
233
+
234
+ it("map get", () => {
235
+ assertEquals(b.get("ab"), 123);
236
+ });
237
+
238
+ it("getValueDeep", () => {
239
+ bText.insert(loro, 0, "hello world Text");
240
+ assertEquals(b.getValueDeep(loro), { ab: 123, hh: "hello world Text" });
241
+ });
242
+
243
+ it("should throw error when using the wrong context", () => {
244
+ expect(() => {
245
+ const loro2 = new Loro();
246
+ bText.insert(loro2, 0, "hello world Text");
247
+ }).toThrow();
248
+ });
249
+
250
+ it("get container by id", () => {
251
+ const id = b.id;
252
+ const b2 = loro.getContainerById(id) as LoroMap;
253
+ assertEquals(b2.value, b.value);
254
+ assertEquals(b2.id, id);
255
+ b2.set(loro, "0", 12);
256
+ assertEquals(b2.value, b.value);
257
+ });
258
+ });
259
+
260
+ function one_ms(): Promise<void> {
261
+ return new Promise((resolve) => setTimeout(resolve, 1));
262
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs" /* Specify what module code is generated. */,
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
+ // "resolveJsonModule": true, /* Enable importing .json files. */
43
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
+
46
+ /* JavaScript Support */
47
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
+
51
+ /* Emit */
52
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
+ // "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. */
58
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
59
+ // "removeComments": true, /* Disable emitting comments. */
60
+ // "noEmit": true, /* Disable emitting files from a compilation. */
61
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
63
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
69
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "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. */
79
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
81
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
83
+
84
+ /* Type Checking */
85
+ "strict": true /* Enable all strict type-checking options. */,
86
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
92
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
93
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
94
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
95
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
96
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
97
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
98
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
99
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104
+
105
+ /* Completeness */
106
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
+ }
109
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,8 @@
1
+ /// <reference types="vitest" />
2
+ import wasm from "vite-plugin-wasm";
3
+ import { defineConfig } from "vite";
4
+
5
+ export default defineConfig({
6
+ plugins: [wasm()],
7
+ test: {},
8
+ });