loro-crdt 0.16.4-alpha.0 β†’ 0.16.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.
package/README.md CHANGED
@@ -1,8 +1,141 @@
1
- # loro-crdt
1
+ <p align="center">
2
+ <a href="https://loro.dev">
3
+ <picture>
4
+ <img src="./docs/Loro.svg" width="200"/>
5
+ </picture>
6
+ </a>
7
+ </p>
8
+ <h1 align="center">
9
+ <a href="https://loro.dev" alt="loro-site">Loro</a>
10
+ </h1>
11
+ <p align="center">
12
+ <b>Reimagine state management with CRDTs 🦜</b><br/>
13
+ Make your app state synchronized and collaborative effortlessly.
14
+ </p>
15
+ <p align="center">
16
+ <a href="https://trendshift.io/repositories/4964" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4964" alt="loro-dev%2Floro | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
17
+ </p>
18
+ <p align="center">
19
+ <a href="https://loro.dev/docs">
20
+ <b>Documentation</b>
21
+ </a>
22
+ |
23
+ <a href="https://loro.dev/docs/tutorial/get_started">
24
+ <b>Getting Started</b>
25
+ </a>
26
+ |
27
+ <a href="https://docs.rs/loro">
28
+ <b>Rust Doc</b>
29
+ </a>
30
+ </p>
31
+ <p align="center">
32
+ <a aria-label="X" href="https://x.com/loro_dev" target="_blank">
33
+ <img alt="" src="https://img.shields.io/badge/Twitter-black?style=for-the-badge&logo=Twitter">
34
+ </a>
35
+ <a aria-label="Discord-Link" href="https://discord.gg/tUsBSVfqzf" target="_blank">
36
+ <img alt="" src="https://img.shields.io/badge/Discord-black?style=for-the-badge&logo=discord">
37
+ </a>
38
+ </p>
2
39
 
3
- Loro CRDTs is a high-performance CRDT framework.
4
40
 
5
- It makes your app state synchronized, collaborative and maintainable effortlessly.
41
+ https://github.com/loro-dev/loro/assets/18425020/fe246c47-a120-44b3-91d4-1e7232a5b4ac
6
42
 
7
- Learn more at https://loro.dev
8
43
 
44
+ > ⚠️ **Notice**: The current API and encoding schema of Loro are **experimental** and **subject to change**. You should not use it in production.
45
+
46
+ Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) library that makes building [local-first apps][local-first] easier. It is currently available for JavaScript (via WASM) and Rust developers.
47
+
48
+ Explore our vision in our blog: [**✨ Reimagine State Management with CRDTs**](https://loro.dev/blog/loro-now-open-source).
49
+
50
+ # Features
51
+
52
+ **Basic Features Provided by CRDTs**
53
+
54
+ - P2P Synchronization
55
+ - Automatic Merging
56
+ - Local Availability
57
+ - Scalability
58
+ - Delta Updates
59
+
60
+ **Supported CRDT Algorithms**
61
+
62
+ - πŸ“ Text Editing with [Fugue]
63
+ - πŸ“™ [Peritext-like Rich Text CRDT](https://loro.dev/blog/loro-richtext)
64
+ - 🌲 [Moveable Tree](https://loro.dev/docs/tutorial/tree)
65
+ - πŸš— [Moveable List](https://loro.dev/docs/tutorial/list)
66
+ - πŸ—ΊοΈ [Last-Write-Wins Map](https://loro.dev/docs/tutorial/map)
67
+ - πŸ”„ [Replayable Event Graph](https://loro.dev/docs/advanced/replayable_event_graph)
68
+
69
+ **Advanced Features in Loro**
70
+
71
+ - πŸ“– Preserve Editing History in a [Replayable Event Graph](https://loro.dev/docs/advanced/replayable_event_graph)
72
+ - ⏱️ Fast [Time Travel](https://loro.dev/docs/tutorial/time_travel) Through History
73
+
74
+ https://github.com/loro-dev/loro/assets/18425020/ec2d20a3-3d8c-4483-a601-b200243c9792
75
+
76
+ # Example
77
+
78
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/loro-basic-test?file=test%2Floro-sync.test.ts)
79
+
80
+ ```ts
81
+ import { expect, test } from 'vitest';
82
+ import { Loro, LoroList } from 'loro-crdt';
83
+
84
+ /**
85
+ * Demonstrates synchronization of two documents with two rounds of exchanges.
86
+ */
87
+ // Initialize document A
88
+ const docA = new Loro();
89
+ const listA: LoroList = docA.getList('list');
90
+ listA.insert(0, 'A');
91
+ listA.insert(1, 'B');
92
+ listA.insert(2, 'C');
93
+
94
+ // Export the state of document A as a byte array
95
+ const bytes: Uint8Array = docA.exportFrom();
96
+
97
+ // Simulate sending `bytes` across the network to another peer, B
98
+ const docB = new Loro();
99
+ // Peer B imports the updates from A
100
+ docB.import(bytes);
101
+
102
+ // Verify that B's state matches A's state
103
+ expect(docB.toJSON()).toStrictEqual({
104
+ list: ['A', 'B', 'C'],
105
+ });
106
+
107
+ // Get the current operation log version of document B
108
+ const version = docB.oplogVersion();
109
+
110
+ // Simulate editing at B: delete item 'B'
111
+ const listB: LoroList = docB.getList('list');
112
+ listB.delete(1, 1);
113
+
114
+ // Export the updates from B since the last synchronization point
115
+ const bytesB: Uint8Array = docB.exportFrom(version);
116
+
117
+ // Simulate sending `bytesB` back across the network to A
118
+ // A imports the updates from B
119
+ docA.import(bytesB);
120
+
121
+ // Verify that the list at A now matches the list at B after merging
122
+ expect(docA.toJSON()).toStrictEqual({
123
+ list: ['A', 'C'],
124
+ });
125
+ ```
126
+
127
+ # Credits
128
+
129
+ Loro draws inspiration from the innovative work of the following projects and individuals:
130
+
131
+ - [Ink & Switch](https://inkandswitch.com/): The principles of Local-first Software have greatly influenced this project. The [Peritext](https://www.inkandswitch.com/peritext/) project has also shaped our approach to rich text CRDTs.
132
+ - [Diamond-types](https://github.com/josephg/diamond-types): The [Replayable Event Graph (REG)](https://loro.dev/docs/advanced/replayable_event_graph) algorithm from @josephg has been adapted to reduce the computation and space usage of CRDTs.
133
+ - [Automerge](https://github.com/automerge/automerge): Their use of columnar encoding for CRDTs has informed our strategies for efficient data encoding.
134
+ - [Yjs](https://github.com/yjs/yjs): We have incorporated a similar algorithm for effectively merging collaborative editing operations, thanks to their pioneering works.
135
+ - [Matthew Weidner](https://mattweidner.com/): His work on the [Fugue](https://arxiv.org/abs/2305.00583) algorithm has been invaluable, enhancing our text editing capabilities.
136
+ - [Martin Kleppmann](https://martin.kleppmann.com/): His work on CRDTs has significantly influenced our comprehension of the field.
137
+
138
+
139
+ [local-first]: https://www.inkandswitch.com/local-first/
140
+ [Fugue]: https://arxiv.org/abs/2305.00583
141
+ [Peritext]: https://www.inkandswitch.com/peritext/
package/dist/loro.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Value, AwarenessWasm, PeerID as PeerID$1, Container, ContainerID, TreeID, OpId, Delta, LoroText, LoroMap, LoroTree, LoroList } from 'loro-wasm';
1
+ import { Value, AwarenessWasm, PeerID as PeerID$1, Container, ContainerID, TreeID, OpId, Delta, LoroText, LoroMap, LoroTree, LoroList, LoroCounter } from 'loro-wasm';
2
2
  export * from 'loro-wasm';
3
3
  export { Loro } from 'loro-wasm';
4
4
 
@@ -113,7 +113,11 @@ type TreeDiff = {
113
113
  type: "tree";
114
114
  diff: TreeDiffItem[];
115
115
  };
116
- type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;
116
+ type CounterDiff = {
117
+ type: "counter";
118
+ increment: number;
119
+ };
120
+ type Diff = ListDiff | TextDiff | MapDiff | TreeDiff | CounterDiff;
117
121
  interface Listener {
118
122
  (event: LoroEventBatch): void;
119
123
  }
@@ -153,7 +157,7 @@ declare function isContainer(value: any): value is Container;
153
157
  * getType({}); // "Json"
154
158
  * ```
155
159
  */
156
- 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";
160
+ 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" : T extends LoroCounter ? "Counter" : "Json";
157
161
  declare module "loro-wasm" {
158
162
  interface Loro {
159
163
  subscribe(listener: Listener): number;
@@ -577,4 +581,4 @@ declare module "loro-wasm" {
577
581
  }
578
582
  type NonNullableType<T> = Exclude<T, null | undefined>;
579
583
 
580
- export { Awareness, Diff, Frontiers, ListDiff, LoroEvent, LoroEventBatch, MapDiff, Path, TextDiff, TreeDiff, TreeDiffItem, getType, isContainer, isContainerId };
584
+ export { Awareness, CounterDiff, Diff, Frontiers, ListDiff, LoroEvent, LoroEventBatch, MapDiff, Path, TextDiff, TreeDiff, TreeDiffItem, getType, isContainer, isContainerId };
package/dist/loro.js CHANGED
@@ -84,7 +84,7 @@ class Awareness {
84
84
  }
85
85
  }
86
86
 
87
- const CONTAINER_TYPES = ["Map", "Text", "List", "Tree", "MovableList"];
87
+ const CONTAINER_TYPES = ["Map", "Text", "List", "Tree", "MovableList", "Counter"];
88
88
  function isContainerId(s) {
89
89
  return s.startsWith("cid:");
90
90
  }
package/dist/loro.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"loro.js","sources":["../src/awareness.ts","../src/index.ts"],"sourcesContent":["import { AwarenessWasm, PeerID, Value } from \"loro-wasm\";\n\nexport type AwarenessListener = (\n arg: { updated: PeerID[]; added: PeerID[]; removed: PeerID[] },\n origin: \"local\" | \"timeout\" | \"remote\" | string,\n) => void;\n\n/**\n * Awareness is a structure that allows to track the ephemeral state of the peers.\n *\n * If we don't receive a state update from a peer within the timeout, we will remove their state.\n * The timeout is in milliseconds. This can be used to handle the off-line state of a peer.\n */\nexport class Awareness<T extends Value = Value> {\n inner: AwarenessWasm<T>;\n private peer: PeerID;\n private timer: number | undefined;\n private timeout: number;\n private listeners: Set<AwarenessListener> = new Set();\n constructor(peer: PeerID, timeout: number = 30000) {\n this.inner = new AwarenessWasm(peer, timeout);\n this.peer = peer;\n this.timeout = timeout;\n }\n\n apply(bytes: Uint8Array, origin = \"remote\") {\n const { updated, added } = this.inner.apply(bytes);\n this.listeners.forEach((listener) => {\n listener({ updated, added, removed: [] }, origin);\n });\n\n this.startTimerIfNotEmpty();\n }\n\n setLocalState(state: T) {\n const wasEmpty = this.inner.getState(this.peer) == null;\n this.inner.setLocalState(state);\n if (wasEmpty) {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [], added: [this.inner.peer()], removed: [] },\n \"local\",\n );\n });\n } else {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [this.inner.peer()], added: [], removed: [] },\n \"local\",\n );\n });\n }\n\n this.startTimerIfNotEmpty();\n }\n\n getLocalState(): T | undefined {\n return this.inner.getState(this.peer);\n }\n\n getAllStates(): Record<PeerID, T> {\n return this.inner.getAllStates();\n }\n\n encode(peers: PeerID[]): Uint8Array {\n return this.inner.encode(peers);\n }\n\n encodeAll(): Uint8Array {\n return this.inner.encodeAll();\n }\n\n addListener(listener: AwarenessListener) {\n this.listeners.add(listener);\n }\n\n removeListener(listener: AwarenessListener) {\n this.listeners.delete(listener);\n }\n\n peers(): PeerID[] {\n return this.inner.peers();\n }\n\n destroy() {\n clearInterval(this.timer);\n this.listeners.clear();\n }\n\n private startTimerIfNotEmpty() {\n if (this.inner.isEmpty() || this.timer != null) {\n return;\n }\n\n this.timer = setInterval(() => {\n const removed = this.inner.removeOutdated();\n if (removed.length > 0) {\n this.listeners.forEach((listener) => {\n listener({ updated: [], added: [], removed }, \"timeout\");\n });\n }\n if (this.inner.isEmpty()) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n }, this.timeout / 2) as unknown as number;\n }\n}\n","export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n OpId,\n TreeID,\n Value,\n} from \"loro-wasm\";\nexport { Awareness } from \"./awareness\";\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 by - How the event is triggered.\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 /**\n * How the event is triggered.\n *\n * - `local`: The event is triggered by a local transaction.\n * - `import`: The event is triggered by an import operation.\n * - `checkout`: The event is triggered by a checkout operation.\n */\n by: \"local\" | \"import\" | \"checkout\";\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 | {\n target: TreeID;\n action: \"create\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n }\n | { target: TreeID; action: \"delete\" }\n | {\n target: TreeID;\n action: \"move\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n };\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\", \"MovableList\"];\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\n ? \"Text\"\n : T extends LoroMap<any>\n ? \"Map\"\n : T extends LoroTree<any>\n ? \"Tree\"\n : T extends LoroList<any>\n ? \"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 UndoManager {\n /**\n * Set the callback function that is called when an undo/redo step is pushed.\n * The function can return a meta data value that will be attached to the given stack item.\n *\n * @param listener - The callback function.\n */\n setOnPush(listener?: UndoConfig[\"onPush\"]): void;\n /**\n * Set the callback function that is called when an undo/redo step is popped.\n * The function will have a meta data value that was attached to the given stack item when `onPush` was called.\n *\n * @param listener - The callback function.\n */\n setOnPop(listener?: UndoConfig[\"onPop\"]): void;\n }\n\n interface Loro<\n T extends Record<string, Container> = Record<string, Container>,\n > {\n /**\n * Get a LoroMap by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * ```\n */\n getMap<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMap ? T[Key] : LoroMap;\n /**\n * Get a LoroList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroList ? T[Key] : LoroList;\n /**\n * Get a LoroMovableList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getMovableList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;\n /**\n * Get a LoroTree by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * ```\n */\n getTree<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroTree ? T[Key] : LoroTree;\n getText(key: string | ContainerID): LoroText;\n }\n\n interface LoroList<T = unknown> {\n new (): LoroList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroList<T>;\n }\n\n interface LoroMovableList<T = unknown> {\n new (): LoroMovableList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMoableList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroMovableList<T>;\n /**\n * Set the value at the given position.\n *\n * It's different from `delete` + `insert` that it will replace the value at the position.\n *\n * For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.\n * If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.\n *\n * But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations\n * and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.set(1, \"bar\");\n * console.log(list.value); // [100, \"bar\", true];\n * ```\n */\n set<V extends T>(pos: number, value: Exclude<V, Container>): void;\n /**\n * Set a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.setContainer(0, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [\"Hello\"];\n * ```\n */\n setContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n }\n\n interface LoroMap<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroMap<T>;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object returned is a new js object each time because it need to cross\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n getOrCreateContainer<C extends Container>(key: string, child: C): C;\n /**\n * Set the key with a container.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const text = map.setContainer(\"text\", new LoroText());\n * const list = map.setContainer(\"list\", new LoroText());\n * ```\n */\n setContainer<C extends Container, Key extends keyof T>(\n key: Key,\n child: C,\n ): NonNullableType<T[Key]> extends C ? NonNullableType<T[Key]> : C;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object/value returned is a new js object/value each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n get<Key extends keyof T>(key: Key): T[Key];\n /**\n * Set the key with the value.\n *\n * If the value of the key is exist, the old value will be updated.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * map.set(\"foo\", \"baz\");\n * ```\n */\n set<Key extends keyof T, V extends T[Key]>(\n key: Key,\n value: Exclude<V, Container>,\n ): void;\n delete(key: string): void;\n subscribe(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(listener: Listener): number;\n }\n\n interface LoroTree<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroTree<T>;\n /**\n * Create a new tree node as the child of parent and return a `LoroTreeNode` instance.\n * If the parent is undefined, the tree node will be a root node.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * const root = tree.createNode();\n * const node = tree.createNode(undefined, 0);\n *\n * // undefined\n * // / \\\n * // node root\n * ```\n */\n createNode(parent?: TreeID, index?: number): LoroTreeNode<T>;\n move(target: TreeID, parent?: TreeID, index?: number): void;\n delete(target: TreeID): void;\n has(target: TreeID): boolean;\n /**\n * Get LoroTreeNode by the TreeID.\n */\n getNodeByID(target: TreeID): LoroTreeNode<T>;\n subscribe(listener: Listener): number;\n }\n\n interface LoroTreeNode<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n /**\n * Get the associated metadata map container of a tree node.\n */\n readonly data: LoroMap<T>;\n /** \n * Create a new node as the child of the current node and\n * return an instance of `LoroTreeNode`.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```typescript\n * import { Loro } from \"loro-crdt\";\n *\n * let doc = new Loro();\n * let tree = doc.getTree(\"tree\");\n * let root = tree.createNode();\n * let node = root.createNode();\n * let node2 = root.createNode(0);\n * // root\n * // / \\\n * // node2 node\n * ```\n */ \n createNode(index?: number): LoroTreeNode<T>;\n move(parent?: LoroTreeNode<T>, index?: number): void;\n parent(): LoroTreeNode<T> | undefined;\n /**\n * Get the children of this node.\n *\n * The objects returned are new js objects each time because they need to cross\n * the WASM boundary.\n */\n children(): Array<LoroTreeNode<T>>;\n }\n\n interface AwarenessWasm<T extends Value = Value> {\n getState(peer: PeerID): T | undefined;\n getTimestamp(peer: PeerID): number | undefined;\n getAllStates(): Record<PeerID, T>;\n setLocalState(value: T): void;\n removeOutdated(): PeerID[];\n }\n}\n\ntype NonNullableType<T> = Exclude<T, null | undefined>;\n"],"names":["AwarenessWasm"],"mappings":";;;;AAaO,MAAM,SAAmC,CAAA;AAAA,EAC9C,KAAA,CAAA;AAAA,EACQ,IAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EACA,OAAA,CAAA;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AY,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,KASe,EAAA;AACf,EAAI,IAAA,WAAA,CAAY,KAAK,CAAG,EAAA;AACtB,IAAA,OAAO,MAAM,IAAK,EAAA,CAAA;AAAA,GACpB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"loro.js","sources":["../src/awareness.ts","../src/index.ts"],"sourcesContent":["import { AwarenessWasm, PeerID, Value } from \"loro-wasm\";\n\nexport type AwarenessListener = (\n arg: { updated: PeerID[]; added: PeerID[]; removed: PeerID[] },\n origin: \"local\" | \"timeout\" | \"remote\" | string,\n) => void;\n\n/**\n * Awareness is a structure that allows to track the ephemeral state of the peers.\n *\n * If we don't receive a state update from a peer within the timeout, we will remove their state.\n * The timeout is in milliseconds. This can be used to handle the off-line state of a peer.\n */\nexport class Awareness<T extends Value = Value> {\n inner: AwarenessWasm<T>;\n private peer: PeerID;\n private timer: number | undefined;\n private timeout: number;\n private listeners: Set<AwarenessListener> = new Set();\n constructor(peer: PeerID, timeout: number = 30000) {\n this.inner = new AwarenessWasm(peer, timeout);\n this.peer = peer;\n this.timeout = timeout;\n }\n\n apply(bytes: Uint8Array, origin = \"remote\") {\n const { updated, added } = this.inner.apply(bytes);\n this.listeners.forEach((listener) => {\n listener({ updated, added, removed: [] }, origin);\n });\n\n this.startTimerIfNotEmpty();\n }\n\n setLocalState(state: T) {\n const wasEmpty = this.inner.getState(this.peer) == null;\n this.inner.setLocalState(state);\n if (wasEmpty) {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [], added: [this.inner.peer()], removed: [] },\n \"local\",\n );\n });\n } else {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [this.inner.peer()], added: [], removed: [] },\n \"local\",\n );\n });\n }\n\n this.startTimerIfNotEmpty();\n }\n\n getLocalState(): T | undefined {\n return this.inner.getState(this.peer);\n }\n\n getAllStates(): Record<PeerID, T> {\n return this.inner.getAllStates();\n }\n\n encode(peers: PeerID[]): Uint8Array {\n return this.inner.encode(peers);\n }\n\n encodeAll(): Uint8Array {\n return this.inner.encodeAll();\n }\n\n addListener(listener: AwarenessListener) {\n this.listeners.add(listener);\n }\n\n removeListener(listener: AwarenessListener) {\n this.listeners.delete(listener);\n }\n\n peers(): PeerID[] {\n return this.inner.peers();\n }\n\n destroy() {\n clearInterval(this.timer);\n this.listeners.clear();\n }\n\n private startTimerIfNotEmpty() {\n if (this.inner.isEmpty() || this.timer != null) {\n return;\n }\n\n this.timer = setInterval(() => {\n const removed = this.inner.removeOutdated();\n if (removed.length > 0) {\n this.listeners.forEach((listener) => {\n listener({ updated: [], added: [], removed }, \"timeout\");\n });\n }\n if (this.inner.isEmpty()) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n }, this.timeout / 2) as unknown as number;\n }\n}\n","export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n LoroCounter,\n OpId,\n TreeID,\n Value,\n} from \"loro-wasm\";\nexport { Awareness } from \"./awareness\";\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 by - How the event is triggered.\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 /**\n * How the event is triggered.\n *\n * - `local`: The event is triggered by a local transaction.\n * - `import`: The event is triggered by an import operation.\n * - `checkout`: The event is triggered by a checkout operation.\n */\n by: \"local\" | \"import\" | \"checkout\";\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 | {\n target: TreeID;\n action: \"create\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n }\n | { target: TreeID; action: \"delete\" }\n | {\n target: TreeID;\n action: \"move\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n };\n\nexport type TreeDiff = {\n type: \"tree\";\n diff: TreeDiffItem[];\n};\n\nexport type CounterDiff = {\n type: \"counter\";\n increment: number;\n}\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff | CounterDiff;\n\ninterface Listener {\n (event: LoroEventBatch): void;\n}\n\nconst CONTAINER_TYPES = [\"Map\", \"Text\", \"List\", \"Tree\", \"MovableList\", \"Counter\"];\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\n ? \"Text\"\n : T extends LoroMap<any>\n ? \"Map\"\n : T extends LoroTree<any>\n ? \"Tree\"\n : T extends LoroList<any>\n ? \"List\"\n :T extends LoroCounter?\"Counter\"\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 UndoManager {\n /**\n * Set the callback function that is called when an undo/redo step is pushed.\n * The function can return a meta data value that will be attached to the given stack item.\n *\n * @param listener - The callback function.\n */\n setOnPush(listener?: UndoConfig[\"onPush\"]): void;\n /**\n * Set the callback function that is called when an undo/redo step is popped.\n * The function will have a meta data value that was attached to the given stack item when `onPush` was called.\n *\n * @param listener - The callback function.\n */\n setOnPop(listener?: UndoConfig[\"onPop\"]): void;\n }\n\n interface Loro<\n T extends Record<string, Container> = Record<string, Container>,\n > {\n /**\n * Get a LoroMap by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * ```\n */\n getMap<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMap ? T[Key] : LoroMap;\n /**\n * Get a LoroList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroList ? T[Key] : LoroList;\n /**\n * Get a LoroMovableList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getMovableList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;\n /**\n * Get a LoroTree by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * ```\n */\n getTree<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroTree ? T[Key] : LoroTree;\n getText(key: string | ContainerID): LoroText;\n }\n\n interface LoroList<T = unknown> {\n new (): LoroList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroList<T>;\n }\n\n interface LoroMovableList<T = unknown> {\n new (): LoroMovableList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMoableList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroMovableList<T>;\n /**\n * Set the value at the given position.\n *\n * It's different from `delete` + `insert` that it will replace the value at the position.\n *\n * For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.\n * If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.\n *\n * But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations\n * and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.set(1, \"bar\");\n * console.log(list.value); // [100, \"bar\", true];\n * ```\n */\n set<V extends T>(pos: number, value: Exclude<V, Container>): void;\n /**\n * Set a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.setContainer(0, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [\"Hello\"];\n * ```\n */\n setContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n }\n\n interface LoroMap<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroMap<T>;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object returned is a new js object each time because it need to cross\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n getOrCreateContainer<C extends Container>(key: string, child: C): C;\n /**\n * Set the key with a container.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const text = map.setContainer(\"text\", new LoroText());\n * const list = map.setContainer(\"list\", new LoroText());\n * ```\n */\n setContainer<C extends Container, Key extends keyof T>(\n key: Key,\n child: C,\n ): NonNullableType<T[Key]> extends C ? NonNullableType<T[Key]> : C;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object/value returned is a new js object/value each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n get<Key extends keyof T>(key: Key): T[Key];\n /**\n * Set the key with the value.\n *\n * If the value of the key is exist, the old value will be updated.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * map.set(\"foo\", \"baz\");\n * ```\n */\n set<Key extends keyof T, V extends T[Key]>(\n key: Key,\n value: Exclude<V, Container>,\n ): void;\n delete(key: string): void;\n subscribe(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(listener: Listener): number;\n }\n\n interface LoroTree<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroTree<T>;\n /**\n * Create a new tree node as the child of parent and return a `LoroTreeNode` instance.\n * If the parent is undefined, the tree node will be a root node.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * const root = tree.createNode();\n * const node = tree.createNode(undefined, 0);\n *\n * // undefined\n * // / \\\n * // node root\n * ```\n */\n createNode(parent?: TreeID, index?: number): LoroTreeNode<T>;\n move(target: TreeID, parent?: TreeID, index?: number): void;\n delete(target: TreeID): void;\n has(target: TreeID): boolean;\n /**\n * Get LoroTreeNode by the TreeID.\n */\n getNodeByID(target: TreeID): LoroTreeNode<T>;\n subscribe(listener: Listener): number;\n }\n\n interface LoroTreeNode<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n /**\n * Get the associated metadata map container of a tree node.\n */\n readonly data: LoroMap<T>;\n /** \n * Create a new node as the child of the current node and\n * return an instance of `LoroTreeNode`.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```typescript\n * import { Loro } from \"loro-crdt\";\n *\n * let doc = new Loro();\n * let tree = doc.getTree(\"tree\");\n * let root = tree.createNode();\n * let node = root.createNode();\n * let node2 = root.createNode(0);\n * // root\n * // / \\\n * // node2 node\n * ```\n */ \n createNode(index?: number): LoroTreeNode<T>;\n move(parent?: LoroTreeNode<T>, index?: number): void;\n parent(): LoroTreeNode<T> | undefined;\n /**\n * Get the children of this node.\n *\n * The objects returned are new js objects each time because they need to cross\n * the WASM boundary.\n */\n children(): Array<LoroTreeNode<T>>;\n }\n\n interface AwarenessWasm<T extends Value = Value> {\n getState(peer: PeerID): T | undefined;\n getTimestamp(peer: PeerID): number | undefined;\n getAllStates(): Record<PeerID, T>;\n setLocalState(value: T): void;\n removeOutdated(): PeerID[];\n }\n}\n\ntype NonNullableType<T> = Exclude<T, null | undefined>;\n"],"names":["AwarenessWasm"],"mappings":";;;;AAaO,MAAM,SAAmC,CAAA;AAAA,EAC9C,KAAA,CAAA;AAAA,EACQ,IAAA,CAAA;AAAA,E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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,KAUe,EAAA;AACf,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
@@ -84,7 +84,7 @@ class Awareness {
84
84
  }
85
85
  }
86
86
 
87
- const CONTAINER_TYPES = ["Map", "Text", "List", "Tree", "MovableList"];
87
+ const CONTAINER_TYPES = ["Map", "Text", "List", "Tree", "MovableList", "Counter"];
88
88
  function isContainerId(s) {
89
89
  return s.startsWith("cid:");
90
90
  }
package/dist/loro.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"loro.mjs","sources":["../src/awareness.ts","../src/index.ts"],"sourcesContent":["import { AwarenessWasm, PeerID, Value } from \"loro-wasm\";\n\nexport type AwarenessListener = (\n arg: { updated: PeerID[]; added: PeerID[]; removed: PeerID[] },\n origin: \"local\" | \"timeout\" | \"remote\" | string,\n) => void;\n\n/**\n * Awareness is a structure that allows to track the ephemeral state of the peers.\n *\n * If we don't receive a state update from a peer within the timeout, we will remove their state.\n * The timeout is in milliseconds. This can be used to handle the off-line state of a peer.\n */\nexport class Awareness<T extends Value = Value> {\n inner: AwarenessWasm<T>;\n private peer: PeerID;\n private timer: number | undefined;\n private timeout: number;\n private listeners: Set<AwarenessListener> = new Set();\n constructor(peer: PeerID, timeout: number = 30000) {\n this.inner = new AwarenessWasm(peer, timeout);\n this.peer = peer;\n this.timeout = timeout;\n }\n\n apply(bytes: Uint8Array, origin = \"remote\") {\n const { updated, added } = this.inner.apply(bytes);\n this.listeners.forEach((listener) => {\n listener({ updated, added, removed: [] }, origin);\n });\n\n this.startTimerIfNotEmpty();\n }\n\n setLocalState(state: T) {\n const wasEmpty = this.inner.getState(this.peer) == null;\n this.inner.setLocalState(state);\n if (wasEmpty) {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [], added: [this.inner.peer()], removed: [] },\n \"local\",\n );\n });\n } else {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [this.inner.peer()], added: [], removed: [] },\n \"local\",\n );\n });\n }\n\n this.startTimerIfNotEmpty();\n }\n\n getLocalState(): T | undefined {\n return this.inner.getState(this.peer);\n }\n\n getAllStates(): Record<PeerID, T> {\n return this.inner.getAllStates();\n }\n\n encode(peers: PeerID[]): Uint8Array {\n return this.inner.encode(peers);\n }\n\n encodeAll(): Uint8Array {\n return this.inner.encodeAll();\n }\n\n addListener(listener: AwarenessListener) {\n this.listeners.add(listener);\n }\n\n removeListener(listener: AwarenessListener) {\n this.listeners.delete(listener);\n }\n\n peers(): PeerID[] {\n return this.inner.peers();\n }\n\n destroy() {\n clearInterval(this.timer);\n this.listeners.clear();\n }\n\n private startTimerIfNotEmpty() {\n if (this.inner.isEmpty() || this.timer != null) {\n return;\n }\n\n this.timer = setInterval(() => {\n const removed = this.inner.removeOutdated();\n if (removed.length > 0) {\n this.listeners.forEach((listener) => {\n listener({ updated: [], added: [], removed }, \"timeout\");\n });\n }\n if (this.inner.isEmpty()) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n }, this.timeout / 2) as unknown as number;\n }\n}\n","export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n OpId,\n TreeID,\n Value,\n} from \"loro-wasm\";\nexport { Awareness } from \"./awareness\";\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 by - How the event is triggered.\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 /**\n * How the event is triggered.\n *\n * - `local`: The event is triggered by a local transaction.\n * - `import`: The event is triggered by an import operation.\n * - `checkout`: The event is triggered by a checkout operation.\n */\n by: \"local\" | \"import\" | \"checkout\";\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 | {\n target: TreeID;\n action: \"create\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n }\n | { target: TreeID; action: \"delete\" }\n | {\n target: TreeID;\n action: \"move\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n };\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\", \"MovableList\"];\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\n ? \"Text\"\n : T extends LoroMap<any>\n ? \"Map\"\n : T extends LoroTree<any>\n ? \"Tree\"\n : T extends LoroList<any>\n ? \"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 UndoManager {\n /**\n * Set the callback function that is called when an undo/redo step is pushed.\n * The function can return a meta data value that will be attached to the given stack item.\n *\n * @param listener - The callback function.\n */\n setOnPush(listener?: UndoConfig[\"onPush\"]): void;\n /**\n * Set the callback function that is called when an undo/redo step is popped.\n * The function will have a meta data value that was attached to the given stack item when `onPush` was called.\n *\n * @param listener - The callback function.\n */\n setOnPop(listener?: UndoConfig[\"onPop\"]): void;\n }\n\n interface Loro<\n T extends Record<string, Container> = Record<string, Container>,\n > {\n /**\n * Get a LoroMap by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * ```\n */\n getMap<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMap ? T[Key] : LoroMap;\n /**\n * Get a LoroList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroList ? T[Key] : LoroList;\n /**\n * Get a LoroMovableList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getMovableList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;\n /**\n * Get a LoroTree by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * ```\n */\n getTree<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroTree ? T[Key] : LoroTree;\n getText(key: string | ContainerID): LoroText;\n }\n\n interface LoroList<T = unknown> {\n new (): LoroList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroList<T>;\n }\n\n interface LoroMovableList<T = unknown> {\n new (): LoroMovableList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMoableList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroMovableList<T>;\n /**\n * Set the value at the given position.\n *\n * It's different from `delete` + `insert` that it will replace the value at the position.\n *\n * For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.\n * If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.\n *\n * But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations\n * and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.set(1, \"bar\");\n * console.log(list.value); // [100, \"bar\", true];\n * ```\n */\n set<V extends T>(pos: number, value: Exclude<V, Container>): void;\n /**\n * Set a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.setContainer(0, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [\"Hello\"];\n * ```\n */\n setContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n }\n\n interface LoroMap<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroMap<T>;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object returned is a new js object each time because it need to cross\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n getOrCreateContainer<C extends Container>(key: string, child: C): C;\n /**\n * Set the key with a container.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const text = map.setContainer(\"text\", new LoroText());\n * const list = map.setContainer(\"list\", new LoroText());\n * ```\n */\n setContainer<C extends Container, Key extends keyof T>(\n key: Key,\n child: C,\n ): NonNullableType<T[Key]> extends C ? NonNullableType<T[Key]> : C;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object/value returned is a new js object/value each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n get<Key extends keyof T>(key: Key): T[Key];\n /**\n * Set the key with the value.\n *\n * If the value of the key is exist, the old value will be updated.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * map.set(\"foo\", \"baz\");\n * ```\n */\n set<Key extends keyof T, V extends T[Key]>(\n key: Key,\n value: Exclude<V, Container>,\n ): void;\n delete(key: string): void;\n subscribe(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(listener: Listener): number;\n }\n\n interface LoroTree<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroTree<T>;\n /**\n * Create a new tree node as the child of parent and return a `LoroTreeNode` instance.\n * If the parent is undefined, the tree node will be a root node.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * const root = tree.createNode();\n * const node = tree.createNode(undefined, 0);\n *\n * // undefined\n * // / \\\n * // node root\n * ```\n */\n createNode(parent?: TreeID, index?: number): LoroTreeNode<T>;\n move(target: TreeID, parent?: TreeID, index?: number): void;\n delete(target: TreeID): void;\n has(target: TreeID): boolean;\n /**\n * Get LoroTreeNode by the TreeID.\n */\n getNodeByID(target: TreeID): LoroTreeNode<T>;\n subscribe(listener: Listener): number;\n }\n\n interface LoroTreeNode<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n /**\n * Get the associated metadata map container of a tree node.\n */\n readonly data: LoroMap<T>;\n /** \n * Create a new node as the child of the current node and\n * return an instance of `LoroTreeNode`.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```typescript\n * import { Loro } from \"loro-crdt\";\n *\n * let doc = new Loro();\n * let tree = doc.getTree(\"tree\");\n * let root = tree.createNode();\n * let node = root.createNode();\n * let node2 = root.createNode(0);\n * // root\n * // / \\\n * // node2 node\n * ```\n */ \n createNode(index?: number): LoroTreeNode<T>;\n move(parent?: LoroTreeNode<T>, index?: number): void;\n parent(): LoroTreeNode<T> | undefined;\n /**\n * Get the children of this node.\n *\n * The objects returned are new js objects each time because they need to cross\n * the WASM boundary.\n */\n children(): Array<LoroTreeNode<T>>;\n }\n\n interface AwarenessWasm<T extends Value = Value> {\n getState(peer: PeerID): T | undefined;\n getTimestamp(peer: PeerID): number | undefined;\n getAllStates(): Record<PeerID, T>;\n setLocalState(value: T): void;\n removeOutdated(): PeerID[];\n }\n}\n\ntype NonNullableType<T> = Exclude<T, null | undefined>;\n"],"names":[],"mappings":";;;;AAaO,MAAM,SAAmC,CAAA;AAAA,EAC9C,KAAA,CAAA;AAAA,EACQ,IAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EACA,OAAA,CAAA;AAAA,EACA,SAAA,uBAAwC,GAAI,EAAA,CAAA;AAAA,EACpD,WAAA,CAAY,IAAc,EAAA,OAAA,GAAkB,GAAO,EAAA;AACjD,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAI,aAAc,CAAA,IAAA,EAAM,OAAO,CAAA,CAAA;AAC5C,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AAAA,GACjB;AAAA,EAEA,KAAA,CAAM,KAAmB,EAAA,MAAA,GAAS,QAAU,EAAA;AAC1C,IAAA,MAAM,EAAE,OAAS,EAAA,KAAA,KAAU,IAAK,CAAA,KAAA,CAAM,MAAM,KAAK,CAAA,CAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,OAAQ,CAAA,CAAC,QAAa,KAAA;AACnC,MAAA,QAAA,CAAS,EAAE,OAAS,EAAA,KAAA,EAAO,SAAS,EAAC,IAAK,MAAM,CAAA,CAAA;AAAA,KACjD,CAAA,CAAA;AAED,IAAA,IAAA,CAAK,oBAAqB,EAAA,CAAA;AAAA,GAC5B;AAAA,EAEA,cAAc,KAAU,EAAA;AACtB,IAAA,MAAM,WAAW,IAAK,CAAA,KAAA,CAAM,QAAS,CAAA,IAAA,CAAK,IAAI,CAAK,IAAA,IAAA,CAAA;AACnD,IAAK,IAAA,CAAA,KAAA,CAAM,cAAc,KAAK,CAAA,CAAA;AAC9B,IAAA,IAAI,QAAU,EAAA;AACZ,MAAK,IAAA,CAAA,SAAA,CAAU,OAAQ,CAAA,CAAC,QAAa,KAAA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AAA,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,KASe,EAAA;AACf,EAAI,IAAA,WAAA,CAAY,KAAK,CAAG,EAAA;AACtB,IAAA,OAAO,MAAM,IAAK,EAAA,CAAA;AAAA,GACpB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"loro.mjs","sources":["../src/awareness.ts","../src/index.ts"],"sourcesContent":["import { AwarenessWasm, PeerID, Value } from \"loro-wasm\";\n\nexport type AwarenessListener = (\n arg: { updated: PeerID[]; added: PeerID[]; removed: PeerID[] },\n origin: \"local\" | \"timeout\" | \"remote\" | string,\n) => void;\n\n/**\n * Awareness is a structure that allows to track the ephemeral state of the peers.\n *\n * If we don't receive a state update from a peer within the timeout, we will remove their state.\n * The timeout is in milliseconds. This can be used to handle the off-line state of a peer.\n */\nexport class Awareness<T extends Value = Value> {\n inner: AwarenessWasm<T>;\n private peer: PeerID;\n private timer: number | undefined;\n private timeout: number;\n private listeners: Set<AwarenessListener> = new Set();\n constructor(peer: PeerID, timeout: number = 30000) {\n this.inner = new AwarenessWasm(peer, timeout);\n this.peer = peer;\n this.timeout = timeout;\n }\n\n apply(bytes: Uint8Array, origin = \"remote\") {\n const { updated, added } = this.inner.apply(bytes);\n this.listeners.forEach((listener) => {\n listener({ updated, added, removed: [] }, origin);\n });\n\n this.startTimerIfNotEmpty();\n }\n\n setLocalState(state: T) {\n const wasEmpty = this.inner.getState(this.peer) == null;\n this.inner.setLocalState(state);\n if (wasEmpty) {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [], added: [this.inner.peer()], removed: [] },\n \"local\",\n );\n });\n } else {\n this.listeners.forEach((listener) => {\n listener(\n { updated: [this.inner.peer()], added: [], removed: [] },\n \"local\",\n );\n });\n }\n\n this.startTimerIfNotEmpty();\n }\n\n getLocalState(): T | undefined {\n return this.inner.getState(this.peer);\n }\n\n getAllStates(): Record<PeerID, T> {\n return this.inner.getAllStates();\n }\n\n encode(peers: PeerID[]): Uint8Array {\n return this.inner.encode(peers);\n }\n\n encodeAll(): Uint8Array {\n return this.inner.encodeAll();\n }\n\n addListener(listener: AwarenessListener) {\n this.listeners.add(listener);\n }\n\n removeListener(listener: AwarenessListener) {\n this.listeners.delete(listener);\n }\n\n peers(): PeerID[] {\n return this.inner.peers();\n }\n\n destroy() {\n clearInterval(this.timer);\n this.listeners.clear();\n }\n\n private startTimerIfNotEmpty() {\n if (this.inner.isEmpty() || this.timer != null) {\n return;\n }\n\n this.timer = setInterval(() => {\n const removed = this.inner.removeOutdated();\n if (removed.length > 0) {\n this.listeners.forEach((listener) => {\n listener({ updated: [], added: [], removed }, \"timeout\");\n });\n }\n if (this.inner.isEmpty()) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n }, this.timeout / 2) as unknown as number;\n }\n}\n","export * from \"loro-wasm\";\nimport {\n Container,\n ContainerID,\n Delta,\n Loro,\n LoroList,\n LoroMap,\n LoroText,\n LoroTree,\n LoroCounter,\n OpId,\n TreeID,\n Value,\n} from \"loro-wasm\";\nexport { Awareness } from \"./awareness\";\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 by - How the event is triggered.\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 /**\n * How the event is triggered.\n *\n * - `local`: The event is triggered by a local transaction.\n * - `import`: The event is triggered by an import operation.\n * - `checkout`: The event is triggered by a checkout operation.\n */\n by: \"local\" | \"import\" | \"checkout\";\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 | {\n target: TreeID;\n action: \"create\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n }\n | { target: TreeID; action: \"delete\" }\n | {\n target: TreeID;\n action: \"move\";\n parent: TreeID | undefined;\n index: number;\n position: string;\n };\n\nexport type TreeDiff = {\n type: \"tree\";\n diff: TreeDiffItem[];\n};\n\nexport type CounterDiff = {\n type: \"counter\";\n increment: number;\n}\n\nexport type Diff = ListDiff | TextDiff | MapDiff | TreeDiff | CounterDiff;\n\ninterface Listener {\n (event: LoroEventBatch): void;\n}\n\nconst CONTAINER_TYPES = [\"Map\", \"Text\", \"List\", \"Tree\", \"MovableList\", \"Counter\"];\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\n ? \"Text\"\n : T extends LoroMap<any>\n ? \"Map\"\n : T extends LoroTree<any>\n ? \"Tree\"\n : T extends LoroList<any>\n ? \"List\"\n :T extends LoroCounter?\"Counter\"\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 UndoManager {\n /**\n * Set the callback function that is called when an undo/redo step is pushed.\n * The function can return a meta data value that will be attached to the given stack item.\n *\n * @param listener - The callback function.\n */\n setOnPush(listener?: UndoConfig[\"onPush\"]): void;\n /**\n * Set the callback function that is called when an undo/redo step is popped.\n * The function will have a meta data value that was attached to the given stack item when `onPush` was called.\n *\n * @param listener - The callback function.\n */\n setOnPop(listener?: UndoConfig[\"onPop\"]): void;\n }\n\n interface Loro<\n T extends Record<string, Container> = Record<string, Container>,\n > {\n /**\n * Get a LoroMap by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * ```\n */\n getMap<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMap ? T[Key] : LoroMap;\n /**\n * Get a LoroList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroList ? T[Key] : LoroList;\n /**\n * Get a LoroMovableList by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * ```\n */\n getMovableList<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;\n /**\n * Get a LoroTree by container id\n *\n * The object returned is a new js object each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * ```\n */\n getTree<Key extends keyof T | ContainerID>(\n name: Key,\n ): T[Key] extends LoroTree ? T[Key] : LoroTree;\n getText(key: string | ContainerID): LoroText;\n }\n\n interface LoroList<T = unknown> {\n new (): LoroList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroList<T>;\n }\n\n interface LoroMovableList<T = unknown> {\n new (): LoroMovableList<T>;\n /**\n * Get elements of the list. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * @example\n * ```ts\n * import { Loro, LoroText } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.insertContainer(3, new LoroText());\n * console.log(list.value); // [100, \"foo\", true, LoroText];\n * ```\n */\n toArray(): T[];\n /**\n * Insert a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.insertContainer(1, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [100, \"Hello\"];\n * ```\n */\n insertContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n /**\n * Get the value at the index. If the value is a container, the corresponding handler will be returned.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMoableList(\"list\");\n * list.insert(0, 100);\n * console.log(list.get(0)); // 100\n * console.log(list.get(1)); // undefined\n * ```\n */\n get(index: number): T;\n /**\n * Insert a value at index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * console.log(list.value); // [100, \"foo\", true];\n * ```\n */\n insert<V extends T>(pos: number, value: Exclude<V, Container>): void;\n delete(pos: number, len: number): void;\n push<V extends T>(value: Exclude<V, Container>): void;\n subscribe(listener: Listener): number;\n getAttached(): undefined | LoroMovableList<T>;\n /**\n * Set the value at the given position.\n *\n * It's different from `delete` + `insert` that it will replace the value at the position.\n *\n * For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.\n * If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.\n *\n * But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations\n * and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getList(\"list\");\n * list.insert(0, 100);\n * list.insert(1, \"foo\");\n * list.insert(2, true);\n * list.set(1, \"bar\");\n * console.log(list.value); // [100, \"bar\", true];\n * ```\n */\n set<V extends T>(pos: number, value: Exclude<V, Container>): void;\n /**\n * Set a container at the index.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const list = doc.getMovableList(\"list\");\n * list.insert(0, 100);\n * const text = list.setContainer(0, new LoroText());\n * text.insert(0, \"Hello\");\n * console.log(list.toJSON()); // [\"Hello\"];\n * ```\n */\n setContainer<C extends Container>(\n pos: number,\n child: C,\n ): T extends C ? T : C;\n }\n\n interface LoroMap<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroMap<T>;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object returned is a new js object each time because it need to cross\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n getOrCreateContainer<C extends Container>(key: string, child: C): C;\n /**\n * Set the key with a container.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const text = map.setContainer(\"text\", new LoroText());\n * const list = map.setContainer(\"list\", new LoroText());\n * ```\n */\n setContainer<C extends Container, Key extends keyof T>(\n key: Key,\n child: C,\n ): NonNullableType<T[Key]> extends C ? NonNullableType<T[Key]> : C;\n /**\n * Get the value of the key. If the value is a child container, the corresponding\n * `Container` will be returned.\n *\n * The object/value returned is a new js object/value each time because it need to cross\n * the WASM boundary.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * const bar = map.get(\"foo\");\n * ```\n */\n get<Key extends keyof T>(key: Key): T[Key];\n /**\n * Set the key with the value.\n *\n * If the value of the key is exist, the old value will be updated.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const map = doc.getMap(\"map\");\n * map.set(\"foo\", \"bar\");\n * map.set(\"foo\", \"baz\");\n * ```\n */\n set<Key extends keyof T, V extends T[Key]>(\n key: Key,\n value: Exclude<V, Container>,\n ): void;\n delete(key: string): void;\n subscribe(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(listener: Listener): number;\n }\n\n interface LoroTree<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n new (): LoroTree<T>;\n /**\n * Create a new tree node as the child of parent and return a `LoroTreeNode` instance.\n * If the parent is undefined, the tree node will be a root node.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```ts\n * import { Loro } from \"loro-crdt\";\n *\n * const doc = new Loro();\n * const tree = doc.getTree(\"tree\");\n * const root = tree.createNode();\n * const node = tree.createNode(undefined, 0);\n *\n * // undefined\n * // / \\\n * // node root\n * ```\n */\n createNode(parent?: TreeID, index?: number): LoroTreeNode<T>;\n move(target: TreeID, parent?: TreeID, index?: number): void;\n delete(target: TreeID): void;\n has(target: TreeID): boolean;\n /**\n * Get LoroTreeNode by the TreeID.\n */\n getNodeByID(target: TreeID): LoroTreeNode<T>;\n subscribe(listener: Listener): number;\n }\n\n interface LoroTreeNode<\n T extends Record<string, unknown> = Record<string, unknown>,\n > {\n /**\n * Get the associated metadata map container of a tree node.\n */\n readonly data: LoroMap<T>;\n /** \n * Create a new node as the child of the current node and\n * return an instance of `LoroTreeNode`.\n *\n * If the index is not provided, the new node will be appended to the end.\n *\n * @example\n * ```typescript\n * import { Loro } from \"loro-crdt\";\n *\n * let doc = new Loro();\n * let tree = doc.getTree(\"tree\");\n * let root = tree.createNode();\n * let node = root.createNode();\n * let node2 = root.createNode(0);\n * // root\n * // / \\\n * // node2 node\n * ```\n */ \n createNode(index?: number): LoroTreeNode<T>;\n move(parent?: LoroTreeNode<T>, index?: number): void;\n parent(): LoroTreeNode<T> | undefined;\n /**\n * Get the children of this node.\n *\n * The objects returned are new js objects each time because they need to cross\n * the WASM boundary.\n */\n children(): Array<LoroTreeNode<T>>;\n }\n\n interface AwarenessWasm<T extends Value = Value> {\n getState(peer: PeerID): T | undefined;\n getTimestamp(peer: PeerID): number | undefined;\n getAllStates(): Record<PeerID, T>;\n setLocalState(value: T): void;\n removeOutdated(): PeerID[];\n }\n}\n\ntype NonNullableType<T> = Exclude<T, null | undefined>;\n"],"names":[],"mappings":";;;;AAaO,MAAM,SAAmC,CAAA;AAAA,EAC9C,KAAA,CAAA;AAAA,EACQ,IAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EACA,OAAA,CAAA;AAAA,EACA,SAAA,uBAAwC,GAAI,EAAA,CAAA;AAAA,EACpD,WAAA,CAAY,IAAc,EAAA,OAAA,GAAkB,GAAO,EAAA;AACjD,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAI,aAAc,CAAA,IAAA,EAAM,OAAO,CAAA,CAAA;AAC5C,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AAAA,GACjB;AAAA,EAEA,KAAA,CAAM,KAAmB,EAAA,MAAA,GAAS,QAAU,EAAA;AAC1C,IAAA,MAAM,EAAE,OAAS,EAAA,KAAA,KAAU,IAAK,CAAA,KAAA,CAAM,MAAM,KAAK,CAAA,CAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,OAAQ,CAAA,CAAC,QAAa,KAAA;AACnC,MAAA,QAAA,CAAS,EAAE,OAAS,EAAA,KAAA,EAAO,SAAS,EAAC,IAAK,MAAM,CAAA,CAAA;AAAA,KACjD,CAAA,CAAA;AAED,IAAA,IAAA,CAAK,oBAAqB,EAAA,CAAA;AAAA,GAC5B;AAAA,EAEA,cAAc,KAAU,EAAA;AACtB,IAAA,MAAM,WAAW,IAAK,CAAA,KAAA,CAAM,QAAS,CAAA,IAAA,CAAK,IAAI,CAAK,IAAA,IAAA,CAAA;AACnD,IAAK,IAAA,CAAA,KAAA,CAAM,cAAc,KAAK,CAAA,CAAA;AAC9B,IAAA,IAAI,QAAU,EAAA;AACZ,MAAK,IAAA,CAAA,SAAA,CAAU,OAAQ,CAAA,CAAC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AAA,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,KAUe,EAAA;AACf,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.16.4-alpha.0",
3
+ "version": "0.16.5",
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",
@@ -10,6 +10,10 @@
10
10
  "sync",
11
11
  "p2p"
12
12
  ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/loro-dev/loro.git"
16
+ },
13
17
  "main": "dist/loro.js",
14
18
  "module": "dist/loro.mjs",
15
19
  "typings": "dist/loro.d.ts",
@@ -17,7 +21,7 @@
17
21
  "homepage": "https://loro.dev",
18
22
  "license": "MIT",
19
23
  "dependencies": {
20
- "loro-wasm": "0.16.4-alpha.0"
24
+ "loro-wasm": "0.16.5"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@rollup/plugin-node-resolve": "^15.0.1",