@codesandbox/crdt-tree
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -244,4 +244,4 @@ 'use strict'; | ||
/** A node that is stored in a `Tree` */ | ||
// Logically, each `TreeNode` consists of a triple `(parent_id, metadata, child_id)`. | ||
// However, in this implementation, the `child_id` is stored as the | ||
// Logically, each `TreeNode` consists of a triple `(parentId, metadata, childId)`. | ||
// However, in this implementation, the `childId` is stored as the | ||
// keys in `Tree.children` | ||
@@ -400,3 +400,3 @@ var TreeNode = function TreeNode(parentId, metadata) { | ||
* | ||
* To generate multiple ops before calling ::apply_op(), use ::opmoves() instead. | ||
* To generate multiple ops before calling `applyOp`, use `opMoves` instead. | ||
*/ | ||
@@ -414,6 +414,6 @@ ; | ||
/** | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parent_id) | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parentId) | ||
* | ||
* Each timestamp will be greater than the previous op in the returned list. | ||
* Therefore, these operations can be successfully applied via `apply_op()` without | ||
* Therefore, these operations can be successfully applied via `applyOp()` without | ||
* timestamp collision. | ||
@@ -452,3 +452,3 @@ */ | ||
if (op.timestamp <= latestTimeOfActor) { | ||
console.log("Clock not increased, current timestamp " + latestTimeOfActor + ", provided is " + op.timestamp + "."); | ||
console.log("Clock not increased, current timestamp " + latestTimeOfActor.toString() + ", provided is " + op.timestamp.toString() + "."); | ||
console.log("Dropping operation."); | ||
@@ -455,0 +455,0 @@ } else { |
@@ -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.time=new e(t)}var r=t.prototype;return r.get=function(t){return 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; | ||
"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){return 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.toString()+", provided is "+t.timestamp.toString()+"."),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 |
@@ -242,4 +242,4 @@ var Ordering; | ||
/** A node that is stored in a `Tree` */ | ||
// Logically, each `TreeNode` consists of a triple `(parent_id, metadata, child_id)`. | ||
// However, in this implementation, the `child_id` is stored as the | ||
// Logically, each `TreeNode` consists of a triple `(parentId, metadata, childId)`. | ||
// However, in this implementation, the `childId` is stored as the | ||
// keys in `Tree.children` | ||
@@ -398,3 +398,3 @@ var TreeNode = function TreeNode(parentId, metadata) { | ||
* | ||
* To generate multiple ops before calling ::apply_op(), use ::opmoves() instead. | ||
* To generate multiple ops before calling `applyOp`, use `opMoves` instead. | ||
*/ | ||
@@ -412,6 +412,6 @@ ; | ||
/** | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parent_id) | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parentId) | ||
* | ||
* Each timestamp will be greater than the previous op in the returned list. | ||
* Therefore, these operations can be successfully applied via `apply_op()` without | ||
* Therefore, these operations can be successfully applied via `applyOp()` without | ||
* timestamp collision. | ||
@@ -450,3 +450,3 @@ */ | ||
if (op.timestamp <= latestTimeOfActor) { | ||
console.log("Clock not increased, current timestamp " + latestTimeOfActor + ", provided is " + op.timestamp + "."); | ||
console.log("Clock not increased, current timestamp " + latestTimeOfActor.toString() + ", provided is " + op.timestamp.toString() + "."); | ||
console.log("Dropping operation."); | ||
@@ -453,0 +453,0 @@ } else { |
@@ -24,10 +24,10 @@ import { Clock } from "./Clock"; | ||
* | ||
* To generate multiple ops before calling ::apply_op(), use ::opmoves() instead. | ||
* To generate multiple ops before calling `applyOp`, use `opMoves` instead. | ||
*/ | ||
opMove(id: Id, metadata: Metadata, parentId: Id): OpMove<Id, Metadata>; | ||
/** | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parent_id) | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parentId) | ||
* | ||
* Each timestamp will be greater than the previous op in the returned list. | ||
* Therefore, these operations can be successfully applied via `apply_op()` without | ||
* Therefore, these operations can be successfully applied via `applyOp()` without | ||
* timestamp collision. | ||
@@ -34,0 +34,0 @@ */ |
@@ -5,3 +5,3 @@ { | ||
"author": "Matan Kushner", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
// Implements `OpMove`, the only way to manipulate tree data. | ||
// | ||
// `OpMove` are applied via `State`::apply_op() or at a higher | ||
// level via `TreeReplica`::apply_op() | ||
// `OpMove` are applied via `State.applyOp` or at a higher | ||
// level via `TreeReplica.applyOp` | ||
// | ||
@@ -6,0 +6,0 @@ // From the paper[1]: |
/** A node that is stored in a `Tree` */ | ||
// Logically, each `TreeNode` consists of a triple `(parent_id, metadata, child_id)`. | ||
// However, in this implementation, the `child_id` is stored as the | ||
// Logically, each `TreeNode` consists of a triple `(parentId, metadata, childId)`. | ||
// However, in this implementation, the `childId` is stored as the | ||
// keys in `Tree.children` | ||
@@ -5,0 +5,0 @@ export class TreeNode<Id, Metadata> { |
@@ -44,3 +44,3 @@ // `TreeReplica` holds tree `State` plus lamport timestamp (actor + counter) | ||
* | ||
* To generate multiple ops before calling ::apply_op(), use ::opmoves() instead. | ||
* To generate multiple ops before calling `applyOp`, use `opMoves` instead. | ||
*/ | ||
@@ -52,6 +52,6 @@ opMove(id: Id, metadata: Metadata, parentId: Id): OpMove<Id, Metadata> { | ||
/** | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parent_id) | ||
* Generates a list of OpMove from a list of tuples (id, metadata, parentId) | ||
* | ||
* Each timestamp will be greater than the previous op in the returned list. | ||
* Therefore, these operations can be successfully applied via `apply_op()` without | ||
* Therefore, these operations can be successfully applied via `applyOp()` without | ||
* timestamp collision. | ||
@@ -83,3 +83,3 @@ */ | ||
console.log( | ||
`Clock not increased, current timestamp ${latestTimeOfActor}, provided is ${op.timestamp}.` | ||
`Clock not increased, current timestamp ${latestTimeOfActor.toString()}, provided is ${op.timestamp.toString()}.` | ||
); | ||
@@ -86,0 +86,0 @@ console.log("Dropping operation."); |
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
119803