loro-crdt 0.13.0 → 0.13.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/CHANGELOG.md +8 -0
- package/dist/loro.d.ts +19 -15
- package/dist/loro.js.map +1 -1
- package/dist/loro.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +42 -24
package/CHANGELOG.md
CHANGED
package/dist/loro.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Container, Value, TreeID, OpId,
|
|
1
|
+
import { ContainerID, Container, Value, TreeID, OpId, Delta, LoroText, LoroMap, LoroTree, LoroList } from 'loro-wasm';
|
|
2
2
|
export * from 'loro-wasm';
|
|
3
3
|
export { Loro } from 'loro-wasm';
|
|
4
4
|
|
|
@@ -115,7 +115,7 @@ declare function isContainer(value: any): value is Container;
|
|
|
115
115
|
* getType({}); // "Json"
|
|
116
116
|
* ```
|
|
117
117
|
*/
|
|
118
|
-
declare function getType<T>(value: T): T extends LoroText ? "Text" : T extends LoroMap ? "Map" : T extends LoroTree ? "Tree" : T extends LoroList ? "List" : "Json";
|
|
118
|
+
declare function getType<T>(value: T): T extends LoroText ? "Text" : T extends LoroMap<any> ? "Map" : T extends LoroTree<any> ? "Tree" : T extends LoroList<any> ? "List" : "Json";
|
|
119
119
|
declare module "loro-wasm" {
|
|
120
120
|
interface Loro {
|
|
121
121
|
subscribe(listener: Listener): number;
|
|
@@ -123,23 +123,25 @@ declare module "loro-wasm" {
|
|
|
123
123
|
interface Loro<T extends Record<string, any> = Record<string, any>> {
|
|
124
124
|
getTypedMap<Key extends keyof T & string>(name: Key): T[Key] extends LoroMap ? T[Key] : never;
|
|
125
125
|
getTypedList<Key extends keyof T & string>(name: Key): T[Key] extends LoroList ? T[Key] : never;
|
|
126
|
+
getMap(key: string | ContainerID): LoroMap<T[string]>;
|
|
127
|
+
getList(key: string | ContainerID): LoroList<T[string]>;
|
|
128
|
+
getTree(key: string | ContainerID): LoroTree<T[string]>;
|
|
129
|
+
getText(key: string | ContainerID): LoroText;
|
|
126
130
|
}
|
|
127
131
|
interface LoroList<T extends any[] = any[]> {
|
|
132
|
+
new (): LoroList<T>;
|
|
128
133
|
insertContainer<C extends Container>(pos: number, child: C): C;
|
|
129
134
|
get(index: number): undefined | Value | Container;
|
|
130
135
|
getTyped<Key extends keyof T & number>(loro: Loro, index: Key): T[Key];
|
|
131
136
|
insertTyped<Key extends keyof T & number>(pos: Key, value: T[Key]): void;
|
|
132
|
-
insert(pos: number, value: Container): never;
|
|
133
137
|
insert(pos: number, value: Value): void;
|
|
134
138
|
delete(pos: number, len: number): void;
|
|
135
139
|
subscribe(txn: Loro, listener: Listener): number;
|
|
140
|
+
getAttached(): undefined | LoroList<T>;
|
|
136
141
|
}
|
|
137
142
|
interface LoroMap<T extends Record<string, any> = Record<string, any>> {
|
|
138
|
-
|
|
139
|
-
getOrCreateContainer(key: string,
|
|
140
|
-
getOrCreateContainer(key: string, container_type: "Text"): LoroText;
|
|
141
|
-
getOrCreateContainer(key: string, container_type: "Tree"): LoroTree;
|
|
142
|
-
getOrCreateContainer(key: string, container_type: string): never;
|
|
143
|
+
new (): LoroMap<T>;
|
|
144
|
+
getOrCreateContainer<C extends Container>(key: string, child: C): C;
|
|
143
145
|
setContainer<C extends Container>(key: string, child: C): C;
|
|
144
146
|
get(key: string): undefined | Value | Container;
|
|
145
147
|
getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];
|
|
@@ -149,25 +151,27 @@ declare module "loro-wasm" {
|
|
|
149
151
|
subscribe(txn: Loro, listener: Listener): number;
|
|
150
152
|
}
|
|
151
153
|
interface LoroText {
|
|
154
|
+
new (): LoroText;
|
|
152
155
|
insert(pos: number, text: string): void;
|
|
153
156
|
delete(pos: number, len: number): void;
|
|
154
157
|
subscribe(txn: Loro, listener: Listener): number;
|
|
155
158
|
}
|
|
156
|
-
interface LoroTree {
|
|
157
|
-
|
|
159
|
+
interface LoroTree<T extends Record<string, any> = Record<string, any>> {
|
|
160
|
+
new (): LoroTree<T>;
|
|
161
|
+
createNode(parent: TreeID | undefined): LoroTreeNode<T>;
|
|
158
162
|
move(target: TreeID, parent: TreeID | undefined): void;
|
|
159
163
|
delete(target: TreeID): void;
|
|
160
164
|
has(target: TreeID): boolean;
|
|
161
165
|
getNodeByID(target: TreeID): LoroTreeNode;
|
|
162
166
|
subscribe(txn: Loro, listener: Listener): number;
|
|
163
167
|
}
|
|
164
|
-
interface LoroTreeNode {
|
|
165
|
-
readonly data: LoroMap
|
|
166
|
-
createNode(): LoroTreeNode
|
|
168
|
+
interface LoroTreeNode<T extends Record<string, any> = Record<string, any>> {
|
|
169
|
+
readonly data: LoroMap<T>;
|
|
170
|
+
createNode(): LoroTreeNode<T>;
|
|
167
171
|
setAsRoot(): void;
|
|
168
|
-
moveTo(parent: LoroTreeNode): void;
|
|
172
|
+
moveTo(parent: LoroTreeNode<T>): void;
|
|
169
173
|
parent(): LoroTreeNode | undefined;
|
|
170
|
-
children(): Array<LoroTreeNode
|
|
174
|
+
children(): Array<LoroTreeNode<T>>;
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
|
package/dist/loro.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loro.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n LoroTreeNode,\n OpId,\n TreeID,\n Value,\n} 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 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) strings\n * (e.g., keys of a map container) and TreeID (the node of a tree container),\n * indicating the absolute position of the event's source within a loro document.\n */\nexport type Path = (number | string | TreeID)[];\n\n/**\n * A batch of events that created by a single `import`/`transaction`/`checkout`.\n *\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 LoroEventBatch {\n local: boolean;\n /**\n * If true, this event was triggered by a checkout.\n */\n fromCheckout: boolean;\n origin?: string;\n /**\n * The container ID of the current event receiver.\n * It's undefined if the subscriber is on the root document.\n */\n currentTarget?: ContainerID;\n events: LoroEvent[];\n}\n\n/**\n * The concrete event of Loro.\n */\nexport interface LoroEvent {\n /**\n * The container ID of the event's target.\n */\n target: ContainerID;\n diff: Diff;\n /**\n * 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 */\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 TreeDiffItem =\n | { target: TreeID; action: \"create\"; parent: TreeID | undefined }\n | { target: TreeID; action: \"delete\" }\n | { target: TreeID; action: \"move\"; parent: TreeID | undefined };\n\nexport type TreeDiff = {\n type: \"tree\";\n diff: TreeDiffItem[];\n};\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;\n\ninterface Listener {\n (event: LoroEventBatch): 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\n/** Whether the value is a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * isContainer(map); // true\n * isContainer(list); // true\n * isContainer(text); // true\n * isContainer(123); // false\n * isContainer(\"123\"); // false\n * isContainer({}); // false\n */\nexport function isContainer(value: any): value is Container {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n const p = Object.getPrototypeOf(value);\n if (p == null || typeof p !== \"object\" || typeof p[\"kind\"] !== \"function\") {\n return false;\n }\n\n return CONTAINER_TYPES.includes(value.kind());\n}\n\n/** Get the type of a value that may be a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * getType(map); // \"Map\"\n * getType(list); // \"List\"\n * getType(text); // \"Text\"\n * getType(123); // \"Json\"\n * getType(\"123\"); // \"Json\"\n * getType({}); // \"Json\"\n * ```\n */\nexport function getType<T>(\n value: T,\n): T extends LoroText ? \"Text\"\n : T extends LoroMap ? \"Map\"\n : T extends LoroTree ? \"Tree\"\n : T extends LoroList ? \"List\"\n : \"Json\" {\n if (isContainer(value)) {\n return value.kind();\n }\n\n return \"Json\" as any;\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
|
|
1
|
+
{"version":3,"file":"loro.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n LoroTreeNode,\n OpId,\n TreeID,\n Value,\n} 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 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) strings\n * (e.g., keys of a map container) and TreeID (the node of a tree container),\n * indicating the absolute position of the event's source within a loro document.\n */\nexport type Path = (number | string | TreeID)[];\n\n/**\n * A batch of events that created by a single `import`/`transaction`/`checkout`.\n *\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 LoroEventBatch {\n local: boolean;\n /**\n * If true, this event was triggered by a checkout.\n */\n fromCheckout: boolean;\n origin?: string;\n /**\n * The container ID of the current event receiver.\n * It's undefined if the subscriber is on the root document.\n */\n currentTarget?: ContainerID;\n events: LoroEvent[];\n}\n\n/**\n * The concrete event of Loro.\n */\nexport interface LoroEvent {\n /**\n * The container ID of the event's target.\n */\n target: ContainerID;\n diff: Diff;\n /**\n * 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 */\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 TreeDiffItem =\n | { target: TreeID; action: \"create\"; parent: TreeID | undefined }\n | { target: TreeID; action: \"delete\" }\n | { target: TreeID; action: \"move\"; parent: TreeID | undefined };\n\nexport type TreeDiff = {\n type: \"tree\";\n diff: TreeDiffItem[];\n};\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;\n\ninterface Listener {\n (event: LoroEventBatch): 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\n/** Whether the value is a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * isContainer(map); // true\n * isContainer(list); // true\n * isContainer(text); // true\n * isContainer(123); // false\n * isContainer(\"123\"); // false\n * isContainer({}); // false\n */\nexport function isContainer(value: any): value is Container {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n const p = Object.getPrototypeOf(value);\n if (p == null || typeof p !== \"object\" || typeof p[\"kind\"] !== \"function\") {\n return false;\n }\n\n return CONTAINER_TYPES.includes(value.kind());\n}\n\n/** Get the type of a value that may be a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * getType(map); // \"Map\"\n * getType(list); // \"List\"\n * getType(text); // \"Text\"\n * getType(123); // \"Json\"\n * getType(\"123\"); // \"Json\"\n * getType({}); // \"Json\"\n * ```\n */\nexport function getType<T>(\n value: T,\n): T extends LoroText ? \"Text\"\n : T extends LoroMap<any> ? \"Map\"\n : T extends LoroTree<any> ? \"Tree\"\n : T extends LoroList<any> ? \"List\"\n : \"Json\" {\n if (isContainer(value)) {\n return value.kind() as unknown as any;\n }\n\n return \"Json\" as any;\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 getMap(key: string | ContainerID): LoroMap<T[string]>;\n getList(key: string | ContainerID): LoroList<T[string]>;\n getTree(key: string | ContainerID): LoroTree<T[string]>;\n getText(key: string | ContainerID): LoroText;\n }\n\n interface LoroList<\n T extends any[] = any[],\n > {\n new (): LoroList<T>;\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): C;\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): void;\n delete(pos: number, len: number): void;\n subscribe(txn: Loro, listener: Listener): number;\n getAttached(): undefined | LoroList<T>;\n }\n\n interface LoroMap<\n T extends Record<string, any> = Record<string, any>,\n > {\n new (): LoroMap<T>;\n getOrCreateContainer<C extends Container>(\n key: string,\n child: C,\n ): C;\n setContainer<C extends Container>(\n key: string,\n child: C,\n ): C;\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): 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 new (): 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 T extends Record<string, any> = Record<string, any>,\n > {\n new (): LoroTree<T>;\n createNode(parent: TreeID | undefined): LoroTreeNode<T>;\n move(target: TreeID, parent: TreeID | undefined): void;\n delete(target: TreeID): void;\n has(target: TreeID): boolean;\n getNodeByID(target: TreeID): LoroTreeNode;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroTreeNode<\n T extends Record<string, any> = Record<string, any>,\n > {\n readonly data: LoroMap<T>;\n createNode(): LoroTreeNode<T>;\n setAsRoot(): void;\n moveTo(parent: LoroTreeNode<T>): void;\n parent(): LoroTreeNode | undefined;\n children(): Array<LoroTreeNode<T>>;\n }\n}\n"],"names":["Loro","LoroList","LoroMap"],"mappings":";;;;AAgBAA,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;AAkFA,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;AAoBO,SAAS,YAAY,KAAgC,EAAA;AAC1D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,IAAS,IAAM,EAAA;AAC9C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAM,MAAA,CAAA,GAAI,MAAO,CAAA,cAAA,CAAe,KAAK,CAAA,CAAA;AACrC,EAAI,IAAA,CAAA,IAAK,QAAQ,OAAO,CAAA,KAAM,YAAY,OAAO,CAAA,CAAE,MAAM,CAAA,KAAM,UAAY,EAAA;AACzE,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,OAAO,eAAgB,CAAA,QAAA,CAAS,KAAM,CAAA,IAAA,EAAM,CAAA,CAAA;AAC9C,CAAA;AAmBO,SAAS,QACd,KAKS,EAAA;AACT,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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loro.mjs","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n LoroTreeNode,\n OpId,\n TreeID,\n Value,\n} 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 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) strings\n * (e.g., keys of a map container) and TreeID (the node of a tree container),\n * indicating the absolute position of the event's source within a loro document.\n */\nexport type Path = (number | string | TreeID)[];\n\n/**\n * A batch of events that created by a single `import`/`transaction`/`checkout`.\n *\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 LoroEventBatch {\n local: boolean;\n /**\n * If true, this event was triggered by a checkout.\n */\n fromCheckout: boolean;\n origin?: string;\n /**\n * The container ID of the current event receiver.\n * It's undefined if the subscriber is on the root document.\n */\n currentTarget?: ContainerID;\n events: LoroEvent[];\n}\n\n/**\n * The concrete event of Loro.\n */\nexport interface LoroEvent {\n /**\n * The container ID of the event's target.\n */\n target: ContainerID;\n diff: Diff;\n /**\n * 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 */\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 TreeDiffItem =\n | { target: TreeID; action: \"create\"; parent: TreeID | undefined }\n | { target: TreeID; action: \"delete\" }\n | { target: TreeID; action: \"move\"; parent: TreeID | undefined };\n\nexport type TreeDiff = {\n type: \"tree\";\n diff: TreeDiffItem[];\n};\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;\n\ninterface Listener {\n (event: LoroEventBatch): 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\n/** Whether the value is a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * isContainer(map); // true\n * isContainer(list); // true\n * isContainer(text); // true\n * isContainer(123); // false\n * isContainer(\"123\"); // false\n * isContainer({}); // false\n */\nexport function isContainer(value: any): value is Container {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n const p = Object.getPrototypeOf(value);\n if (p == null || typeof p !== \"object\" || typeof p[\"kind\"] !== \"function\") {\n return false;\n }\n\n return CONTAINER_TYPES.includes(value.kind());\n}\n\n/** Get the type of a value that may be a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * getType(map); // \"Map\"\n * getType(list); // \"List\"\n * getType(text); // \"Text\"\n * getType(123); // \"Json\"\n * getType(\"123\"); // \"Json\"\n * getType({}); // \"Json\"\n * ```\n */\nexport function getType<T>(\n value: T,\n): T extends LoroText ? \"Text\"\n : T extends LoroMap ? \"Map\"\n : T extends LoroTree ? \"Tree\"\n : T extends LoroList ? \"List\"\n : \"Json\" {\n if (isContainer(value)) {\n return value.kind();\n }\n\n return \"Json\" as any;\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
|
|
1
|
+
{"version":3,"file":"loro.mjs","sources":["../src/index.ts"],"sourcesContent":["export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n LoroTreeNode,\n OpId,\n TreeID,\n Value,\n} 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 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) strings\n * (e.g., keys of a map container) and TreeID (the node of a tree container),\n * indicating the absolute position of the event's source within a loro document.\n */\nexport type Path = (number | string | TreeID)[];\n\n/**\n * A batch of events that created by a single `import`/`transaction`/`checkout`.\n *\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 LoroEventBatch {\n local: boolean;\n /**\n * If true, this event was triggered by a checkout.\n */\n fromCheckout: boolean;\n origin?: string;\n /**\n * The container ID of the current event receiver.\n * It's undefined if the subscriber is on the root document.\n */\n currentTarget?: ContainerID;\n events: LoroEvent[];\n}\n\n/**\n * The concrete event of Loro.\n */\nexport interface LoroEvent {\n /**\n * The container ID of the event's target.\n */\n target: ContainerID;\n diff: Diff;\n /**\n * 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 */\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 TreeDiffItem =\n | { target: TreeID; action: \"create\"; parent: TreeID | undefined }\n | { target: TreeID; action: \"delete\" }\n | { target: TreeID; action: \"move\"; parent: TreeID | undefined };\n\nexport type TreeDiff = {\n type: \"tree\";\n diff: TreeDiffItem[];\n};\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;\n\ninterface Listener {\n (event: LoroEventBatch): 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\n/** Whether the value is a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * isContainer(map); // true\n * isContainer(list); // true\n * isContainer(text); // true\n * isContainer(123); // false\n * isContainer(\"123\"); // false\n * isContainer({}); // false\n */\nexport function isContainer(value: any): value is Container {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n const p = Object.getPrototypeOf(value);\n if (p == null || typeof p !== \"object\" || typeof p[\"kind\"] !== \"function\") {\n return false;\n }\n\n return CONTAINER_TYPES.includes(value.kind());\n}\n\n/** Get the type of a value that may be a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * getType(map); // \"Map\"\n * getType(list); // \"List\"\n * getType(text); // \"Text\"\n * getType(123); // \"Json\"\n * getType(\"123\"); // \"Json\"\n * getType({}); // \"Json\"\n * ```\n */\nexport function getType<T>(\n value: T,\n): T extends LoroText ? \"Text\"\n : T extends LoroMap<any> ? \"Map\"\n : T extends LoroTree<any> ? \"Tree\"\n : T extends LoroList<any> ? \"List\"\n : \"Json\" {\n if (isContainer(value)) {\n return value.kind() as unknown as any;\n }\n\n return \"Json\" as any;\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 getMap(key: string | ContainerID): LoroMap<T[string]>;\n getList(key: string | ContainerID): LoroList<T[string]>;\n getTree(key: string | ContainerID): LoroTree<T[string]>;\n getText(key: string | ContainerID): LoroText;\n }\n\n interface LoroList<\n T extends any[] = any[],\n > {\n new (): LoroList<T>;\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): C;\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): void;\n delete(pos: number, len: number): void;\n subscribe(txn: Loro, listener: Listener): number;\n getAttached(): undefined | LoroList<T>;\n }\n\n interface LoroMap<\n T extends Record<string, any> = Record<string, any>,\n > {\n new (): LoroMap<T>;\n getOrCreateContainer<C extends Container>(\n key: string,\n child: C,\n ): C;\n setContainer<C extends Container>(\n key: string,\n child: C,\n ): C;\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): 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 new (): 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 T extends Record<string, any> = Record<string, any>,\n > {\n new (): LoroTree<T>;\n createNode(parent: TreeID | undefined): LoroTreeNode<T>;\n move(target: TreeID, parent: TreeID | undefined): void;\n delete(target: TreeID): void;\n has(target: TreeID): boolean;\n getNodeByID(target: TreeID): LoroTreeNode;\n subscribe(txn: Loro, listener: Listener): number;\n }\n\n interface LoroTreeNode<\n T extends Record<string, any> = Record<string, any>,\n > {\n readonly data: LoroMap<T>;\n createNode(): LoroTreeNode<T>;\n setAsRoot(): void;\n moveTo(parent: LoroTreeNode<T>): void;\n parent(): LoroTreeNode | undefined;\n children(): Array<LoroTreeNode<T>>;\n }\n}\n"],"names":[],"mappings":";;;;AAgBA,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;AAkFA,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;AAoBO,SAAS,YAAY,KAAgC,EAAA;AAC1D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,IAAS,IAAM,EAAA;AAC9C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAM,MAAA,CAAA,GAAI,MAAO,CAAA,cAAA,CAAe,KAAK,CAAA,CAAA;AACrC,EAAI,IAAA,CAAA,IAAK,QAAQ,OAAO,CAAA,KAAM,YAAY,OAAO,CAAA,CAAE,MAAM,CAAA,KAAM,UAAY,EAAA;AACzE,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,OAAO,eAAgB,CAAA,QAAA,CAAS,KAAM,CAAA,IAAA,EAAM,CAAA,CAAA;AAC9C,CAAA;AAmBO,SAAS,QACd,KAKS,EAAA;AACT,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.13.
|
|
3
|
+
"version": "0.13.1",
|
|
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.13.
|
|
20
|
+
"loro-wasm": "0.13.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "rollup -c",
|
|
39
39
|
"watch": "rollup -c -w",
|
|
40
|
-
"test": "vitest run",
|
|
40
|
+
"test": "vitest run --typecheck",
|
|
41
41
|
"prepublish": "pnpm run build"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -180,12 +180,12 @@ export function isContainer(value: any): value is Container {
|
|
|
180
180
|
export function getType<T>(
|
|
181
181
|
value: T,
|
|
182
182
|
): T extends LoroText ? "Text"
|
|
183
|
-
: T extends LoroMap ? "Map"
|
|
184
|
-
: T extends LoroTree ? "Tree"
|
|
185
|
-
: T extends LoroList ? "List"
|
|
183
|
+
: T extends LoroMap<any> ? "Map"
|
|
184
|
+
: T extends LoroTree<any> ? "Tree"
|
|
185
|
+
: T extends LoroList<any> ? "List"
|
|
186
186
|
: "Json" {
|
|
187
187
|
if (isContainer(value)) {
|
|
188
|
-
return value.kind();
|
|
188
|
+
return value.kind() as unknown as any;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
return "Json" as any;
|
|
@@ -203,29 +203,41 @@ declare module "loro-wasm" {
|
|
|
203
203
|
getTypedList<Key extends keyof T & string>(
|
|
204
204
|
name: Key,
|
|
205
205
|
): T[Key] extends LoroList ? T[Key] : never;
|
|
206
|
+
getMap(key: string | ContainerID): LoroMap<T[string]>;
|
|
207
|
+
getList(key: string | ContainerID): LoroList<T[string]>;
|
|
208
|
+
getTree(key: string | ContainerID): LoroTree<T[string]>;
|
|
209
|
+
getText(key: string | ContainerID): LoroText;
|
|
206
210
|
}
|
|
207
211
|
|
|
208
|
-
interface LoroList<
|
|
209
|
-
|
|
210
|
-
|
|
212
|
+
interface LoroList<
|
|
213
|
+
T extends any[] = any[],
|
|
214
|
+
> {
|
|
215
|
+
new (): LoroList<T>;
|
|
216
|
+
insertContainer<C extends Container>(
|
|
217
|
+
pos: number,
|
|
218
|
+
child: C,
|
|
219
|
+
): C;
|
|
211
220
|
get(index: number): undefined | Value | Container;
|
|
212
221
|
getTyped<Key extends keyof T & number>(loro: Loro, index: Key): T[Key];
|
|
213
222
|
insertTyped<Key extends keyof T & number>(pos: Key, value: T[Key]): void;
|
|
214
|
-
insert(pos: number, value: Container): never;
|
|
215
223
|
insert(pos: number, value: Value): void;
|
|
216
224
|
delete(pos: number, len: number): void;
|
|
217
225
|
subscribe(txn: Loro, listener: Listener): number;
|
|
226
|
+
getAttached(): undefined | LoroList<T>;
|
|
218
227
|
}
|
|
219
228
|
|
|
220
|
-
interface LoroMap<
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
getOrCreateContainer
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
+
interface LoroMap<
|
|
230
|
+
T extends Record<string, any> = Record<string, any>,
|
|
231
|
+
> {
|
|
232
|
+
new (): LoroMap<T>;
|
|
233
|
+
getOrCreateContainer<C extends Container>(
|
|
234
|
+
key: string,
|
|
235
|
+
child: C,
|
|
236
|
+
): C;
|
|
237
|
+
setContainer<C extends Container>(
|
|
238
|
+
key: string,
|
|
239
|
+
child: C,
|
|
240
|
+
): C;
|
|
229
241
|
get(key: string): undefined | Value | Container;
|
|
230
242
|
getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];
|
|
231
243
|
set(key: string, value: Value): void;
|
|
@@ -235,13 +247,17 @@ declare module "loro-wasm" {
|
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
interface LoroText {
|
|
250
|
+
new (): LoroText;
|
|
238
251
|
insert(pos: number, text: string): void;
|
|
239
252
|
delete(pos: number, len: number): void;
|
|
240
253
|
subscribe(txn: Loro, listener: Listener): number;
|
|
241
254
|
}
|
|
242
255
|
|
|
243
|
-
interface LoroTree
|
|
244
|
-
|
|
256
|
+
interface LoroTree<
|
|
257
|
+
T extends Record<string, any> = Record<string, any>,
|
|
258
|
+
> {
|
|
259
|
+
new (): LoroTree<T>;
|
|
260
|
+
createNode(parent: TreeID | undefined): LoroTreeNode<T>;
|
|
245
261
|
move(target: TreeID, parent: TreeID | undefined): void;
|
|
246
262
|
delete(target: TreeID): void;
|
|
247
263
|
has(target: TreeID): boolean;
|
|
@@ -249,12 +265,14 @@ declare module "loro-wasm" {
|
|
|
249
265
|
subscribe(txn: Loro, listener: Listener): number;
|
|
250
266
|
}
|
|
251
267
|
|
|
252
|
-
interface LoroTreeNode
|
|
253
|
-
|
|
254
|
-
|
|
268
|
+
interface LoroTreeNode<
|
|
269
|
+
T extends Record<string, any> = Record<string, any>,
|
|
270
|
+
> {
|
|
271
|
+
readonly data: LoroMap<T>;
|
|
272
|
+
createNode(): LoroTreeNode<T>;
|
|
255
273
|
setAsRoot(): void;
|
|
256
|
-
moveTo(parent: LoroTreeNode): void;
|
|
274
|
+
moveTo(parent: LoroTreeNode<T>): void;
|
|
257
275
|
parent(): LoroTreeNode | undefined;
|
|
258
|
-
children(): Array<LoroTreeNode
|
|
276
|
+
children(): Array<LoroTreeNode<T>>;
|
|
259
277
|
}
|
|
260
278
|
}
|