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

@codesandbox/crdt-tree

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codesandbox/crdt-tree - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0-beta.1

21

package.json

@@ -5,3 +5,3 @@ {

"author": "Matan Kushner",
"version": "1.2.0",
"version": "1.3.0-beta.1",
"license": "MIT",

@@ -19,2 +19,3 @@ "main": "dist/index.js",

"scripts": {
"prepare": "husky install",
"start": "tsdx watch",

@@ -24,3 +25,2 @@ "build": "tsdx build",

"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",

@@ -31,5 +31,5 @@ "analyze": "size-limit --why"

"@size-limit/preset-small-lib": "^4.10.2",
"@weiran.zsd/tsdx": "^0.15.0",
"husky": "^6.0.0",
"size-limit": "^4.10.2",
"@weiran.zsd/tsdx": "^0.15.0",
"tslib": "^2.2.0",

@@ -50,3 +50,13 @@ "typescript": "^4.2.4"

"branches": [
"main"
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
]

@@ -58,3 +68,6 @@ },

}
},
"dependencies": {
"mitt": "^3.0.0"
}
}

@@ -21,3 +21,24 @@ // Holds Tree CRDT state and implements the core algorithm.

import { TreeNode } from "./TreeNode";
import mitt from "mitt";
type Events<Id, Metadata> = {
/**
* Intermediary operations made when reordering events based on timestamps.
*
* This is useful when mirroring the state of `crdt-tree` to another
* stateful representation.
* */
intermediaryOp: {
id: Id;
metadata: Metadata;
parent?: Parent<Id, Metadata>;
};
};
type Parent<Id, Metadata> = {
id: Id;
metadata?: Metadata;
parent?: Parent<Id, Metadata>;
};
interface StateOptions<Id, Metadata> {

@@ -42,2 +63,4 @@ /**

tree: Tree<Id, Metadata> = new Tree();
/** An event emitter for updates to the state of the tree */
emitter = mitt<Events<Id, Metadata>>();
/** Returns true if the given operation should be discarded */

@@ -130,2 +153,8 @@ conflictHandler: (

this.tree.addNode(op.id, node);
this.emitter.emit("intermediaryOp", {
id: op.id,
metadata: op.metadata,
parent: this.flattenTree(op.parentId, this.tree)
});
return { op, oldNode };

@@ -141,2 +170,8 @@ }

this.tree.addNode(log.op.id, node);
this.emitter.emit("intermediaryOp", {
id: log.op.id,
metadata: log.op.metadata,
parent: log.oldNode && this.flattenTree(log.oldNode?.parentId, this.tree)
});
}

@@ -153,2 +188,18 @@

}
/**
* Produces a flattened tree of ancestors used by `intermediaryOp` for operations
* that may require a snapshot of the state of the entry's ancestors.
* */
private flattenTree(
parentId: Id,
tree: Tree<Id, Metadata>
): Parent<Id, Metadata> {
const ancestorId = tree.get(parentId)?.parentId;
return {
id: parentId,
metadata: tree.get(parentId)?.metadata,
parent: ancestorId && this.flattenTree(ancestorId, tree)
};
}
}
dist/Clock.d.ts
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