@codesandbox/crdt-tree
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -382,7 +382,12 @@ 'use strict'; | ||
this.tree = this.state.tree; | ||
/** Get a node by its id */ | ||
this.get = this.tree.get; | ||
this.time = new Clock(authorId); | ||
} | ||
/** Get a node by its id */ | ||
var _proto = TreeReplica.prototype; | ||
_proto.get = function get(id) { | ||
this.tree.get(id); | ||
} | ||
/** | ||
@@ -397,6 +402,4 @@ * Generates an OpMove | ||
*/ | ||
; | ||
var _proto = TreeReplica.prototype; | ||
_proto.opMove = function opMove(id, metadata, parentId) { | ||
@@ -403,0 +406,0 @@ return { |
@@ -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){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function i(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return r(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?r(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);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 n=function(){function t(){this.nodes=new Map,this.children=new Map,this.size=this.nodes.size}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,i=t;r=this.get(i);){if(r.parentId===e)return!0;i=r.parentId}return!1},e.printNode=function(t,e){var r;void 0===e&&(e=0);var i=this.get(t),n=t+" "+(i?""+JSON.stringify(i.metadata):""),o=" ".repeat(2*e);console.log(o+n);for(var a=0,s=Array.from(null!=(r=this.children.get(t))?r:[]);a<s.length;a++)this.printNode(s[a],e+1)},t}(),o=function(t,e){this.parentId=t,this.metadata=e},a=function(){function t(){this.operationLog=[],this.tree=new n}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 i=this.operationLog.shift();this.undoOp(i),this.applyOp(t),this.redoOp(i)}if(t.timestamp>r.timestamp){var n=this.doOperation(t);this.addLogEntry(n)}}},e.applyOps=function(t){for(var e,r=i(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=[],n=i(t);!(e=n()).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,i=null!=(e=this.latestTimeByReplica.get(r))?e:0;t.timestamp<=i?(console.log("Clock not increased, current timestamp "+i+", 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=i(t);!(e=r()).done;)this.applyOp(e.value)},t}();exports.Clock=e,exports.State=a,exports.Tree=n,exports.TreeNode=o,exports.TreeReplica=s; | ||
"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,i=new Array(e);r<e;r++)i[r]=t[r];return i}function i(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return r(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?r(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);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 n=function(){function t(){this.nodes=new Map,this.children=new Map,this.size=this.nodes.size}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,i=t;r=this.get(i);){if(r.parentId===e)return!0;i=r.parentId}return!1},e.printNode=function(t,e){var r;void 0===e&&(e=0);var i=this.get(t),n=t+" "+(i?""+JSON.stringify(i.metadata):""),o=" ".repeat(2*e);console.log(o+n);for(var a=0,s=Array.from(null!=(r=this.children.get(t))?r:[]);a<s.length;a++)this.printNode(s[a],e+1)},t}(),o=function(t,e){this.parentId=t,this.metadata=e},a=function(){function t(){this.operationLog=[],this.tree=new n}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 i=this.operationLog.shift();this.undoOp(i),this.applyOp(t),this.redoOp(i)}if(t.timestamp>r.timestamp){var n=this.doOperation(t);this.addLogEntry(n)}}},e.applyOps=function(t){for(var e,r=i(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.time=new e(t)}var r=t.prototype;return r.get=function(t){this.tree.get(t)},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=i(t);!(e=n()).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,i=null!=(e=this.latestTimeByReplica.get(r))?e:0;t.timestamp<=i?(console.log("Clock not increased, current timestamp "+i+", 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=i(t);!(e=r()).done;)this.applyOp(e.value)},t}();exports.Clock=e,exports.State=a,exports.Tree=n,exports.TreeNode=o,exports.TreeReplica=s; | ||
//# sourceMappingURL=crdt-tree.cjs.production.min.js.map |
@@ -380,7 +380,12 @@ var Ordering; | ||
this.tree = this.state.tree; | ||
/** Get a node by its id */ | ||
this.get = this.tree.get; | ||
this.time = new Clock(authorId); | ||
} | ||
/** Get a node by its id */ | ||
var _proto = TreeReplica.prototype; | ||
_proto.get = function get(id) { | ||
this.tree.get(id); | ||
} | ||
/** | ||
@@ -395,6 +400,4 @@ * Generates an OpMove | ||
*/ | ||
; | ||
var _proto = TreeReplica.prototype; | ||
_proto.opMove = function opMove(id, metadata, parentId) { | ||
@@ -401,0 +404,0 @@ return { |
@@ -13,5 +13,5 @@ import { Clock } from "./Clock"; | ||
tree: import("./Tree").Tree<Id, Metadata>; | ||
constructor(authorId: Id); | ||
/** Get a node by its id */ | ||
get: (id: Id) => import("./TreeNode").TreeNode<Id, Metadata> | undefined; | ||
constructor(authorId: Id); | ||
get(id: Id): void; | ||
/** | ||
@@ -18,0 +18,0 @@ * Generates an OpMove |
@@ -5,3 +5,3 @@ { | ||
"author": "Matan Kushner", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
@@ -26,4 +26,2 @@ // `TreeReplica` holds tree `State` plus lamport timestamp (actor + counter) | ||
tree = this.state.tree; | ||
/** Get a node by its id */ | ||
get = this.tree.get; | ||
@@ -34,2 +32,7 @@ constructor(authorId: Id) { | ||
/** Get a node by its id */ | ||
get(id: Id) { | ||
this.tree.get(id); | ||
} | ||
/** | ||
@@ -36,0 +39,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
119180
1420