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.3.0 to 0.4.0-alpha.0

README.md

133

dist/loro.d.ts

@@ -1,19 +0,42 @@

import { ContainerID, PrelimList, PrelimMap, PrelimText } from 'loro-wasm';
export { ContainerID, ContainerType, Loro, LoroList, LoroMap, LoroText, PrelimList, PrelimMap, PrelimText, Transaction, setPanicHook } from 'loro-wasm';
import { ContainerID, PrelimList, PrelimMap, PrelimText, Delta, TreeID } from 'loro-wasm';
export * from 'loro-wasm';
export { Loro } from 'loro-wasm';
type Value = ContainerID | string | number | null | {
/**
* Data types supported by loro
*/
type Value = ContainerID | string | number | boolean | null | {
[key: string]: Value;
} | Value[];
} | Uint8Array | Value[];
type Prelim = PrelimList | PrelimMap | PrelimText;
/**
* Represents a path to identify the exact location of an event's target.
* The path is composed of numbers (e.g., indices of a list container) and strings
* (e.g., keys of a map container), indicating the absolute position of the event's source
* within a loro document.
*/
type Path = (number | string)[];
type Delta<T> = {
type: "insert";
value: T;
} | {
type: "delete";
len: number;
} | {
type: "retain";
len: number;
};
/**
* The event of Loro.
* @prop local - Indicates whether the event is local.
* @prop origin - (Optional) Provides information about the origin of the event.
* @prop diff - Contains the differential information related to the event.
* @prop target - Identifies the container ID of the event's target.
* @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.
*/
interface LoroEvent {
local: boolean;
origin?: string;
/**
* If true, this event was triggered by a child container.
*/
fromChildren: boolean;
/**
* If true, this event was triggered by a checkout.
*/
fromCheckout: boolean;
diff: Diff;
target: ContainerID;
path: Path;
}
type ListDiff = {

@@ -29,19 +52,16 @@ type: "list";

type: "map";
updated: Record<string, Value | undefined>;
};
type TreeDiff = {
type: "tree";
diff: {
added: Record<string, Value>;
deleted: Record<string, Value>;
updated: Record<string, {
old: Value;
new: Value;
}>;
target: TreeID;
action: "create" | "delete";
} | {
target: TreeID;
action: "move";
parent: TreeID;
};
};
type Diff = ListDiff | TextDiff | MapDiff;
interface LoroEvent {
local: boolean;
origin?: string;
diff: Diff;
target: ContainerID;
path: Path;
}
type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;
interface Listener {

@@ -55,45 +75,40 @@ (event: LoroEvent): void;

subscribe(listener: Listener): number;
transact(f: (tx: Transaction) => void, origin?: string): void;
}
interface Loro<T extends Record<string, any> = Record<string, any>> {
getTypedMap<Key extends (keyof T) & string>(name: Key): T[Key] extends LoroMap ? T[Key] : never;
getTypedList<Key extends (keyof T) & string>(name: Key): T[Key] extends LoroList ? T[Key] : never;
getTypedMap<Key extends keyof T & string>(name: Key): T[Key] extends LoroMap ? T[Key] : never;
getTypedList<Key extends keyof T & string>(name: Key): T[Key] extends LoroList ? T[Key] : never;
}
interface LoroList<T extends any[] = any[]> {
insertContainer(txn: Transaction | Loro, pos: number, container: "Map"): LoroMap;
insertContainer(txn: Transaction | Loro, pos: number, container: "List"): LoroList;
insertContainer(txn: Transaction | Loro, pos: number, container: "Text"): LoroText;
insertContainer(txn: Transaction | Loro, pos: number, container: string): never;
insertContainer(pos: number, container: "Map"): LoroMap;
insertContainer(pos: number, container: "List"): LoroList;
insertContainer(pos: number, container: "Text"): LoroText;
insertContainer(pos: number, container: "Tree"): LoroTree;
insertContainer(pos: number, container: string): never;
get(index: number): Value;
getTyped<Key extends (keyof T) & number>(loro: Loro, index: Key): T[Key];
insertTyped<Key extends (keyof T) & number>(txn: Transaction | Loro, pos: Key, value: T[Key]): void;
insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void;
delete(txn: Transaction | Loro, pos: number, len: number): void;
subscribe(txn: Transaction | Loro, listener: Listener): number;
subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
getTyped<Key extends keyof T & number>(loro: Loro, index: Key): T[Key];
insertTyped<Key extends keyof T & number>(pos: Key, value: T[Key]): void;
insert(pos: number, value: Value | Prelim): void;
delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
}
interface LoroMap<T extends Record<string, any> = Record<string, any>> {
insertContainer(txn: Transaction | Loro, key: string, container_type: "Map"): LoroMap;
insertContainer(txn: Transaction | Loro, key: string, container_type: "List"): LoroList;
insertContainer(txn: Transaction | Loro, key: string, container_type: "Text"): LoroText;
insertContainer(txn: Transaction | Loro, key: string, container_type: string): never;
setContainer(key: string, container_type: "Map"): LoroMap;
setContainer(key: string, container_type: "List"): LoroList;
setContainer(key: string, container_type: "Text"): LoroText;
setContainer(key: string, container_type: "Tree"): LoroTree;
setContainer(key: string, container_type: string): never;
get(key: string): Value;
getTyped<Key extends (keyof T) & string>(txn: Loro, key: Key): T[Key];
set(txn: Transaction | Loro, key: string, value: Value | Prelim): void;
setTyped<Key extends (keyof T) & string>(txn: Transaction | Loro, key: Key, value: T[Key]): void;
delete(txn: Transaction | Loro, key: string): void;
subscribe(txn: Transaction | Loro, listener: Listener): number;
subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];
set(key: string, value: Value | Prelim): void;
setTyped<Key extends keyof T & string>(key: Key, value: T[Key]): void;
delete(key: string): void;
subscribe(txn: Loro, listener: Listener): number;
}
interface LoroText {
insert(txn: Transaction | Loro, pos: number, text: string): void;
delete(txn: Transaction | Loro, pos: number, len: number): void;
subscribe(txn: Transaction | Loro, listener: Listener): number;
subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
insert(pos: number, text: string): void;
delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
}
}
export { Delta, Diff, ListDiff, LoroEvent, MapDiff, Path, Prelim, TextDiff, Value, isContainerId };
export { Diff, ListDiff, LoroEvent, MapDiff, Path, Prelim, TextDiff, TreeDiff, Value, isContainerId };

@@ -5,14 +5,8 @@ 'use strict';

loroWasm.Loro.prototype.transact = function(cb, origin) {
this.__raw__transactionWithOrigin(origin, (txn) => {
try {
cb(txn);
} finally {
txn.commit();
txn.free();
}
});
loroWasm.Loro.prototype.getTypedMap = function(...args) {
return this.getMap(...args);
};
loroWasm.Loro.prototype.getTypedMap = loroWasm.Loro.prototype.getMap;
loroWasm.Loro.prototype.getTypedList = loroWasm.Loro.prototype.getList;
loroWasm.Loro.prototype.getTypedList = function(...args) {
return this.getList(...args);
};
loroWasm.LoroList.prototype.getTyped = function(loro, index) {

@@ -26,3 +20,5 @@ const value = this.get(index);

};
loroWasm.LoroList.prototype.insertTyped = loroWasm.LoroList.prototype.insert;
loroWasm.LoroList.prototype.insertTyped = function(...args) {
return this.insert(...args);
};
loroWasm.LoroMap.prototype.getTyped = function(loro, key) {

@@ -36,66 +32,7 @@ const value = this.get(key);

};
loroWasm.LoroMap.prototype.setTyped = loroWasm.LoroMap.prototype.set;
loroWasm.LoroText.prototype.insert = function(txn, pos, text) {
if (txn instanceof loroWasm.Loro) {
this.__loro_insert(txn, pos, text);
} else {
this.__txn_insert(txn, pos, text);
}
loroWasm.LoroMap.prototype.setTyped = function(...args) {
return this.set(...args);
};
loroWasm.LoroText.prototype.delete = function(txn, pos, len) {
if (txn instanceof loroWasm.Loro) {
this.__loro_delete(txn, pos, len);
} else {
this.__txn_delete(txn, pos, len);
}
};
loroWasm.LoroList.prototype.insert = function(txn, pos, len) {
if (txn instanceof loroWasm.Loro) {
this.__loro_insert(txn, pos, len);
} else {
this.__txn_insert(txn, pos, len);
}
};
loroWasm.LoroList.prototype.delete = function(txn, pos, len) {
if (txn instanceof loroWasm.Loro) {
this.__loro_delete(txn, pos, len);
} else {
this.__txn_delete(txn, pos, len);
}
};
loroWasm.LoroMap.prototype.set = function(txn, key, value) {
if (txn instanceof loroWasm.Loro) {
this.__loro_insert(txn, key, value);
} else {
this.__txn_insert(txn, key, value);
}
};
loroWasm.LoroMap.prototype.delete = function(txn, key) {
if (txn instanceof loroWasm.Loro) {
this.__loro_delete(txn, key);
} else {
this.__txn_delete(txn, key);
}
};
const CONTAINER_TYPES = ["Map", "Text", "List"];
function isContainerId(s) {
try {
if (s.startsWith("/")) {
const [_, type] = s.slice(1).split(":");
if (!CONTAINER_TYPES.includes(type)) {
return false;
}
} else {
const [id, type] = s.split(":");
if (!CONTAINER_TYPES.includes(type)) {
return false;
}
const [counter, client] = id.split("@");
Number.parseInt(counter);
Number.parseInt(client);
}
return true;
} catch (e) {
return false;
}
return s.startsWith("cid:");
}

@@ -107,35 +44,9 @@

});
Object.defineProperty(exports, 'LoroList', {
enumerable: true,
get: function () { return loroWasm.LoroList; }
exports.isContainerId = isContainerId;
Object.keys(loroWasm).forEach(function (k) {
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return loroWasm[k]; }
});
});
Object.defineProperty(exports, 'LoroMap', {
enumerable: true,
get: function () { return loroWasm.LoroMap; }
});
Object.defineProperty(exports, 'LoroText', {
enumerable: true,
get: function () { return loroWasm.LoroText; }
});
Object.defineProperty(exports, 'PrelimList', {
enumerable: true,
get: function () { return loroWasm.PrelimList; }
});
Object.defineProperty(exports, 'PrelimMap', {
enumerable: true,
get: function () { return loroWasm.PrelimMap; }
});
Object.defineProperty(exports, 'PrelimText', {
enumerable: true,
get: function () { return loroWasm.PrelimText; }
});
Object.defineProperty(exports, 'Transaction', {
enumerable: true,
get: function () { return loroWasm.Transaction; }
});
Object.defineProperty(exports, 'setPanicHook', {
enumerable: true,
get: function () { return loroWasm.setPanicHook; }
});
exports.isContainerId = isContainerId;
//# sourceMappingURL=loro.js.map
{
"name": "loro-crdt",
"version": "0.3.0",
"description": "",
"version": "0.4.0-alpha.0",
"description": "Loro CRDTs is a high-performance CRDT framework that makes your app state synchronized, collaborative and maintainable effortlessly.",
"keywords": [
"crdt",
"CRDTs",
"realtime",
"collaboration",
"sync",
"p2p"
],
"main": "dist/loro.js",
"module": "dist/loro.mjs",
"typings": "dist/loro.d.ts",
"author": "",
"author": "Loro",
"homepage": "https://loro.dev",
"license": "ISC",
"dependencies": {
"loro-wasm": "0.3.0"
"loro-wasm": "0.4.0-alpha.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
"esbuild": "^0.17.12",
"@typescript-eslint/parser": "^6.2.0",
"@vitest/ui": "^0.34.6",
"esbuild": "^0.18.20",
"eslint": "^8.46.0",
"prettier": "^3.0.0",
"rollup": "^3.20.1",

@@ -22,3 +35,3 @@ "rollup-plugin-dts": "^5.3.0",

"vite-plugin-wasm": "^3.2.2",
"vitest": "^0.29.7"
"vitest": "^0.34.0"
},

@@ -25,0 +38,0 @@ "scripts": {

@@ -1,38 +0,12 @@

export {
LoroList,
LoroMap,
LoroText,
PrelimList,
PrelimMap,
PrelimText,
setPanicHook,
Transaction,
} from "loro-wasm";
import { PrelimMap } from "loro-wasm";
import { PrelimText } from "loro-wasm";
import { PrelimList } from "loro-wasm";
import {
ContainerID,
Loro,
LoroList,
LoroMap,
LoroText,
Transaction,
} from "loro-wasm";
export * from "loro-wasm";
import { Delta } from "loro-wasm";
import { PrelimText,PrelimList,PrelimMap } from "loro-wasm";
import { ContainerID, Loro, LoroList, LoroMap, LoroText , LoroTree, TreeID} from "loro-wasm";
export type { ContainerID, ContainerType } from "loro-wasm";
Loro.prototype.transact = function (cb, origin) {
this.__raw__transactionWithOrigin(origin, (txn: Transaction) => {
try {
cb(txn);
} finally {
txn.commit();
txn.free();
}
});
Loro.prototype.getTypedMap = function (...args) {
return this.getMap(...args);
};
Loro.prototype.getTypedMap = Loro.prototype.getMap;
Loro.prototype.getTypedList = Loro.prototype.getList;
Loro.prototype.getTypedList = function (...args) {
return this.getList(...args);
};
LoroList.prototype.getTyped = function (loro, index) {

@@ -46,3 +20,5 @@ const value = this.get(index);

};
LoroList.prototype.insertTyped = LoroList.prototype.insert;
LoroList.prototype.insertTyped = function (...args) {
return this.insert(...args);
};
LoroMap.prototype.getTyped = function (loro, key) {

@@ -56,52 +32,9 @@ const value = this.get(key);

};
LoroMap.prototype.setTyped = LoroMap.prototype.set;
LoroText.prototype.insert = function (txn, pos, text) {
if (txn instanceof Loro) {
this.__loro_insert(txn, pos, text);
} else {
this.__txn_insert(txn, pos, text);
}
LoroMap.prototype.setTyped = function (...args) {
return this.set(...args);
};
LoroText.prototype.delete = function (txn, pos, len) {
if (txn instanceof Loro) {
this.__loro_delete(txn, pos, len);
} else {
this.__txn_delete(txn, pos, len);
}
};
LoroList.prototype.insert = function (txn, pos, len) {
if (txn instanceof Loro) {
this.__loro_insert(txn, pos, len);
} else {
this.__txn_insert(txn, pos, len);
}
};
LoroList.prototype.delete = function (txn, pos, len) {
if (txn instanceof Loro) {
this.__loro_delete(txn, pos, len);
} else {
this.__txn_delete(txn, pos, len);
}
};
LoroMap.prototype.set = function (txn, key, value) {
if (txn instanceof Loro) {
this.__loro_insert(txn, key, value);
} else {
this.__txn_insert(txn, key, value);
}
};
LoroMap.prototype.delete = function (txn, key) {
if (txn instanceof Loro) {
this.__loro_delete(txn, key);
} else {
this.__txn_delete(txn, key);
}
};
/**
* Data types supported by loro
*/
export type Value =

@@ -111,20 +44,43 @@ | ContainerID

| number
| boolean
| null
| { [key: string]: Value }
| Uint8Array
| Value[];
export type Prelim = PrelimList | PrelimMap | PrelimText;
/**
* Represents a path to identify the exact location of an event's target.
* The path is composed of numbers (e.g., indices of a list container) and strings
* (e.g., keys of a map container), indicating the absolute position of the event's source
* within a loro document.
*/
export type Path = (number | string)[];
export type Delta<T> = {
type: "insert";
value: T;
} | {
type: "delete";
len: number;
} | {
type: "retain";
len: number;
};
/**
* The event of Loro.
* @prop local - Indicates whether the event is local.
* @prop origin - (Optional) Provides information about the origin of the event.
* @prop diff - Contains the differential information related to the event.
* @prop target - Identifies the container ID of the event's target.
* @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.
*/
export interface LoroEvent {
local: boolean;
origin?: string;
/**
* If true, this event was triggered by a child container.
*/
fromChildren: boolean;
/**
* If true, this event was triggered by a checkout.
*/
fromCheckout: boolean;
diff: Diff;
target: ContainerID;
path: Path;
}
export type ListDiff = {

@@ -142,22 +98,12 @@ type: "list";

type: "map";
diff: {
added: Record<string, Value>;
deleted: Record<string, Value>;
updated: Record<string, {
old: Value;
new: Value;
}>;
};
updated: Record<string, Value | undefined>;
};
export type Diff = ListDiff | TextDiff | MapDiff;
export interface LoroEvent {
local: boolean;
origin?: string;
diff: Diff;
target: ContainerID;
path: Path;
export type TreeDiff = {
type: "tree";
diff: {target: TreeID, action: "create"|"delete" } | {target: TreeID; action:"move"; parent: TreeID};
}
export type Diff = ListDiff | TextDiff | MapDiff | TreeDiff;
interface Listener {

@@ -167,26 +113,6 @@ (event: LoroEvent): void;

const CONTAINER_TYPES = ["Map", "Text", "List"];
const CONTAINER_TYPES = ["Map", "Text", "List", "Tree"];
export function isContainerId(s: string): s is ContainerID {
try {
if (s.startsWith("/")) {
const [_, type] = s.slice(1).split(":");
if (!CONTAINER_TYPES.includes(type)) {
return false;
}
} else {
const [id, type] = s.split(":");
if (!CONTAINER_TYPES.includes(type)) {
return false;
}
const [counter, client] = id.split("@");
Number.parseInt(counter);
Number.parseInt(client);
}
return true;
} catch (e) {
return false;
}
return s.startsWith("cid:");
}

@@ -199,10 +125,9 @@

subscribe(listener: Listener): number;
transact(f: (tx: Transaction) => void, origin?: string): void;
}
interface Loro<T extends Record<string, any> = Record<string, any>> {
getTypedMap<Key extends (keyof T) & string>(
getTypedMap<Key extends keyof T & string>(
name: Key,
): T[Key] extends LoroMap ? T[Key] : never;
getTypedList<Key extends (keyof T) & string>(
getTypedList<Key extends keyof T & string>(
name: Key,

@@ -213,83 +138,36 @@ ): T[Key] extends LoroList ? T[Key] : never;

interface LoroList<T extends any[] = any[]> {
insertContainer(
txn: Transaction | Loro,
pos: number,
container: "Map",
): LoroMap;
insertContainer(
txn: Transaction | Loro,
pos: number,
container: "List",
): LoroList;
insertContainer(
txn: Transaction | Loro,
pos: number,
container: "Text",
): LoroText;
insertContainer(
txn: Transaction | Loro,
pos: number,
container: string,
): never;
insertContainer(pos: number, container: "Map"): LoroMap;
insertContainer(pos: number, container: "List"): LoroList;
insertContainer(pos: number, container: "Text"): LoroText;
insertContainer(pos: number, container: "Tree"): LoroTree;
insertContainer(pos: number, container: string): never;
get(index: number): Value;
getTyped<Key extends (keyof T) & number>(loro: Loro, index: Key): T[Key];
insertTyped<Key extends (keyof T) & number>(
txn: Transaction | Loro,
pos: Key,
value: T[Key],
): void;
insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void;
delete(txn: Transaction | Loro, pos: number, len: number): void;
subscribe(txn: Transaction | Loro, listener: Listener): number;
subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
getTyped<Key extends keyof T & number>(loro: Loro, index: Key): T[Key];
insertTyped<Key extends keyof T & number>(pos: Key, value: T[Key]): void;
insert(pos: number, value: Value | Prelim): void;
delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
}
interface LoroMap<T extends Record<string, any> = Record<string, any>> {
insertContainer(
txn: Transaction | Loro,
key: string,
container_type: "Map",
): LoroMap;
insertContainer(
txn: Transaction | Loro,
key: string,
container_type: "List",
): LoroList;
insertContainer(
txn: Transaction | Loro,
key: string,
container_type: "Text",
): LoroText;
insertContainer(
txn: Transaction | Loro,
key: string,
container_type: string,
): never;
setContainer(key: string, container_type: "Map"): LoroMap;
setContainer(key: string, container_type: "List"): LoroList;
setContainer(key: string, container_type: "Text"): LoroText;
setContainer(key: string, container_type: "Tree"): LoroTree;
setContainer(key: string, container_type: string): never;
get(key: string): Value;
getTyped<Key extends (keyof T) & string>(
txn: Loro,
key: Key,
): T[Key];
set(txn: Transaction | Loro, key: string, value: Value | Prelim): void;
setTyped<Key extends (keyof T) & string>(
txn: Transaction | Loro,
key: Key,
value: T[Key],
): void;
delete(txn: Transaction | Loro, key: string): void;
subscribe(txn: Transaction | Loro, listener: Listener): number;
subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];
set(key: string, value: Value | Prelim): void;
setTyped<Key extends keyof T & string>(key: Key, value: T[Key]): void;
delete(key: string): void;
subscribe(txn: Loro, listener: Listener): number;
}
interface LoroText {
insert(txn: Transaction | Loro, pos: number, text: string): void;
delete(txn: Transaction | Loro, pos: number, len: number): void;
subscribe(txn: Transaction | Loro, listener: Listener): number;
subscribeDeep(txn: Transaction | Loro, listener: Listener): number;
subscribeOnce(txn: Transaction | Loro, listener: Listener): number;
insert(pos: number, text: string): void;
delete(pos: number, len: number): void;
subscribe(txn: Loro, listener: Listener): number;
}
}

@@ -7,3 +7,3 @@ /// <reference types="vitest" />

plugins: [wasm()],
test: {},
// test: {},
});

Sorry, the diff of this file is not supported yet

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