@roomservice/core
Advanced tools
Comparing version 0.2.1-0 to 0.2.1
@@ -144,2 +144,3 @@ 'use strict'; | ||
var keyword = cmd[0]; | ||
var MALFORMED = 'Malformed command '; | ||
@@ -149,3 +150,3 @@ switch (keyword) { | ||
if (cmd.length !== 5) { | ||
console.error('Malformed command ', cmd); | ||
console.error(MALFORMED, cmd); | ||
break; | ||
@@ -161,3 +162,3 @@ } | ||
if (cmd.length !== 4) { | ||
console.error('Malformed command ', cmd); | ||
console.error(MALFORMED, cmd); | ||
break; | ||
@@ -169,3 +170,8 @@ } | ||
break; | ||
// These are technically "valid" in some places | ||
// but can be ignored here | ||
case 'mcreate': | ||
break; | ||
default: | ||
@@ -605,3 +611,8 @@ throw new Error('Unexpected command keyword: ' + keyword); | ||
break; | ||
// These are technically "valid" in some places | ||
// but can be ignored here | ||
case 'lcreate': | ||
break; | ||
default: | ||
@@ -608,0 +619,0 @@ throw new Error('Unexpected command keyword: ' + keyword); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("tiny-invariant"))&&"object"==typeof t&&"default"in t?t.default:t,r=function(){function t(t){this.stringToB64=t}var e=t.prototype;return e.base64toArrayBuffer=function(t){for(var e=this.stringToB64(t),r=e.length,n=new Uint8Array(r),o=0;o<r;o++)n[o]=e.charCodeAt(o);return n.buffer},e.isOlderVS=function(t,e){if(!t)return!0;if(!e)return!1;for(var r=new Uint8Array(this.base64toArrayBuffer(t).slice(0,9)),n=new Uint8Array(this.base64toArrayBuffer(e).slice(0,9)),o=0;o<r.byteLength;o++){if(n[o]>r[o])return!0;if(n[o]<r[o])return!1}return!1},t}();function n(t){return JSON.stringify(t)}function o(t){try{return JSON.parse(t)}catch(e){return t}}var i={validateCommand:function(t,e){if(e.length<3)throw new Error("Unexpected command: "+e);if(e[1]!==t.docID||e[2]!==t.mapID)throw new Error("Command unexpectedly routed to the wrong client")},applyCommand:function(t,e){var r=e[0];switch(r){case"mput":if(5!==e.length){console.error("Malformed command ",e);break}t[e[3]]=o(e[4]);break;case"mdel":if(4!==e.length){console.error("Malformed command ",e);break}delete t[e[3]];break;default:throw new Error("Unexpected command keyword: "+r)}},newMap:function(t,e){return{cmd:["mcreate",t,e],meta:{docID:t,mapID:e},store:{}}},importFromRawCheckpoint:function(t,e,r){for(var n=0,i=Object.keys(t);n<i.length;n++)delete t[i[n]];if(e.maps[r])for(var a in e.maps[r]){var s=e.maps[r][a];"string"==typeof s&&(t[a]=o(s))}},runSet:function(t,e,r,o){var i=n(o);return t[r]=o,["mput",e.docID,e.mapID,r,i]},runDelete:function(t,e,r){return delete t[r],["mdel",e.docID,e.mapID,r]}};function a(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 s(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return a(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)?a(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.")}return(r=t[Symbol.iterator]()).next.bind(r)}function u(t,e){if("root"===e)return"root";var r=e.split(":");return r[0]+":"+t.actors[parseInt(r[1])]}var c=function(){function t(t){this.count=0,this.actor=t,this.nodes={},this.log=[]}var r,n=t.prototype;return n.import=function(t,r){t||e(!1),this.log=[],this.nodes={},this.count=0;for(var n=t.lists[r],o=n.afters||[],i=n.ids||[],a=n.values||[],s=0;s<o.length;s++){var c={after:u(t,o[s]),id:u(t,i[s]),value:a[s]};this.nodes[c.id]=c,this.log.push(c)}this.count=this.log.length},n.get=function(t){if(this.nodes[t])return this.nodes[t].value},n.insert=function(t,r,n){this.log||e(!1);var o=n;o||(o=this.count+":"+this.actor),this.count++;var i={after:t,value:r,id:o};return this.nodes[o]=i,this.log.push(i),o},n.put=function(t,e){this.nodes[t]&&(this.nodes[t].value=e)},n.has=function(t){return!!this.nodes[t]},n.delete=function(t){this.nodes[t]&&(this.nodes[t].value={t:""})},n.toTree=function(){for(var t,e=new Map,r=new Map,n=s(this.log);!(t=n()).done;){var o,i=t.value;e.has(i.after)||e.set(i.after,[]),null==(o=e.get(i.after))||o.push(i.id),r.set(i.id,i.value)}return e.forEach((function(t){t.sort((function(t,e){var r=t.split(":"),n=r[0],o=r[1],i=e.split(":"),a=i[0];return n===a?o.localeCompare(i[1]):parseInt(a)-parseInt(n)}))})),{childrenById:e,valueById:r}},n.lastID=function(){return 0===this.log.length?"root":function t(e,r){var n=e.childrenById.get(r);return n&&0!==n.length?t(e,n[n.length-1]):r}(this.toTree(),"root")},n.preOrderTraverse=function(){var t=this.toTree(),e=new Set;return function t(r,n){if(e.has(n))return console.warn("RoomService list cycle detected. Consider updating @roomservice/browser."),[];e.add(n);var o=[],i=r.valueById.get(n);if(i)if("string"==typeof i)o.push({value:i,id:n});else if(!("t"in i)||""!==i.t)throw new Error("Unimplemented");var a=r.childrenById.get(n);if(!a||0===a.length)return o;for(var u,c=s(a);!(u=c()).done;)o=o.concat(t(r,u.value));return o}(t,"root")},n.toArray=function(){return this.preOrderTraverse().map((function(t){return t.value}))},(r=[{key:"length",get:function(){return Object.keys(this.nodes).length}}])&&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,r),t}();function l(t,e,r,o){if(r<0)throw"Negative indices unsupported";var i;if(!(i=0==r?"root":t.itemIDs[r-1]))throw new RangeError("List '"+e.listID+"' has no index: '"+r+"'");var a=n(o),s=t.rt.insert(i,a);return t.itemIDs.splice(r,0,s),["lins",e.docID,e.listID,i,s,a]}function f(t,e,r){var o=t.rt.lastID(),i=n(r),a=t.rt.insert(o,i);return t.itemIDs.push(a),["lins",e.docID,e.listID,o,a,i]}exports.ListInterpreter={importFromRawCheckpoint:function(t,e,r){if(t.itemIDs=[],e.lists[r]){t.rt.import(e,r);for(var n=e.lists[r].ids||[],o=0;o<n.length;o++){var i=e.lists[r].values[o];"object"==typeof i&&""===i.t||t.itemIDs.push(u(e,n[o]))}}},validateCommand:function(t,e){if(e.length<3)throw new Error("Unexpected command: "+e);if(e[1]!==t.docID||e[2]!==t.listID)throw new Error("Command unexpectedly routed to the wrong client")},applyCommand:function(t,e){var r=e[0];switch(r){case"lins":var n=e[3],o=e[4],i=e[5];t.itemIDs.splice(t.itemIDs.findIndex((function(t){return t===n}))+1,0,o),t.rt.insert(n,i,o);break;case"lput":t.rt.put(e[3],e[4]);break;case"ldel":var a=e[3];t.rt.delete(a),t.itemIDs.splice(t.itemIDs.findIndex((function(t){return t===a})),1);break;default:throw new Error("Unexpected command keyword: "+r)}},get:function(t,e){var r=t.itemIDs[e];if(r){var n=t.rt.get(r);if(n){if("object"==typeof n){if(""===n.t)return;throw new Error("Unimplemented references")}return o(n)}}},map:function(t,e){return t.rt.preOrderTraverse().map((function(t,r){return e(o(t.value),r,t.id)}))},toArray:function(t){return t.rt.toArray().map((function(t){return o(t)}))},newList:function(t,e,r){return{store:{itemIDs:[],rt:new c(r)},meta:{docID:t,listID:e},cmd:["mcreate",t,e]}},runSet:function(t,e,r,o){var i=t.itemIDs[r];if(!i)throw new Error("Index '"+r+"' doesn't already exist. Try .push() or .insertAfter() instead.");var a=n(o);return t.rt.put(i,a),["lput",e.docID,e.listID,i,a]},runDelete:function(t,e,r){if(0===t.itemIDs.length)return!1;var n=t.itemIDs[r];return n?(t.rt.delete(n),t.itemIDs.splice(r,1),["ldel",e.docID,e.listID,n]):(console.warn("Unknown index: ",r,t.itemIDs),!1)},runInsertAt:l,runInsertAfter:function(t,e,r,n){return l(t,e,r+1,n)},runPush:function(t,e){for(var r=[],n=arguments.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];for(var a=0,s=o;a<s.length;a++){var u=s[a];r.push(f(t,e,u))}return r}},exports.MapInterpreter=i,exports.vsReader=function(t){return new r(t)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("tiny-invariant"))&&"object"==typeof e&&"default"in e?e.default:e,r=function(){function e(e){this.stringToB64=e}var t=e.prototype;return t.base64toArrayBuffer=function(e){for(var t=this.stringToB64(e),r=t.length,n=new Uint8Array(r),o=0;o<r;o++)n[o]=t.charCodeAt(o);return n.buffer},t.isOlderVS=function(e,t){if(!e)return!0;if(!t)return!1;for(var r=new Uint8Array(this.base64toArrayBuffer(e).slice(0,9)),n=new Uint8Array(this.base64toArrayBuffer(t).slice(0,9)),o=0;o<r.byteLength;o++){if(n[o]>r[o])return!0;if(n[o]<r[o])return!1}return!1},e}();function n(e){return JSON.stringify(e)}function o(e){try{return JSON.parse(e)}catch(t){return e}}var i={validateCommand:function(e,t){if(t.length<3)throw new Error("Unexpected command: "+t);if(t[1]!==e.docID||t[2]!==e.mapID)throw new Error("Command unexpectedly routed to the wrong client")},applyCommand:function(e,t){var r=t[0];switch(r){case"mput":if(5!==t.length){console.error("Malformed command ",t);break}e[t[3]]=o(t[4]);break;case"mdel":if(4!==t.length){console.error("Malformed command ",t);break}delete e[t[3]];break;case"mcreate":break;default:throw new Error("Unexpected command keyword: "+r)}},newMap:function(e,t){return{cmd:["mcreate",e,t],meta:{docID:e,mapID:t},store:{}}},importFromRawCheckpoint:function(e,t,r){for(var n=0,i=Object.keys(e);n<i.length;n++)delete e[i[n]];if(t.maps[r])for(var a in t.maps[r]){var s=t.maps[r][a];"string"==typeof s&&(e[a]=o(s))}},runSet:function(e,t,r,o){var i=n(o);return e[r]=o,["mput",t.docID,t.mapID,r,i]},runDelete:function(e,t,r){return delete e[r],["mdel",t.docID,t.mapID,r]}};function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return a(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[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.")}return(r=e[Symbol.iterator]()).next.bind(r)}function u(e,t){if("root"===t)return"root";var r=t.split(":");return r[0]+":"+e.actors[parseInt(r[1])]}var c=function(){function e(e){this.count=0,this.actor=e,this.nodes={},this.log=[]}var r,n=e.prototype;return n.import=function(e,r){e||t(!1),this.log=[],this.nodes={},this.count=0;for(var n=e.lists[r],o=n.afters||[],i=n.ids||[],a=n.values||[],s=0;s<o.length;s++){var c={after:u(e,o[s]),id:u(e,i[s]),value:a[s]};this.nodes[c.id]=c,this.log.push(c)}this.count=this.log.length},n.get=function(e){if(this.nodes[e])return this.nodes[e].value},n.insert=function(e,r,n){this.log||t(!1);var o=n;o||(o=this.count+":"+this.actor),this.count++;var i={after:e,value:r,id:o};return this.nodes[o]=i,this.log.push(i),o},n.put=function(e,t){this.nodes[e]&&(this.nodes[e].value=t)},n.has=function(e){return!!this.nodes[e]},n.delete=function(e){this.nodes[e]&&(this.nodes[e].value={t:""})},n.toTree=function(){for(var e,t=new Map,r=new Map,n=s(this.log);!(e=n()).done;){var o,i=e.value;t.has(i.after)||t.set(i.after,[]),null==(o=t.get(i.after))||o.push(i.id),r.set(i.id,i.value)}return t.forEach((function(e){e.sort((function(e,t){var r=e.split(":"),n=r[0],o=r[1],i=t.split(":"),a=i[0];return n===a?o.localeCompare(i[1]):parseInt(a)-parseInt(n)}))})),{childrenById:t,valueById:r}},n.lastID=function(){return 0===this.log.length?"root":function e(t,r){var n=t.childrenById.get(r);return n&&0!==n.length?e(t,n[n.length-1]):r}(this.toTree(),"root")},n.preOrderTraverse=function(){var e=this.toTree(),t=new Set;return function e(r,n){if(t.has(n))return console.warn("RoomService list cycle detected. Consider updating @roomservice/browser."),[];t.add(n);var o=[],i=r.valueById.get(n);if(i)if("string"==typeof i)o.push({value:i,id:n});else if(!("t"in i)||""!==i.t)throw new Error("Unimplemented");var a=r.childrenById.get(n);if(!a||0===a.length)return o;for(var u,c=s(a);!(u=c()).done;)o=o.concat(e(r,u.value));return o}(e,"root")},n.toArray=function(){return this.preOrderTraverse().map((function(e){return e.value}))},(r=[{key:"length",get:function(){return Object.keys(this.nodes).length}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(e.prototype,r),e}();function l(e,t,r,o){if(r<0)throw"Negative indices unsupported";var i;if(!(i=0==r?"root":e.itemIDs[r-1]))throw new RangeError("List '"+t.listID+"' has no index: '"+r+"'");var a=n(o),s=e.rt.insert(i,a);return e.itemIDs.splice(r,0,s),["lins",t.docID,t.listID,i,s,a]}function f(e,t,r){var o=e.rt.lastID(),i=n(r),a=e.rt.insert(o,i);return e.itemIDs.push(a),["lins",t.docID,t.listID,o,a,i]}exports.ListInterpreter={importFromRawCheckpoint:function(e,t,r){if(e.itemIDs=[],t.lists[r]){e.rt.import(t,r);for(var n=t.lists[r].ids||[],o=0;o<n.length;o++){var i=t.lists[r].values[o];"object"==typeof i&&""===i.t||e.itemIDs.push(u(t,n[o]))}}},validateCommand:function(e,t){if(t.length<3)throw new Error("Unexpected command: "+t);if(t[1]!==e.docID||t[2]!==e.listID)throw new Error("Command unexpectedly routed to the wrong client")},applyCommand:function(e,t){var r=t[0];switch(r){case"lins":var n=t[3],o=t[4],i=t[5];e.itemIDs.splice(e.itemIDs.findIndex((function(e){return e===n}))+1,0,o),e.rt.insert(n,i,o);break;case"lput":e.rt.put(t[3],t[4]);break;case"ldel":var a=t[3];e.rt.delete(a),e.itemIDs.splice(e.itemIDs.findIndex((function(e){return e===a})),1);break;case"lcreate":break;default:throw new Error("Unexpected command keyword: "+r)}},get:function(e,t){var r=e.itemIDs[t];if(r){var n=e.rt.get(r);if(n){if("object"==typeof n){if(""===n.t)return;throw new Error("Unimplemented references")}return o(n)}}},map:function(e,t){return e.rt.preOrderTraverse().map((function(e,r){return t(o(e.value),r,e.id)}))},toArray:function(e){return e.rt.toArray().map((function(e){return o(e)}))},newList:function(e,t,r){return{store:{itemIDs:[],rt:new c(r)},meta:{docID:e,listID:t},cmd:["mcreate",e,t]}},runSet:function(e,t,r,o){var i=e.itemIDs[r];if(!i)throw new Error("Index '"+r+"' doesn't already exist. Try .push() or .insertAfter() instead.");var a=n(o);return e.rt.put(i,a),["lput",t.docID,t.listID,i,a]},runDelete:function(e,t,r){if(0===e.itemIDs.length)return!1;var n=e.itemIDs[r];return n?(e.rt.delete(n),e.itemIDs.splice(r,1),["ldel",t.docID,t.listID,n]):(console.warn("Unknown index: ",r,e.itemIDs),!1)},runInsertAt:l,runInsertAfter:function(e,t,r,n){return l(e,t,r+1,n)},runPush:function(e,t){for(var r=[],n=arguments.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];for(var a=0,s=o;a<s.length;a++){var u=s[a];r.push(f(e,t,u))}return r}},exports.MapInterpreter=i,exports.vsReader=function(e){return new r(e)}; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -138,2 +138,3 @@ import invariant from 'tiny-invariant'; | ||
var keyword = cmd[0]; | ||
var MALFORMED = 'Malformed command '; | ||
@@ -143,3 +144,3 @@ switch (keyword) { | ||
if (cmd.length !== 5) { | ||
console.error('Malformed command ', cmd); | ||
console.error(MALFORMED, cmd); | ||
break; | ||
@@ -155,3 +156,3 @@ } | ||
if (cmd.length !== 4) { | ||
console.error('Malformed command ', cmd); | ||
console.error(MALFORMED, cmd); | ||
break; | ||
@@ -163,3 +164,8 @@ } | ||
break; | ||
// These are technically "valid" in some places | ||
// but can be ignored here | ||
case 'mcreate': | ||
break; | ||
default: | ||
@@ -599,3 +605,8 @@ throw new Error('Unexpected command keyword: ' + keyword); | ||
break; | ||
// These are technically "valid" in some places | ||
// but can be ignored here | ||
case 'lcreate': | ||
break; | ||
default: | ||
@@ -602,0 +613,0 @@ throw new Error('Unexpected command keyword: ' + keyword); |
{ | ||
"version": "0.2.1-0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -115,2 +115,6 @@ import { unescape, escape } from './escape'; | ||
break; | ||
// These are technically "valid" in some places | ||
// but can be ignored here | ||
case 'lcreate': | ||
break; | ||
default: | ||
@@ -117,0 +121,0 @@ throw new Error('Unexpected command keyword: ' + keyword); |
@@ -62,6 +62,8 @@ import { unescape, escape } from './escape'; | ||
const MALFORMED = 'Malformed command ' | ||
switch (keyword) { | ||
case 'mput': | ||
if (cmd.length !== 5) { | ||
console.error('Malformed command ', cmd); | ||
console.error(MALFORMED, cmd); | ||
break; | ||
@@ -75,3 +77,3 @@ } | ||
if (cmd.length !== 4) { | ||
console.error('Malformed command ', cmd); | ||
console.error(MALFORMED, cmd); | ||
break; | ||
@@ -82,2 +84,6 @@ } | ||
break; | ||
// These are technically "valid" in some places | ||
// but can be ignored here | ||
case 'mcreate': | ||
break; | ||
default: | ||
@@ -84,0 +90,0 @@ throw new Error('Unexpected command keyword: ' + keyword); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
172656
2472
0