Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loro-crdt

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loro-crdt - npm Package Compare versions

Comparing version 0.14.6 to 0.15.0

139

dist/loro.d.ts

@@ -189,2 +189,17 @@ import { Value, AwarenessWasm, PeerID as PeerID$1, Container, ContainerID, TreeID, OpId, Delta, LoroText, LoroMap, LoroTree, LoroList } from 'loro-wasm';

/**
* Get a LoroMovableList by container id
*
* The object returned is a new js object each time because it need to cross
* the WASM boundary.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getList("list");
* ```
*/
getMovableList<Key extends (keyof T) | ContainerID>(name: Key): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;
/**
* Get a LoroTree by container id

@@ -231,3 +246,3 @@ *

* ```ts
* import { Loro } from "loro-crdt";
* import { Loro, LoroText } from "loro-crdt";
*

@@ -239,3 +254,3 @@ * const doc = new Loro();

* text.insert(0, "Hello");
* console.log(list.getDeepValue()); // [100, "Hello"];
* console.log(list.toJson()); // [100, "Hello"];
* ```

@@ -276,5 +291,117 @@ */

delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
getAttached(): undefined | LoroList<T>;
}
interface LoroMovableList<T = unknown> {
new (): LoroMovableList<T>;
/**
* Get elements of the list. If the value is a child container, the corresponding
* `Container` will be returned.
*
* @example
* ```ts
* import { Loro, LoroText } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* list.insert(1, "foo");
* list.insert(2, true);
* list.insertContainer(3, new LoroText());
* console.log(list.value); // [100, "foo", true, LoroText];
* ```
*/
toArray(): T[];
/**
* Insert a container at the index.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* const text = list.insertContainer(1, new LoroText());
* text.insert(0, "Hello");
* console.log(list.toJson()); // [100, "Hello"];
* ```
*/
insertContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
/**
* Get the value at the index. If the value is a container, the corresponding handler will be returned.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMoableList("list");
* list.insert(0, 100);
* console.log(list.get(0)); // 100
* console.log(list.get(1)); // undefined
* ```
*/
get(index: number): T;
/**
* Insert a value at index.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* list.insert(1, "foo");
* list.insert(2, true);
* console.log(list.value); // [100, "foo", true];
* ```
*/
insert(pos: number, value: Exclude<T, Container>): void;
delete(pos: number, len: number): void;
subscribe(listener: Listener): number;
getAttached(): undefined | LoroMovableList<T>;
/**
* Set the value at the given position.
*
* It's different from `delete` + `insert` that it will replace the value at the position.
*
* For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.
* If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.
*
* But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations
* and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getList("list");
* list.insert(0, 100);
* list.insert(1, "foo");
* list.insert(2, true);
* list.set(1, "bar");
* console.log(list.value); // [100, "bar", true];
* ```
*/
set(pos: number, value: Exclude<T, Container>): void;
/**
* Set a container at the index.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* const text = list.setContainer(0, new LoroText());
* text.insert(0, "Hello");
* console.log(list.toJson()); // ["Hello"];
* ```
*/
setContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
}
interface LoroMap<T extends Record<string, unknown> = Record<string, unknown>> {

@@ -349,3 +476,3 @@ new (): LoroMap<T>;

delete(key: string): void;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
}

@@ -356,3 +483,3 @@ interface LoroText {

delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
}

@@ -366,3 +493,3 @@ interface LoroTree<T extends Record<string, unknown> = Record<string, unknown>> {

getNodeByID(target: TreeID): LoroTreeNode;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
}

@@ -369,0 +496,0 @@ interface LoroTreeNode<T extends Record<string, unknown> = Record<string, unknown>> {

4

package.json
{
"name": "loro-crdt",
"version": "0.14.6",
"version": "0.15.0",
"description": "Loro CRDTs is a high-performance CRDT framework that makes your app state synchronized, collaborative and maintainable effortlessly.",

@@ -20,3 +20,3 @@ "keywords": [

"dependencies": {
"loro-wasm": "0.14.6"
"loro-wasm": "0.15.0"
},

@@ -23,0 +23,0 @@ "devDependencies": {

@@ -211,2 +211,19 @@ export * from "loro-wasm";

/**
* Get a LoroMovableList by container id
*
* The object returned is a new js object each time because it need to cross
* the WASM boundary.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getList("list");
* ```
*/
getMovableList<Key extends (keyof T) | ContainerID>(
name: Key,
): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;
/**
* Get a LoroTree by container id

@@ -256,3 +273,3 @@ *

* ```ts
* import { Loro } from "loro-crdt";
* import { Loro, LoroText } from "loro-crdt";
*

@@ -264,3 +281,3 @@ * const doc = new Loro();

* text.insert(0, "Hello");
* console.log(list.getDeepValue()); // [100, "Hello"];
* console.log(list.toJson()); // [100, "Hello"];
* ```

@@ -304,6 +321,125 @@ */

delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
getAttached(): undefined | LoroList<T>;
}
interface LoroMovableList<T = unknown> {
new (): LoroMovableList<T>;
/**
* Get elements of the list. If the value is a child container, the corresponding
* `Container` will be returned.
*
* @example
* ```ts
* import { Loro, LoroText } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* list.insert(1, "foo");
* list.insert(2, true);
* list.insertContainer(3, new LoroText());
* console.log(list.value); // [100, "foo", true, LoroText];
* ```
*/
toArray(): T[];
/**
* Insert a container at the index.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* const text = list.insertContainer(1, new LoroText());
* text.insert(0, "Hello");
* console.log(list.toJson()); // [100, "Hello"];
* ```
*/
insertContainer<C extends Container>(
pos: number,
child: C,
): T extends C ? T : C;
/**
* Get the value at the index. If the value is a container, the corresponding handler will be returned.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMoableList("list");
* list.insert(0, 100);
* console.log(list.get(0)); // 100
* console.log(list.get(1)); // undefined
* ```
*/
get(index: number): T;
/**
* Insert a value at index.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* list.insert(1, "foo");
* list.insert(2, true);
* console.log(list.value); // [100, "foo", true];
* ```
*/
insert(pos: number, value: Exclude<T, Container>): void;
delete(pos: number, len: number): void;
subscribe(listener: Listener): number;
getAttached(): undefined | LoroMovableList<T>;
/**
* Set the value at the given position.
*
* It's different from `delete` + `insert` that it will replace the value at the position.
*
* For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.
* If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.
*
* But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations
* and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getList("list");
* list.insert(0, 100);
* list.insert(1, "foo");
* list.insert(2, true);
* list.set(1, "bar");
* console.log(list.value); // [100, "bar", true];
* ```
*/
set(pos: number, value: Exclude<T, Container>): void;
/**
* Set a container at the index.
*
* @example
* ```ts
* import { Loro } from "loro-crdt";
*
* const doc = new Loro();
* const list = doc.getMovableList("list");
* list.insert(0, 100);
* const text = list.setContainer(0, new LoroText());
* text.insert(0, "Hello");
* console.log(list.toJson()); // ["Hello"];
* ```
*/
setContainer<C extends Container>(
pos: number,
child: C,
): T extends C ? T : C;
}
interface LoroMap<

@@ -383,3 +519,3 @@ T extends Record<string, unknown> = Record<string, unknown>,

delete(key: string): void;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
}

@@ -391,3 +527,3 @@

delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
}

@@ -404,3 +540,3 @@

getNodeByID(target: TreeID): LoroTreeNode;
subscribe(txn: Loro, listener: Listener): number;
subscribe(listener: Listener): number;
}

@@ -407,0 +543,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc