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.2 to 0.14.3

deno/.vscode/settings.json

42

dist/loro.d.ts

@@ -1,5 +0,36 @@

import { Container, ContainerID, TreeID, OpId, Delta, Value, LoroText, LoroMap, LoroTree, LoroList } from 'loro-wasm';
import { AwarenessWasm, PeerID as PeerID$1, Container, ContainerID, TreeID, OpId, Delta, Value, LoroText, LoroMap, LoroTree, LoroList } from 'loro-wasm';
export * from 'loro-wasm';
export { Loro } from 'loro-wasm';
type AwarenessListener = (arg: {
updated: PeerID$1[];
added: PeerID$1[];
removed: PeerID$1[];
}, origin: "local" | "timeout" | "remote" | string) => void;
/**
* Awareness is a structure that allows to track the ephemeral state of the peers.
*
* If we don't receive a state update from a peer within the timeout, we will remove their state.
* The timeout is in milliseconds. This can be used to handle the off-line state of a peer.
*/
declare class Awareness<T> {
inner: AwarenessWasm<T>;
private peer;
private timer;
private timeout;
private listeners;
constructor(peer: PeerID$1, timeout?: number);
apply(bytes: Uint8Array, origin?: string): void;
setLocalState(state: T): void;
getLocalState(): T | undefined;
getAllStates(): Record<PeerID$1, T>;
encode(peers: PeerID$1[]): Uint8Array;
encodeAll(): Uint8Array;
addListener(listener: AwarenessListener): void;
removeListener(listener: AwarenessListener): void;
peers(): PeerID$1[];
destroy(): void;
private startTimerIfNotEmpty;
}
type Frontiers = OpId[];

@@ -342,5 +373,12 @@ /**

}
interface AwarenessWasm<T = unknown> {
getState(peer: PeerID): T | undefined;
getTimestamp(peer: PeerID): number | undefined;
getAllStates(): Record<PeerID, T>;
setLocalState(value: T): void;
removeOutdated(): PeerID[];
}
}
type NonNullableType<T> = Exclude<T, null | undefined>;
export { Diff, Frontiers, ListDiff, LoroEvent, LoroEventBatch, MapDiff, Path, TextDiff, TreeDiff, TreeDiffItem, getType, isContainer, isContainerId };
export { Awareness, Diff, Frontiers, ListDiff, LoroEvent, LoroEventBatch, MapDiff, Path, TextDiff, TreeDiff, TreeDiffItem, getType, isContainer, isContainerId };

@@ -5,2 +5,84 @@ 'use strict';

class Awareness {
inner;
peer;
timer;
timeout;
listeners = /* @__PURE__ */ new Set();
constructor(peer, timeout = 3e4) {
this.inner = new loroWasm.AwarenessWasm(peer, timeout);
this.peer = peer;
this.timeout = timeout;
}
apply(bytes, origin = "remote") {
const { updated, added } = this.inner.apply(bytes);
this.listeners.forEach((listener) => {
listener({ updated, added, removed: [] }, origin);
});
this.startTimerIfNotEmpty();
}
setLocalState(state) {
const wasEmpty = this.inner.getState(this.peer) == null;
this.inner.setLocalState(state);
if (wasEmpty) {
this.listeners.forEach((listener) => {
listener(
{ updated: [], added: [this.inner.peer()], removed: [] },
"local"
);
});
} else {
this.listeners.forEach((listener) => {
listener(
{ updated: [this.inner.peer()], added: [], removed: [] },
"local"
);
});
}
this.startTimerIfNotEmpty();
}
getLocalState() {
return this.inner.getState(this.peer);
}
getAllStates() {
return this.inner.getAllStates();
}
encode(peers) {
return this.inner.encode(peers);
}
encodeAll() {
return this.inner.encodeAll();
}
addListener(listener) {
this.listeners.add(listener);
}
removeListener(listener) {
this.listeners.delete(listener);
}
peers() {
return this.inner.peers();
}
destroy() {
clearInterval(this.timer);
this.listeners.clear();
}
startTimerIfNotEmpty() {
if (this.inner.isEmpty() || this.timer != null) {
return;
}
this.timer = setInterval(() => {
const removed = this.inner.removeOutdated();
if (removed.length > 0) {
this.listeners.forEach((listener) => {
listener({ updated: [], added: [], removed }, "timeout");
});
}
if (this.inner.isEmpty()) {
clearInterval(this.timer);
this.timer = void 0;
}
}, this.timeout / 2);
}
}
const CONTAINER_TYPES = ["Map", "Text", "List", "Tree"];

@@ -31,2 +113,3 @@ function isContainerId(s) {

});
exports.Awareness = Awareness;
exports.getType = getType;

@@ -33,0 +116,0 @@ exports.isContainer = isContainer;

4

package.json
{
"name": "loro-crdt",
"version": "0.14.2",
"version": "0.14.3",
"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.2"
"loro-wasm": "0.14.3"
},

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

@@ -15,2 +15,3 @@ export * from "loro-wasm";

} from "loro-wasm";
export { Awareness } from "./awareness";

@@ -414,4 +415,14 @@ export type Frontiers = OpId[];

}
interface AwarenessWasm<
T = unknown,
> {
getState(peer: PeerID): T | undefined;
getTimestamp(peer: PeerID): number | undefined;
getAllStates(): Record<PeerID, T>;
setLocalState(value: T): void;
removeOutdated(): PeerID[];
}
}
type NonNullableType<T> = Exclude<T, null | undefined>;

@@ -100,3 +100,8 @@ {

"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
},
"exclude": [
"node_modules",
"dist",
"deno"
]
}

@@ -1,10 +0,12 @@

/// <reference types="vitest" />
import { configDefaults, defineConfig } from 'vitest/config'
import wasm from "vite-plugin-wasm";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [wasm()],
// test: {
// reporters:['hanging-process']
// },
test: {
exclude: [
...configDefaults.exclude,
"deno/*"
]
},
});

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

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