loro-crdt 0.4.3 → 0.6.0
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/CHANGELOG.md +489 -468
- package/dist/loro.d.ts +16 -11
- package/dist/loro.js +16 -0
- package/dist/loro.js.map +1 -1
- package/dist/loro.mjs +15 -1
- package/dist/loro.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +34 -28
- package/vite.config.ts +3 -1
package/dist/loro.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Value, Container, TreeID, PrelimList, PrelimMap, PrelimText, OpId, ContainerID, Delta, ContainerType } from 'loro-wasm';
|
|
2
2
|
export * from 'loro-wasm';
|
|
3
3
|
export { Loro } from 'loro-wasm';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Data types supported by loro
|
|
7
|
-
*/
|
|
8
|
-
type Value = ContainerID | string | number | boolean | null | {
|
|
9
|
-
[key: string]: Value;
|
|
10
|
-
} | Uint8Array | Value[];
|
|
11
|
-
type Container = LoroList | LoroMap | LoroText | LoroTree;
|
|
12
5
|
type Prelim = PrelimList | PrelimMap | PrelimText;
|
|
6
|
+
type Frontiers = OpId[];
|
|
13
7
|
/**
|
|
14
8
|
* Represents a path to identify the exact location of an event's target.
|
|
15
9
|
* The path is composed of numbers (e.g., indices of a list container) and strings
|
|
@@ -46,7 +40,7 @@ interface LoroEvent {
|
|
|
46
40
|
}
|
|
47
41
|
type ListDiff = {
|
|
48
42
|
type: "list";
|
|
49
|
-
diff: Delta<Value[]>[];
|
|
43
|
+
diff: Delta<(Value | Container)[]>[];
|
|
50
44
|
};
|
|
51
45
|
type TextDiff = {
|
|
52
46
|
type: "text";
|
|
@@ -54,7 +48,7 @@ type TextDiff = {
|
|
|
54
48
|
};
|
|
55
49
|
type MapDiff = {
|
|
56
50
|
type: "map";
|
|
57
|
-
updated: Record<string, Value | undefined>;
|
|
51
|
+
updated: Record<string, Value | Container | undefined>;
|
|
58
52
|
};
|
|
59
53
|
type TreeDiff = {
|
|
60
54
|
type: "tree";
|
|
@@ -73,6 +67,8 @@ interface Listener {
|
|
|
73
67
|
}
|
|
74
68
|
declare function isContainerId(s: string): s is ContainerID;
|
|
75
69
|
|
|
70
|
+
declare function isContainer(value: any): value is Container;
|
|
71
|
+
declare function valueType(value: any): "Json" | ContainerType;
|
|
76
72
|
declare module "loro-wasm" {
|
|
77
73
|
interface Loro {
|
|
78
74
|
subscribe(listener: Listener): number;
|
|
@@ -112,6 +108,15 @@ declare module "loro-wasm" {
|
|
|
112
108
|
delete(pos: number, len: number): void;
|
|
113
109
|
subscribe(txn: Loro, listener: Listener): number;
|
|
114
110
|
}
|
|
111
|
+
interface LoroTree {
|
|
112
|
+
create(parent: TreeID | undefined): TreeID;
|
|
113
|
+
mov(target: TreeID, parent: TreeID | undefined): void;
|
|
114
|
+
delete(target: TreeID): void;
|
|
115
|
+
getMeta(target: TreeID): LoroMap;
|
|
116
|
+
parent(target: TreeID): TreeID | undefined;
|
|
117
|
+
contains(target: TreeID): boolean;
|
|
118
|
+
subscribe(txn: Loro, listener: Listener): number;
|
|
119
|
+
}
|
|
115
120
|
}
|
|
116
121
|
|
|
117
|
-
export {
|
|
122
|
+
export { Diff, Frontiers, ListDiff, LoroEvent, MapDiff, Path, Prelim, TextDiff, TreeDiff, isContainer, isContainerId, valueType };
|
package/dist/loro.js
CHANGED
|
@@ -30,15 +30,31 @@ loroWasm.LoroMap.prototype.getTyped = function(loro, key) {
|
|
|
30
30
|
loroWasm.LoroMap.prototype.setTyped = function(...args) {
|
|
31
31
|
return this.set(...args);
|
|
32
32
|
};
|
|
33
|
+
const CONTAINER_TYPES = ["Map", "Text", "List", "Tree"];
|
|
33
34
|
function isContainerId(s) {
|
|
34
35
|
return s.startsWith("cid:");
|
|
35
36
|
}
|
|
37
|
+
function isContainer(value) {
|
|
38
|
+
if (typeof value !== "object" || value == null) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const p = value.__proto__;
|
|
42
|
+
return p.hasOwnProperty("kind") && CONTAINER_TYPES.includes(value.kind());
|
|
43
|
+
}
|
|
44
|
+
function valueType(value) {
|
|
45
|
+
if (isContainer(value)) {
|
|
46
|
+
return value.kind();
|
|
47
|
+
}
|
|
48
|
+
return "Json";
|
|
49
|
+
}
|
|
36
50
|
|
|
37
51
|
Object.defineProperty(exports, 'Loro', {
|
|
38
52
|
enumerable: true,
|
|
39
53
|
get: function () { return loroWasm.Loro; }
|
|
40
54
|
});
|
|
55
|
+
exports.isContainer = isContainer;
|
|
41
56
|
exports.isContainerId = isContainerId;
|
|
57
|
+
exports.valueType = valueType;
|
|
42
58
|
Object.keys(loroWasm).forEach(function (k) {
|
|
43
59
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
44
60
|
enumerable: true,
|
package/dist/loro.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loro.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport { Delta } from \"loro-wasm\";\nimport { PrelimText, PrelimList, PrelimMap } from \"loro-wasm\";\nimport {
|
|
1
|
+
{"version":3,"file":"loro.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport { Container, ContainerType, Delta, OpId, Value } from \"loro-wasm\";\nimport { PrelimText, PrelimList, PrelimMap } from \"loro-wasm\";\nimport { ContainerID, Loro, LoroList, LoroMap, TreeID } from \"loro-wasm\";\n\nLoro.prototype.getTypedMap = function (...args) {\n return this.getMap(...args);\n};\nLoro.prototype.getTypedList = function (...args) {\n return this.getList(...args);\n};\nLoroList.prototype.getTyped = function (loro, index) {\n const value = this.get(index);\n if (typeof value === \"string\" && isContainerId(value)) {\n return loro.getContainerById(value);\n } else {\n return value;\n }\n};\nLoroList.prototype.insertTyped = function (...args) {\n return this.insert(...args);\n};\nLoroMap.prototype.getTyped = function (loro, key) {\n const value = this.get(key);\n if (typeof value === \"string\" && isContainerId(value)) {\n return loro.getContainerById(value);\n } else {\n return value;\n }\n};\nLoroMap.prototype.setTyped = function (...args) {\n return this.set(...args);\n};\n\nexport type Prelim = PrelimList | PrelimMap | PrelimText;\nexport type Frontiers = OpId[];\n\n/**\n * Represents a path to identify the exact location of an event's target.\n * The path is composed of numbers (e.g., indices of a list container) and strings\n * (e.g., keys of a map container), indicating the absolute position of the event's source\n * within a loro document.\n */\nexport type Path = (number | string)[];\n\n/**\n * The event of Loro.\n * @prop local - Indicates whether the event is local.\n * @prop origin - (Optional) Provides information about the origin of the event.\n * @prop diff - Contains the differential information related to the event.\n * @prop target - Identifies the container ID of the event's target.\n * @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.\n */\nexport interface LoroEvent {\n /**\n * The unique ID of the event.\n */\n id: bigint;\n local: boolean;\n origin?: string;\n /**\n * If true, this event was triggered by a child container.\n */\n fromChildren: boolean;\n /**\n * If true, this event was triggered by a checkout.\n */\n fromCheckout: boolean;\n diff: Diff;\n target: ContainerID;\n path: Path;\n}\n\nexport type ListDiff = {\n type: \"list\";\n diff: Delta<(Value | Container)[]>[];\n};\n\nexport type TextDiff = {\n type: \"text\";\n diff: Delta<string>[];\n};\n\nexport type MapDiff = {\n type: \"map\";\n updated: Record<string, Value | Container | undefined>;\n};\n\nexport type TreeDiff = {\n type: \"tree\";\n diff:\n | { target: TreeID; action: \"create\" | \"delete\" }\n | { target: TreeID; action: \"move\"; parent: TreeID };\n};\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;\n\ninterface Listener {\n (event: LoroEvent): void;\n}\n\nconst CONTAINER_TYPES = [\"Map\", \"Text\", \"List\", \"Tree\"];\n\nexport function isContainerId(s: string): s is ContainerID {\n return s.startsWith(\"cid:\");\n}\n\nexport { Loro };\n\nexport function isContainer(value: any): value is Container {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n const p = value.__proto__;\n return p.hasOwnProperty(\"kind\") && CONTAINER_TYPES.includes(value.kind());\n}\n\nexport function valueType(value: any): \"Json\" | ContainerType {\n if (isContainer(value)) {\n return value.kind();\n }\n\n return \"Json\";\n}\n\ndeclare module \"loro-wasm\" {\n interface Loro {\n subscribe(listener: Listener): number;\n }\n\n interface Loro<T extends Record<string, any> = Record<string, any>> {\n getTypedMap<Key extends keyof T & string>(\n name: Key\n ): T[Key] extends LoroMap ? T[Key] : never;\n getTypedList<Key extends keyof T & string>(\n name: Key\n ): T[Key] extends LoroList ? T[Key] : never;\n }\n\n interface LoroList<T extends any[] = any[]> {\n insertContainer(pos: number, container: \"Map\"): LoroMap;\n insertContainer(pos: number, container: \"List\"): LoroList;\n insertContainer(pos: number, container: \"Text\"): LoroText;\n insertContainer(pos: number, container: \"Tree\"): LoroTree;\n insertContainer(pos: number, container: string): never;\n\n get(index: number): undefined | Value | Container;\n getTyped<Key extends keyof T & number>(loro: Loro, index: Key): T[Key];\n insertTyped<Key extends keyof T & number>(pos: Key, value: T[Key]): void;\n insert(pos: number, value: Value | Prelim): void;\n delete(pos: number, len: number): void;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroMap<T extends Record<string, any> = Record<string, any>> {\n setContainer(key: string, container_type: \"Map\"): LoroMap;\n setContainer(key: string, container_type: \"List\"): LoroList;\n setContainer(key: string, container_type: \"Text\"): LoroText;\n setContainer(key: string, container_type: \"Tree\"): LoroTree;\n setContainer(key: string, container_type: string): never;\n\n get(key: string): undefined | Value | Container;\n getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];\n set(key: string, value: Value | Prelim): void;\n setTyped<Key extends keyof T & string>(key: Key, value: T[Key]): void;\n delete(key: string): void;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroText {\n insert(pos: number, text: string): void;\n delete(pos: number, len: number): void;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroTree {\n create(parent: TreeID | undefined): TreeID;\n mov(target: TreeID, parent: TreeID | undefined): void;\n delete(target: TreeID): void;\n getMeta(target: TreeID): LoroMap;\n parent(target: TreeID): TreeID | undefined;\n contains(target: TreeID): boolean;\n subscribe(txn: Loro, listener: Listener): number;\n }\n}\n"],"names":["Loro","LoroList","LoroMap"],"mappings":";;;;AAKAA,aAAK,CAAA,SAAA,CAAU,WAAc,GAAA,SAAA,GAAa,IAAM,EAAA;AAC9C,EAAO,OAAA,IAAA,CAAK,MAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAC5B,CAAA,CAAA;AACAA,aAAK,CAAA,SAAA,CAAU,YAAe,GAAA,SAAA,GAAa,IAAM,EAAA;AAC/C,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,IAAI,CAAA,CAAA;AAC7B,CAAA,CAAA;AACAC,iBAAA,CAAS,SAAU,CAAA,QAAA,GAAW,SAAU,IAAA,EAAM,KAAO,EAAA;AACnD,EAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AAC5B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,aAAA,CAAc,KAAK,CAAG,EAAA;AACrD,IAAO,OAAA,IAAA,CAAK,iBAAiB,KAAK,CAAA,CAAA;AAAA,GAC7B,MAAA;AACL,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA,CAAA;AACAA,iBAAS,CAAA,SAAA,CAAU,WAAc,GAAA,SAAA,GAAa,IAAM,EAAA;AAClD,EAAO,OAAA,IAAA,CAAK,MAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAC5B,CAAA,CAAA;AACAC,gBAAA,CAAQ,SAAU,CAAA,QAAA,GAAW,SAAU,IAAA,EAAM,GAAK,EAAA;AAChD,EAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AAC1B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,aAAA,CAAc,KAAK,CAAG,EAAA;AACrD,IAAO,OAAA,IAAA,CAAK,iBAAiB,KAAK,CAAA,CAAA;AAAA,GAC7B,MAAA;AACL,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA,CAAA;AACAA,gBAAQ,CAAA,SAAA,CAAU,QAAW,GAAA,SAAA,GAAa,IAAM,EAAA;AAC9C,EAAO,OAAA,IAAA,CAAK,GAAI,CAAA,GAAG,IAAI,CAAA,CAAA;AACzB,CAAA,CAAA;AAqEA,MAAM,eAAkB,GAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,QAAQ,MAAM,CAAA,CAAA;AAE/C,SAAS,cAAc,CAA6B,EAAA;AACzD,EAAO,OAAA,CAAA,CAAE,WAAW,MAAM,CAAA,CAAA;AAC5B,CAAA;AAIO,SAAS,YAAY,KAAgC,EAAA;AAC1D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,IAAS,IAAM,EAAA;AAC9C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,IAAI,KAAM,CAAA,SAAA,CAAA;AAChB,EAAO,OAAA,CAAA,CAAE,eAAe,MAAM,CAAA,IAAK,gBAAgB,QAAS,CAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AAC1E,CAAA;AAEO,SAAS,UAAU,KAAoC,EAAA;AAC5D,EAAI,IAAA,WAAA,CAAY,KAAK,CAAG,EAAA;AACtB,IAAA,OAAO,MAAM,IAAK,EAAA,CAAA;AAAA,GACpB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;;;;;;;;;;;;;"}
|
package/dist/loro.mjs
CHANGED
|
@@ -30,9 +30,23 @@ LoroMap.prototype.getTyped = function(loro, key) {
|
|
|
30
30
|
LoroMap.prototype.setTyped = function(...args) {
|
|
31
31
|
return this.set(...args);
|
|
32
32
|
};
|
|
33
|
+
const CONTAINER_TYPES = ["Map", "Text", "List", "Tree"];
|
|
33
34
|
function isContainerId(s) {
|
|
34
35
|
return s.startsWith("cid:");
|
|
35
36
|
}
|
|
37
|
+
function isContainer(value) {
|
|
38
|
+
if (typeof value !== "object" || value == null) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const p = value.__proto__;
|
|
42
|
+
return p.hasOwnProperty("kind") && CONTAINER_TYPES.includes(value.kind());
|
|
43
|
+
}
|
|
44
|
+
function valueType(value) {
|
|
45
|
+
if (isContainer(value)) {
|
|
46
|
+
return value.kind();
|
|
47
|
+
}
|
|
48
|
+
return "Json";
|
|
49
|
+
}
|
|
36
50
|
|
|
37
|
-
export { isContainerId };
|
|
51
|
+
export { isContainer, isContainerId, valueType };
|
|
38
52
|
//# sourceMappingURL=loro.mjs.map
|
package/dist/loro.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loro.mjs","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport { Delta } from \"loro-wasm\";\nimport { PrelimText, PrelimList, PrelimMap } from \"loro-wasm\";\nimport {
|
|
1
|
+
{"version":3,"file":"loro.mjs","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport { Container, ContainerType, Delta, OpId, Value } from \"loro-wasm\";\nimport { PrelimText, PrelimList, PrelimMap } from \"loro-wasm\";\nimport { ContainerID, Loro, LoroList, LoroMap, TreeID } from \"loro-wasm\";\n\nLoro.prototype.getTypedMap = function (...args) {\n return this.getMap(...args);\n};\nLoro.prototype.getTypedList = function (...args) {\n return this.getList(...args);\n};\nLoroList.prototype.getTyped = function (loro, index) {\n const value = this.get(index);\n if (typeof value === \"string\" && isContainerId(value)) {\n return loro.getContainerById(value);\n } else {\n return value;\n }\n};\nLoroList.prototype.insertTyped = function (...args) {\n return this.insert(...args);\n};\nLoroMap.prototype.getTyped = function (loro, key) {\n const value = this.get(key);\n if (typeof value === \"string\" && isContainerId(value)) {\n return loro.getContainerById(value);\n } else {\n return value;\n }\n};\nLoroMap.prototype.setTyped = function (...args) {\n return this.set(...args);\n};\n\nexport type Prelim = PrelimList | PrelimMap | PrelimText;\nexport type Frontiers = OpId[];\n\n/**\n * Represents a path to identify the exact location of an event's target.\n * The path is composed of numbers (e.g., indices of a list container) and strings\n * (e.g., keys of a map container), indicating the absolute position of the event's source\n * within a loro document.\n */\nexport type Path = (number | string)[];\n\n/**\n * The event of Loro.\n * @prop local - Indicates whether the event is local.\n * @prop origin - (Optional) Provides information about the origin of the event.\n * @prop diff - Contains the differential information related to the event.\n * @prop target - Identifies the container ID of the event's target.\n * @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.\n */\nexport interface LoroEvent {\n /**\n * The unique ID of the event.\n */\n id: bigint;\n local: boolean;\n origin?: string;\n /**\n * If true, this event was triggered by a child container.\n */\n fromChildren: boolean;\n /**\n * If true, this event was triggered by a checkout.\n */\n fromCheckout: boolean;\n diff: Diff;\n target: ContainerID;\n path: Path;\n}\n\nexport type ListDiff = {\n type: \"list\";\n diff: Delta<(Value | Container)[]>[];\n};\n\nexport type TextDiff = {\n type: \"text\";\n diff: Delta<string>[];\n};\n\nexport type MapDiff = {\n type: \"map\";\n updated: Record<string, Value | Container | undefined>;\n};\n\nexport type TreeDiff = {\n type: \"tree\";\n diff:\n | { target: TreeID; action: \"create\" | \"delete\" }\n | { target: TreeID; action: \"move\"; parent: TreeID };\n};\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;\n\ninterface Listener {\n (event: LoroEvent): void;\n}\n\nconst CONTAINER_TYPES = [\"Map\", \"Text\", \"List\", \"Tree\"];\n\nexport function isContainerId(s: string): s is ContainerID {\n return s.startsWith(\"cid:\");\n}\n\nexport { Loro };\n\nexport function isContainer(value: any): value is Container {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n const p = value.__proto__;\n return p.hasOwnProperty(\"kind\") && CONTAINER_TYPES.includes(value.kind());\n}\n\nexport function valueType(value: any): \"Json\" | ContainerType {\n if (isContainer(value)) {\n return value.kind();\n }\n\n return \"Json\";\n}\n\ndeclare module \"loro-wasm\" {\n interface Loro {\n subscribe(listener: Listener): number;\n }\n\n interface Loro<T extends Record<string, any> = Record<string, any>> {\n getTypedMap<Key extends keyof T & string>(\n name: Key\n ): T[Key] extends LoroMap ? T[Key] : never;\n getTypedList<Key extends keyof T & string>(\n name: Key\n ): T[Key] extends LoroList ? T[Key] : never;\n }\n\n interface LoroList<T extends any[] = any[]> {\n insertContainer(pos: number, container: \"Map\"): LoroMap;\n insertContainer(pos: number, container: \"List\"): LoroList;\n insertContainer(pos: number, container: \"Text\"): LoroText;\n insertContainer(pos: number, container: \"Tree\"): LoroTree;\n insertContainer(pos: number, container: string): never;\n\n get(index: number): undefined | Value | Container;\n getTyped<Key extends keyof T & number>(loro: Loro, index: Key): T[Key];\n insertTyped<Key extends keyof T & number>(pos: Key, value: T[Key]): void;\n insert(pos: number, value: Value | Prelim): void;\n delete(pos: number, len: number): void;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroMap<T extends Record<string, any> = Record<string, any>> {\n setContainer(key: string, container_type: \"Map\"): LoroMap;\n setContainer(key: string, container_type: \"List\"): LoroList;\n setContainer(key: string, container_type: \"Text\"): LoroText;\n setContainer(key: string, container_type: \"Tree\"): LoroTree;\n setContainer(key: string, container_type: string): never;\n\n get(key: string): undefined | Value | Container;\n getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];\n set(key: string, value: Value | Prelim): void;\n setTyped<Key extends keyof T & string>(key: Key, value: T[Key]): void;\n delete(key: string): void;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroText {\n insert(pos: number, text: string): void;\n delete(pos: number, len: number): void;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroTree {\n create(parent: TreeID | undefined): TreeID;\n mov(target: TreeID, parent: TreeID | undefined): void;\n delete(target: TreeID): void;\n getMeta(target: TreeID): LoroMap;\n parent(target: TreeID): TreeID | undefined;\n contains(target: TreeID): boolean;\n subscribe(txn: Loro, listener: Listener): number;\n }\n}\n"],"names":[],"mappings":";;;;AAKA,IAAK,CAAA,SAAA,CAAU,WAAc,GAAA,SAAA,GAAa,IAAM,EAAA;AAC9C,EAAO,OAAA,IAAA,CAAK,MAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAC5B,CAAA,CAAA;AACA,IAAK,CAAA,SAAA,CAAU,YAAe,GAAA,SAAA,GAAa,IAAM,EAAA;AAC/C,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,IAAI,CAAA,CAAA;AAC7B,CAAA,CAAA;AACA,QAAA,CAAS,SAAU,CAAA,QAAA,GAAW,SAAU,IAAA,EAAM,KAAO,EAAA;AACnD,EAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AAC5B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,aAAA,CAAc,KAAK,CAAG,EAAA;AACrD,IAAO,OAAA,IAAA,CAAK,iBAAiB,KAAK,CAAA,CAAA;AAAA,GAC7B,MAAA;AACL,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA,CAAA;AACA,QAAS,CAAA,SAAA,CAAU,WAAc,GAAA,SAAA,GAAa,IAAM,EAAA;AAClD,EAAO,OAAA,IAAA,CAAK,MAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAC5B,CAAA,CAAA;AACA,OAAA,CAAQ,SAAU,CAAA,QAAA,GAAW,SAAU,IAAA,EAAM,GAAK,EAAA;AAChD,EAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AAC1B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,aAAA,CAAc,KAAK,CAAG,EAAA;AACrD,IAAO,OAAA,IAAA,CAAK,iBAAiB,KAAK,CAAA,CAAA;AAAA,GAC7B,MAAA;AACL,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA,CAAA;AACA,OAAQ,CAAA,SAAA,CAAU,QAAW,GAAA,SAAA,GAAa,IAAM,EAAA;AAC9C,EAAO,OAAA,IAAA,CAAK,GAAI,CAAA,GAAG,IAAI,CAAA,CAAA;AACzB,CAAA,CAAA;AAqEA,MAAM,eAAkB,GAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,QAAQ,MAAM,CAAA,CAAA;AAE/C,SAAS,cAAc,CAA6B,EAAA;AACzD,EAAO,OAAA,CAAA,CAAE,WAAW,MAAM,CAAA,CAAA;AAC5B,CAAA;AAIO,SAAS,YAAY,KAAgC,EAAA;AAC1D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,IAAS,IAAM,EAAA;AAC9C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,IAAI,KAAM,CAAA,SAAA,CAAA;AAChB,EAAO,OAAA,CAAA,CAAE,eAAe,MAAM,CAAA,IAAK,gBAAgB,QAAS,CAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AAC1E,CAAA;AAEO,SAAS,UAAU,KAAoC,EAAA;AAC5D,EAAI,IAAA,WAAA,CAAY,KAAK,CAAG,EAAA;AACtB,IAAA,OAAO,MAAM,IAAK,EAAA,CAAA;AAAA,GACpB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loro-crdt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Loro CRDTs is a high-performance CRDT framework that makes your app state synchronized, collaborative and maintainable effortlessly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"crdt",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"homepage": "https://loro.dev",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"loro-wasm": "0.
|
|
20
|
+
"loro-wasm": "0.6.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
export * from "loro-wasm";
|
|
2
|
-
import { Delta } from "loro-wasm";
|
|
2
|
+
import { Container, ContainerType, Delta, OpId, Value } from "loro-wasm";
|
|
3
3
|
import { PrelimText, PrelimList, PrelimMap } from "loro-wasm";
|
|
4
|
-
import {
|
|
5
|
-
ContainerID,
|
|
6
|
-
Loro,
|
|
7
|
-
LoroList,
|
|
8
|
-
LoroMap,
|
|
9
|
-
LoroText,
|
|
10
|
-
LoroTree,
|
|
11
|
-
TreeID,
|
|
12
|
-
} from "loro-wasm";
|
|
4
|
+
import { ContainerID, Loro, LoroList, LoroMap, TreeID } from "loro-wasm";
|
|
13
5
|
|
|
14
6
|
Loro.prototype.getTypedMap = function (...args) {
|
|
15
7
|
return this.getMap(...args);
|
|
@@ -40,21 +32,8 @@ LoroMap.prototype.setTyped = function (...args) {
|
|
|
40
32
|
return this.set(...args);
|
|
41
33
|
};
|
|
42
34
|
|
|
43
|
-
/**
|
|
44
|
-
* Data types supported by loro
|
|
45
|
-
*/
|
|
46
|
-
export type Value =
|
|
47
|
-
| ContainerID
|
|
48
|
-
| string
|
|
49
|
-
| number
|
|
50
|
-
| boolean
|
|
51
|
-
| null
|
|
52
|
-
| { [key: string]: Value }
|
|
53
|
-
| Uint8Array
|
|
54
|
-
| Value[];
|
|
55
|
-
|
|
56
|
-
export type Container = LoroList | LoroMap | LoroText | LoroTree;
|
|
57
35
|
export type Prelim = PrelimList | PrelimMap | PrelimText;
|
|
36
|
+
export type Frontiers = OpId[];
|
|
58
37
|
|
|
59
38
|
/**
|
|
60
39
|
* Represents a path to identify the exact location of an event's target.
|
|
@@ -94,7 +73,7 @@ export interface LoroEvent {
|
|
|
94
73
|
|
|
95
74
|
export type ListDiff = {
|
|
96
75
|
type: "list";
|
|
97
|
-
diff: Delta<Value[]>[];
|
|
76
|
+
diff: Delta<(Value | Container)[]>[];
|
|
98
77
|
};
|
|
99
78
|
|
|
100
79
|
export type TextDiff = {
|
|
@@ -104,7 +83,7 @@ export type TextDiff = {
|
|
|
104
83
|
|
|
105
84
|
export type MapDiff = {
|
|
106
85
|
type: "map";
|
|
107
|
-
updated: Record<string, Value | undefined>;
|
|
86
|
+
updated: Record<string, Value | Container | undefined>;
|
|
108
87
|
};
|
|
109
88
|
|
|
110
89
|
export type TreeDiff = {
|
|
@@ -128,6 +107,23 @@ export function isContainerId(s: string): s is ContainerID {
|
|
|
128
107
|
|
|
129
108
|
export { Loro };
|
|
130
109
|
|
|
110
|
+
export function isContainer(value: any): value is Container {
|
|
111
|
+
if (typeof value !== "object" || value == null) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const p = value.__proto__;
|
|
116
|
+
return p.hasOwnProperty("kind") && CONTAINER_TYPES.includes(value.kind());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function valueType(value: any): "Json" | ContainerType {
|
|
120
|
+
if (isContainer(value)) {
|
|
121
|
+
return value.kind();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return "Json";
|
|
125
|
+
}
|
|
126
|
+
|
|
131
127
|
declare module "loro-wasm" {
|
|
132
128
|
interface Loro {
|
|
133
129
|
subscribe(listener: Listener): number;
|
|
@@ -135,10 +131,10 @@ declare module "loro-wasm" {
|
|
|
135
131
|
|
|
136
132
|
interface Loro<T extends Record<string, any> = Record<string, any>> {
|
|
137
133
|
getTypedMap<Key extends keyof T & string>(
|
|
138
|
-
name: Key
|
|
134
|
+
name: Key
|
|
139
135
|
): T[Key] extends LoroMap ? T[Key] : never;
|
|
140
136
|
getTypedList<Key extends keyof T & string>(
|
|
141
|
-
name: Key
|
|
137
|
+
name: Key
|
|
142
138
|
): T[Key] extends LoroList ? T[Key] : never;
|
|
143
139
|
}
|
|
144
140
|
|
|
@@ -177,4 +173,14 @@ declare module "loro-wasm" {
|
|
|
177
173
|
delete(pos: number, len: number): void;
|
|
178
174
|
subscribe(txn: Loro, listener: Listener): number;
|
|
179
175
|
}
|
|
176
|
+
|
|
177
|
+
interface LoroTree {
|
|
178
|
+
create(parent: TreeID | undefined): TreeID;
|
|
179
|
+
mov(target: TreeID, parent: TreeID | undefined): void;
|
|
180
|
+
delete(target: TreeID): void;
|
|
181
|
+
getMeta(target: TreeID): LoroMap;
|
|
182
|
+
parent(target: TreeID): TreeID | undefined;
|
|
183
|
+
contains(target: TreeID): boolean;
|
|
184
|
+
subscribe(txn: Loro, listener: Listener): number;
|
|
185
|
+
}
|
|
180
186
|
}
|