@codesandbox/crdt-tree
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -400,7 +400,6 @@ 'use strict'; | ||
this.latestTimeByReplica = new Map(); | ||
this.tree = this.state.tree; | ||
this.get = this.tree.get; | ||
this.time = new Clock(authorId); | ||
} | ||
var _proto = TreeReplica.prototype; | ||
/** | ||
@@ -415,2 +414,6 @@ * Generates an OpMove | ||
*/ | ||
var _proto = TreeReplica.prototype; | ||
_proto.opMove = function opMove(id, metadata, parentId) { | ||
@@ -478,9 +481,2 @@ return { | ||
_createClass(TreeReplica, [{ | ||
key: "tree", | ||
get: function get() { | ||
return this.state.tree; | ||
} | ||
}]); | ||
return TreeReplica; | ||
@@ -487,0 +483,0 @@ }(); |
@@ -1,2 +0,2 @@ | ||
"use strict";var t;Object.defineProperty(exports,"__esModule",{value:!0}),(t=exports.Ordering||(exports.Ordering={}))[t.Equal=0]="Equal",t[t.Greater=1]="Greater",t[t.Less=2]="Less";var e=function(){function t(t,e){void 0===e&&(e=0),this.actorId=t,this.counter=e}var e=t.prototype;return e.inc=function(){return new t(this.actorId,this.counter+1)},e.tick=function(){return this.counter+=1,new t(this.actorId,this.counter)},e.merge=function(e){return new t(this.actorId,Math.max(this.counter,e.counter))},e.compare=function(t){return this.counter>t.counter?exports.Ordering.Greater:this.counter<t.counter?exports.Ordering.Less:this.actorId>t.actorId?exports.Ordering.Greater:this.actorId<t.actorId?exports.Ordering.Less:exports.Ordering.Equal},e.valueOf=function(){return this.toString()},e.toString=function(){return String(this.counter).padStart(10,"0")+":"+this.actorId},t}();function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=function(){function t(){this.nodes=new Map,this.children=new Map}var e=t.prototype;return e.remove=function(t){var e=this.nodes.get(t);if(e){var r=this.children.get(e.parentId);r&&(r.delete(t),0===r.size&&this.children.delete(e.parentId),this.nodes.delete(t))}},e.addNode=function(t,e){var r=this.children.get(e.parentId);r||(r=new Set,this.children.set(e.parentId,r)),r.add(t),this.nodes.set(t,e)},e.get=function(t){return this.nodes.get(t)},e.isAncestor=function(t,e){for(var r,n=t;r=this.get(n);){if(r.parentId===e)return!0;n=r.parentId}return!1},e.printNode=function(t,e){var r;void 0===e&&(e=0);var n=this.get(t),i=t+" "+(n?""+JSON.stringify(n.metadata):""),o=" ".repeat(2*e);console.log(o+i);for(var a=0,s=Array.from(null!=(r=this.children.get(t))?r:[]);a<s.length;a++)this.printNode(s[a],e+1)},n(t,[{key:"size",get:function(){return this.nodes.size}}]),t}(),s=function(t,e){this.parentId=t,this.metadata=e},p=function(){function t(){this.operationLog=[],this.tree=new a}var e=t.prototype;return e.addLogEntry=function(t){this.operationLog.unshift(t)},e.applyOp=function(t){if(0===this.operationLog.length){var e=this.doOperation(t);this.addLogEntry(e)}else{var r=this.operationLog[0].op;if(t.timestamp===r.timestamp&&console.log("op with timestamp equal to previous op ignored. (not applied). Every op must have a unique timestamp."),t.timestamp<r.timestamp){var n=this.operationLog.shift();this.undoOp(n),this.applyOp(t),this.redoOp(n)}if(t.timestamp>r.timestamp){var i=this.doOperation(t);this.addLogEntry(i)}}},e.applyOps=function(t){for(var e,r=o(t);!(e=r()).done;)this.applyOp(e.value)},e.doOperation=function(t){var e=this.tree.get(t.id);if(t.id===t.parentId||this.tree.isAncestor(t.parentId,t.id))return{op:t,oldNode:e};this.tree.remove(t.id);var r=new s(t.parentId,t.metadata);return this.tree.addNode(t.id,r),{op:t,oldNode:e}},e.undoOp=function(t){if(this.tree.remove(t.op.id),t.oldNode){var e=new s(t.oldNode.parentId,t.oldNode.metadata);this.tree.addNode(t.op.id,e)}},e.redoOp=function(t){var e=this.doOperation(t.op);this.addLogEntry(e)},t}(),d=function(){function t(t){this.state=new p,this.latestTimeByReplica=new Map,this.time=new e(t)}var r=t.prototype;return r.opMove=function(t,e,r){return{timestamp:this.time.inc(),metadata:e,id:t,parentId:r}},r.opMoves=function(t){for(var e,r=[],n=o(t);!(e=n()).done;){var i=e.value;r.push({timestamp:this.time.tick(),id:i[0],metadata:i[1],parentId:i[2]})}return r},r.applyOp=function(t){var e;this.time=this.time.merge(t.timestamp);var r=t.timestamp.actorId,n=null!=(e=this.latestTimeByReplica.get(r))?e:0;t.timestamp<=n?(console.log("Clock not increased, current timestamp "+n+", provided is "+t.timestamp+"."),console.log("Dropping operation.")):this.latestTimeByReplica.set(r,t.timestamp),this.state.applyOp(t)},r.applyOps=function(t){for(var e,r=o(t);!(e=r()).done;)this.applyOp(e.value)},n(t,[{key:"tree",get:function(){return this.state.tree}}]),t}();exports.Clock=e,exports.State=p,exports.Tree=a,exports.TreeNode=s,exports.TreeReplica=d; | ||
"use strict";var t;Object.defineProperty(exports,"__esModule",{value:!0}),(t=exports.Ordering||(exports.Ordering={}))[t.Equal=0]="Equal",t[t.Greater=1]="Greater",t[t.Less=2]="Less";var e=function(){function t(t,e){void 0===e&&(e=0),this.actorId=t,this.counter=e}var e=t.prototype;return e.inc=function(){return new t(this.actorId,this.counter+1)},e.tick=function(){return this.counter+=1,new t(this.actorId,this.counter)},e.merge=function(e){return new t(this.actorId,Math.max(this.counter,e.counter))},e.compare=function(t){return this.counter>t.counter?exports.Ordering.Greater:this.counter<t.counter?exports.Ordering.Less:this.actorId>t.actorId?exports.Ordering.Greater:this.actorId<t.actorId?exports.Ordering.Less:exports.Ordering.Equal},e.valueOf=function(){return this.toString()},e.toString=function(){return String(this.counter).padStart(10,"0")+":"+this.actorId},t}();function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function n(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return r(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=function(){function t(){this.nodes=new Map,this.children=new Map}var e,r=t.prototype;return r.remove=function(t){var e=this.nodes.get(t);if(e){var r=this.children.get(e.parentId);r&&(r.delete(t),0===r.size&&this.children.delete(e.parentId),this.nodes.delete(t))}},r.addNode=function(t,e){var r=this.children.get(e.parentId);r||(r=new Set,this.children.set(e.parentId,r)),r.add(t),this.nodes.set(t,e)},r.get=function(t){return this.nodes.get(t)},r.isAncestor=function(t,e){for(var r,n=t;r=this.get(n);){if(r.parentId===e)return!0;n=r.parentId}return!1},r.printNode=function(t,e){var r;void 0===e&&(e=0);var n=this.get(t),i=t+" "+(n?""+JSON.stringify(n.metadata):""),o=" ".repeat(2*e);console.log(o+i);for(var a=0,s=Array.from(null!=(r=this.children.get(t))?r:[]);a<s.length;a++)this.printNode(s[a],e+1)},(e=[{key:"size",get:function(){return this.nodes.size}}])&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}(t.prototype,e),t}(),o=function(t,e){this.parentId=t,this.metadata=e},a=function(){function t(){this.operationLog=[],this.tree=new i}var e=t.prototype;return e.addLogEntry=function(t){this.operationLog.unshift(t)},e.applyOp=function(t){if(0===this.operationLog.length){var e=this.doOperation(t);this.addLogEntry(e)}else{var r=this.operationLog[0].op;if(t.timestamp===r.timestamp&&console.log("op with timestamp equal to previous op ignored. (not applied). Every op must have a unique timestamp."),t.timestamp<r.timestamp){var n=this.operationLog.shift();this.undoOp(n),this.applyOp(t),this.redoOp(n)}if(t.timestamp>r.timestamp){var i=this.doOperation(t);this.addLogEntry(i)}}},e.applyOps=function(t){for(var e,r=n(t);!(e=r()).done;)this.applyOp(e.value)},e.doOperation=function(t){var e=this.tree.get(t.id);if(t.id===t.parentId||this.tree.isAncestor(t.parentId,t.id))return{op:t,oldNode:e};this.tree.remove(t.id);var r=new o(t.parentId,t.metadata);return this.tree.addNode(t.id,r),{op:t,oldNode:e}},e.undoOp=function(t){if(this.tree.remove(t.op.id),t.oldNode){var e=new o(t.oldNode.parentId,t.oldNode.metadata);this.tree.addNode(t.op.id,e)}},e.redoOp=function(t){var e=this.doOperation(t.op);this.addLogEntry(e)},t}(),s=function(){function t(t){this.state=new a,this.latestTimeByReplica=new Map,this.tree=this.state.tree,this.get=this.tree.get,this.time=new e(t)}var r=t.prototype;return r.opMove=function(t,e,r){return{timestamp:this.time.inc(),metadata:e,id:t,parentId:r}},r.opMoves=function(t){for(var e,r=[],i=n(t);!(e=i()).done;){var o=e.value;r.push({timestamp:this.time.tick(),id:o[0],metadata:o[1],parentId:o[2]})}return r},r.applyOp=function(t){var e;this.time=this.time.merge(t.timestamp);var r=t.timestamp.actorId,n=null!=(e=this.latestTimeByReplica.get(r))?e:0;t.timestamp<=n?(console.log("Clock not increased, current timestamp "+n+", provided is "+t.timestamp+"."),console.log("Dropping operation.")):this.latestTimeByReplica.set(r,t.timestamp),this.state.applyOp(t)},r.applyOps=function(t){for(var e,r=n(t);!(e=r()).done;)this.applyOp(e.value)},t}();exports.Clock=e,exports.State=a,exports.Tree=i,exports.TreeNode=o,exports.TreeReplica=s; | ||
//# sourceMappingURL=crdt-tree.cjs.production.min.js.map |
@@ -398,7 +398,6 @@ var Ordering; | ||
this.latestTimeByReplica = new Map(); | ||
this.tree = this.state.tree; | ||
this.get = this.tree.get; | ||
this.time = new Clock(authorId); | ||
} | ||
var _proto = TreeReplica.prototype; | ||
/** | ||
@@ -413,2 +412,6 @@ * Generates an OpMove | ||
*/ | ||
var _proto = TreeReplica.prototype; | ||
_proto.opMove = function opMove(id, metadata, parentId) { | ||
@@ -476,9 +479,2 @@ return { | ||
_createClass(TreeReplica, [{ | ||
key: "tree", | ||
get: function get() { | ||
return this.state.tree; | ||
} | ||
}]); | ||
return TreeReplica; | ||
@@ -485,0 +481,0 @@ }(); |
@@ -11,4 +11,5 @@ import { Clock } from "./Clock"; | ||
latestTimeByReplica: Map<Id, Clock<Id>>; | ||
tree: import("./Tree").Tree<Id, Metadata>; | ||
get: (id: Id) => import("./TreeNode").TreeNode<Id, Metadata> | undefined; | ||
constructor(authorId: Id); | ||
get tree(): import("./Tree").Tree<Id, Metadata>; | ||
/** | ||
@@ -15,0 +16,0 @@ * Generates an OpMove |
{ | ||
"name": "@codesandbox/crdt-tree", | ||
"description": "An accurate implementation of the tree CRDT algorithm described in \"A highly-available move operation for replicated trees and distributed filesystems\"", | ||
"author": "Matan Kushner", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +7,0 @@ "main": "dist/index.js", |
@@ -25,2 +25,5 @@ // `TreeReplica` holds tree `State` plus lamport timestamp (actor + counter) | ||
tree = this.state.tree; | ||
get = this.tree.get; | ||
constructor(authorId: Id) { | ||
@@ -30,6 +33,2 @@ this.time = new Clock(authorId); | ||
get tree() { | ||
return this.state.tree; | ||
} | ||
/** | ||
@@ -36,0 +35,0 @@ * Generates an OpMove |
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
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
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
119949
1445