loro-crdt 1.1.0 β†’ 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 70c4942: Add base64 build target
8
+ - 35e7ea5: Add changeCount and opCount methods
9
+
10
+ ## 1.1.1
11
+
12
+ ### Patch Changes
13
+
14
+ - 9abeb81: Add methods to modify VV
15
+ - ee26952: Add isDeleted() method to each container
16
+
3
17
  ## 1.1.0
4
18
 
5
19
  ### Minor Changes
package/README.md CHANGED
@@ -9,8 +9,7 @@
9
9
  <a href="https://loro.dev" alt="loro-site">Loro</a>
10
10
  </h1>
11
11
  <p align="center">
12
- <b>Reimagine state management with CRDTs 🦜</b><br/>
13
- Make your app state synchronized and collaborative effortlessly.
12
+ <b>Make your JSON data collaborative and version-controlled 🦜</b>
14
13
  </p>
15
14
  <p align="center">
16
15
  <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>
@@ -42,11 +41,11 @@
42
41
  ✨ Loro 1.0 is out! Read the <a href="https://loro.dev/blog/v1.0">announcement</a>.
43
42
  </h4>
44
43
 
45
- 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.
44
+ Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) library that makes building [local-first][local-first] and collaborative apps easier. You can now use it in Rust, JS (via WASM), and Swift.
46
45
 
47
46
  # Features
48
47
 
49
- **Basic Features Provided by CRDTs**
48
+ **Features Provided by CRDTs**
50
49
 
51
50
  - P2P Synchronization
52
51
  - Automatic Merging
@@ -61,10 +60,10 @@ Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) libra
61
60
  - 🌲 [Moveable Tree](https://loro.dev/docs/tutorial/tree)
62
61
  - πŸš— [Moveable List](https://loro.dev/docs/tutorial/list)
63
62
  - πŸ—ΊοΈ [Last-Write-Wins Map](https://loro.dev/docs/tutorial/map)
64
- - πŸ”„ [Replayable Event Graph](https://loro.dev/docs/advanced/replayable_event_graph)
65
63
 
66
64
  **Advanced Features in Loro**
67
65
 
66
+ - πŸš€ [Fast Document Loading](https://loro.dev/blog/v1.0)
68
67
  - ⏱️ Fast [Time Travel](https://loro.dev/docs/tutorial/time_travel) Through History
69
68
  - πŸ›οΈ [Version Control with Real-Time Collaboration](https://loro.dev/blog/v1.0#version-control)
70
69
  - πŸ“¦ [Shallow Snapshot](https://loro.dev/docs/advanced/shallow_snapshot) that Works like Git Shallow Clone
@@ -82,9 +81,8 @@ import { expect, test } from 'vitest';
82
81
  import { LoroDoc, LoroList } from 'loro-crdt';
83
82
 
84
83
  test('sync example', () => {
85
- /**
86
- * Demonstrates synchronization of two documents with two rounds of exchanges.
87
- */
84
+ // Sync two docs with two rounds of exchanges
85
+
88
86
  // Initialize document A
89
87
  const docA = new LoroDoc();
90
88
  const listA: LoroList = docA.getList('list');
@@ -92,34 +90,36 @@ test('sync example', () => {
92
90
  listA.insert(1, 'B');
93
91
  listA.insert(2, 'C');
94
92
 
95
- // Export the state of document A as a byte array
93
+ // Export all updates from docA
96
94
  const bytes: Uint8Array = docA.export({ mode: 'update' });
97
95
 
98
96
  // Simulate sending `bytes` across the network to another peer, B
97
+
99
98
  const docB = new LoroDoc();
100
99
  // Peer B imports the updates from A
101
100
  docB.import(bytes);
102
101
 
103
- // Verify that B's state matches A's state
102
+ // B's state matches A's state
104
103
  expect(docB.toJSON()).toStrictEqual({
105
104
  list: ['A', 'B', 'C'],
106
105
  });
107
106
 
108
- // Get the current operation log version of document B
107
+ // Get the current version of docB
109
108
  const version = docB.oplogVersion();
110
109
 
111
110
  // Simulate editing at B: delete item 'B'
112
111
  const listB: LoroList = docB.getList('list');
113
112
  listB.delete(1, 1);
114
113
 
115
- // Export the updates from B since the last synchronization point
114
+ // Export the updates from B since the last sync point
116
115
  const bytesB: Uint8Array = docB.export({ mode: 'update', from: version });
117
116
 
118
117
  // Simulate sending `bytesB` back across the network to A
118
+
119
119
  // A imports the updates from B
120
120
  docA.import(bytesB);
121
121
 
122
- // Verify that the list at A now matches the list at B after merging
122
+ // A has the same state as B
123
123
  expect(docA.toJSON()).toStrictEqual({
124
124
  list: ['A', 'C'],
125
125
  });
@@ -0,0 +1,72 @@
1
+ export * from "./loro_wasm";
2
+ export type * from "./loro_wasm";
3
+ import { AwarenessWasm, PeerID, Container, ContainerID, ContainerType, LoroCounter, LoroDoc, LoroList, LoroMap, LoroText, LoroTree, OpId, Value, AwarenessListener } from "./loro_wasm";
4
+ /**
5
+ * @deprecated Please use LoroDoc
6
+ */
7
+ export declare class Loro extends LoroDoc {
8
+ }
9
+ export declare function isContainerId(s: string): s is ContainerID;
10
+ /** Whether the value is a container.
11
+ *
12
+ * # Example
13
+ *
14
+ * ```ts
15
+ * const doc = new LoroDoc();
16
+ * const map = doc.getMap("map");
17
+ * const list = doc.getList("list");
18
+ * const text = doc.getText("text");
19
+ * isContainer(map); // true
20
+ * isContainer(list); // true
21
+ * isContainer(text); // true
22
+ * isContainer(123); // false
23
+ * isContainer("123"); // false
24
+ * isContainer({}); // false
25
+ * ```
26
+ */
27
+ export declare function isContainer(value: any): value is Container;
28
+ /** Get the type of a value that may be a container.
29
+ *
30
+ * # Example
31
+ *
32
+ * ```ts
33
+ * const doc = new LoroDoc();
34
+ * const map = doc.getMap("map");
35
+ * const list = doc.getList("list");
36
+ * const text = doc.getText("text");
37
+ * getType(map); // "Map"
38
+ * getType(list); // "List"
39
+ * getType(text); // "Text"
40
+ * getType(123); // "Json"
41
+ * getType("123"); // "Json"
42
+ * getType({}); // "Json"
43
+ * ```
44
+ */
45
+ export 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";
46
+ export declare function newContainerID(id: OpId, type: ContainerType): ContainerID;
47
+ export declare function newRootContainerID(name: string, type: ContainerType): ContainerID;
48
+ /**
49
+ * Awareness is a structure that allows to track the ephemeral state of the peers.
50
+ *
51
+ * If we don't receive a state update from a peer within the timeout, we will remove their state.
52
+ * The timeout is in milliseconds. This can be used to handle the off-line state of a peer.
53
+ */
54
+ export declare class Awareness<T extends Value = Value> {
55
+ inner: AwarenessWasm<T>;
56
+ private peer;
57
+ private timer;
58
+ private timeout;
59
+ private listeners;
60
+ constructor(peer: PeerID, timeout?: number);
61
+ apply(bytes: Uint8Array, origin?: string): void;
62
+ setLocalState(state: T): void;
63
+ getLocalState(): T | undefined;
64
+ getAllStates(): Record<PeerID, T>;
65
+ encode(peers: PeerID[]): Uint8Array;
66
+ encodeAll(): Uint8Array;
67
+ addListener(listener: AwarenessListener): void;
68
+ removeListener(listener: AwarenessListener): void;
69
+ peers(): PeerID[];
70
+ destroy(): void;
71
+ private startTimerIfNotEmpty;
72
+ }