@codesandbox/crdt-tree
Advanced tools
Comparing version 1.2.0 to 1.3.0-beta.1
@@ -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) | ||
}; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
23692
1
12
551
2
1
+ Addedmitt@^3.0.0
+ Addedmitt@3.0.1(transitive)