reactotron-core-client
Advanced tools
Comparing version 2.8.11-beta.2 to 2.8.11-beta.3
@@ -5,2 +5,4 @@ # Changelog | ||
### [2.8.11-beta.3](https://github.com/infinitered/reactotron/compare/reactotron-core-client@2.8.11-beta.2...reactotron-core-client@2.8.11-beta.3) (2023-07-03) | ||
### [2.8.11-beta.2](https://github.com/infinitered/reactotron/compare/reactotron-core-client@2.8.11-beta.1...reactotron-core-client@2.8.11-beta.2) (2023-06-15) | ||
@@ -7,0 +9,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread2(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}var isCreateSocketValid=function(a){return"undefined"!=typeof a&&null!==a},isHostValid=function(a){return"string"==typeof a&&a&&""!==a},isPortValid=function(a){return"number"==typeof a&&1<=a&&65535>=a},onCommandValid=function(a){return"function"==typeof a},validate=function(a){var b=a.createSocket,c=a.host,d=a.port,e=a.onCommand;if(!isCreateSocketValid(b))throw new Error("invalid createSocket function");if(!isHostValid(c))throw new Error("invalid host");if(!isPortValid(d))throw new Error("invalid port");if(!onCommandValid(e))throw new Error("invalid onCommand handler")},logger=function(){return function(a){return{features:{log:function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c&&1===c.length?c[0]:c;a.send("log",{level:"debug",message:e},!1)},logImportant:function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c&&1===c.length?c[0]:c;a.send("log",{level:"debug",message:e},!0)},debug:function(b){var c=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return a.send("log",{level:"debug",message:b},!!c)},warn:function(b){return a.send("log",{level:"warn",message:b},!0)},error:function(b,c){return a.send("log",{level:"error",message:b,stack:c},!0)}}}}},image=function(){return function(a){return{features:{image:function(b){var c=b.uri,d=b.preview,e=b.filename,f=b.width,g=b.height,h=b.caption;return a.send("image",{uri:c,preview:d,filename:e,width:f,height:g,caption:h})}}}}},benchmark=function(){return function(a){var b=a.startTimer;return{features:{benchmark:function(c){var d=[],e=b(),f=function(a){var b=0===d.length?0:d[d.length-1].time,c=e();d.push({title:a,time:c,delta:c-b})};d.push({title:c,time:0,delta:0});var g=function(b){f(b),a.send("benchmark.report",{title:c,steps:d})};return{step:f,stop:g,last:g}}}}}},stateResponses=function(){return function(a){return{features:{stateActionComplete:function(b,c){var d=!!(2<arguments.length&&arguments[2]!==void 0)&&arguments[2];return a.send("state.action.complete",{name:b,action:c},!!d)},stateValuesResponse:function(b,c){var d=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];return a.send("state.values.response",{path:b,value:c,valid:d})},stateKeysResponse:function(b,c){var d=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];return a.send("state.keys.response",{path:b,keys:c,valid:d})},stateValuesChange:function(b){return 0<b.length&&a.send("state.values.change",{changes:b})},stateBackupResponse:function(b){return a.send("state.backup.response",{state:b})}}}}},apiResponse=function(){return function(a){return{features:{apiResponse:function(b,c,d){var e=c&&c.status&&"number"==typeof c.status&&200<=c.status&&299>=c.status;a.send("api.response",{request:b,response:c,duration:d},!e)}}}}},clear=function(){return function(a){return{features:{clear:function(){return a.send("clear")}}}}},repl=function(){return function(reactotron){var myRepls={};return{onCommand:function(_ref){var type=_ref.type,payload=_ref.payload;if("repl."===type.substr(0,5))switch(type.substr(5)){case"ls":reactotron.send("repl.ls.response",Object.keys(myRepls));break;case"execute":reactotron.send("repl.execute.response",function(){return eval(payload)}.call(myRepls));}},features:{repl:function(a,b){if(!a)throw new Error("You must provide a name for your REPL");if(myRepls[a])throw new Error("You are already REPLing an item with that name");myRepls[a]=b}}}}},UNDEFINED="~~~ undefined ~~~",NULL="~~~ null ~~~",FALSE="~~~ false ~~~",ZERO="~~~ zero ~~~",EMPTY_STRING="~~~ empty string ~~~",CIRCULAR="~~~ Circular Reference ~~~",ANONYMOUS="~~~ anonymous function ~~~",INFINITY="~~~ Infinity ~~~",NEGATIVE_INFINITY="~~~ -Infinity ~~~";function getFunctionName(a){var b=a.name;return null===b||void 0===b||""===b?ANONYMOUS:"~~~ ".concat(b,"() ~~~")}function serialize(a){var b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1],c=[],d=[];return JSON.stringify(a,function(a){return function(e,f){if(!0===f)return!0;if(f===1/0)return INFINITY;if(f===-Infinity)return NEGATIVE_INFINITY;if(0===f)return ZERO;if(void 0===f)return UNDEFINED;if(null===f)return NULL;if(!1===f)return FALSE;if(-0===f)return ZERO;if(""===f)return EMPTY_STRING;if(b&&"object"===_typeof(f)&&f.nativeEvent)return f.nativeEvent;switch(_typeof(f)){case"string":return f;case"number":return f;case"function":return getFunctionName(f);}if(f[Symbol.iterator]&&!Array.isArray(f))return _toConsumableArray(f);if(0<c.length){var g=c.indexOf(this);~g?c.splice(g+1):c.push(this),~g?d.splice(g,1/0,e):d.push(e),~c.indexOf(f)&&(f=CIRCULAR)}else c.push(f);return null==a?f:a.call(this,e,f)}}(null))}var defaultPerformanceNow=function(){return Date.now()},nativePerformance="undefined"!=typeof window&&window&&(window.performance||window.msPerformance||window.webkitPerformance),performanceNow=defaultPerformanceNow,delta=function(a){return performanceNow()-a};global.nativePerformanceNow?performanceNow=global.nativePerformanceNow:nativePerformance&&(performanceNow=function(){return nativePerformance.now&&nativePerformance.now()});var start=function(){var a=performanceNow();return function(){return delta(a)}},corePlugins=[image(),logger(),benchmark(),stateResponses(),apiResponse(),clear(),repl()],DEFAULT_OPTIONS={createSocket:null,host:"localhost",port:9090,name:"reactotron-core-client",secure:!1,plugins:corePlugins,safeRecursion:!0,onCommand:function(){return null},onConnect:function(){return null},onDisconnect:function(){return null}},reservedFeatures=["options","connected","socket","plugins","configure","connect","send","use","startTimer"],isReservedFeature=function(a){return reservedFeatures.some(function(b){return b===a})};function emptyPromise(){return Promise.resolve("")}exports.ArgType=void 0,function(a){a.String="string"}(exports.ArgType||(exports.ArgType={}));var ReactotronImpl=function(){function a(){var b=this;_classCallCheck(this,a),_defineProperty(this,"options",Object.assign({},DEFAULT_OPTIONS)),_defineProperty(this,"connected",!1),_defineProperty(this,"socket",null),_defineProperty(this,"plugins",[]),_defineProperty(this,"sendQueue",[]),_defineProperty(this,"isReady",!1),_defineProperty(this,"lastMessageDate",new Date),_defineProperty(this,"customCommands",[]),_defineProperty(this,"customCommandLatestId",1),_defineProperty(this,"startTimer",function(){return start()}),_defineProperty(this,"send",function(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},d=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2],e=new Date,f=e.getTime()-b.lastMessageDate.getTime();0>f&&(f=0),b.lastMessageDate=e;var g={type:a,payload:c,important:!!d,date:e.toISOString(),deltaTime:f},h=serialize(g,b.options.proxyHack);if(b.isReady)try{b.socket.send(h)}catch(a){b.isReady=!1,console.log("An error occured communicating with reactotron. Please reload your app")}else b.sendQueue.push(h)})}return _createClass(a,[{key:"configure",value:function(){var a=this,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=Object.assign({},this.options,b);return validate(c),this.options=c,Array.isArray(this.options.plugins)&&this.options.plugins.forEach(function(b){return a.use(b)}),this}},{key:"close",value:function(){this.connected=!1,this.socket&&this.socket.close&&this.socket.close()}},{key:"connect",value:function(){var a=this;this.connected=!0;var b=this.options,c=b.createSocket,d=b.secure,e=b.host,f=b.environment,g=b.port,i=b.name,j=b.client,k=void 0===j?{}:j,l=b.getClientId,m=this.options,n=m.onCommand,o=m.onConnect,p=m.onDisconnect,q=d?"wss":"ws",r=c("".concat(q,"://").concat(e,":").concat(g)),s=function(){o&&o(),a.plugins.forEach(function(a){return a.onConnect&&a.onConnect()});(l||emptyPromise)().then(function(b){for(a.isReady=!0,a.send("client.intro",_objectSpread2(_objectSpread2({environment:f},k),{},{name:i,clientId:b,reactotronCoreClientVersion:"2.8.11-beta.2"}));0<a.sendQueue.length;){var c=a.sendQueue[0];a.sendQueue=a.sendQueue.slice(1),a.socket.send(c)}})},t=function(){a.isReady=!1,p&&p(),a.plugins.forEach(function(a){return a.onDisconnect&&a.onDisconnect()})},u=function(a){return"string"==typeof a?JSON.parse(a):Buffer.isBuffer(a)?JSON.parse(a.toString()):a},v=function(b){var c=u(b);n&&n(c),a.plugins.forEach(function(a){return a.onCommand&&a.onCommand(c)}),"custom"===c.type?a.customCommands.filter(function(a){return"string"==typeof c.payload?a.command===c.payload:a.command===c.payload.command}).forEach(function(a){return a.handler("object"===_typeof(c.payload)?c.payload.args:void 0)}):"setClientId"===c.type&&a.options.setClientId&&a.options.setClientId(c.payload)};if(r.on){var w=r;w.on("open",s),w.on("close",t),w.on("message",v)}else r.onopen=s,r.onclose=t,r.onmessage=function(a){return v(a.data)};return this.socket=r,this}},{key:"display",value:function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=a.name,c=a.value,d=a.preview,e=a.image,f=a.important;this.send("display",{name:b,value:c||null,preview:d||null,image:e||null},void 0!==f&&f)}},{key:"reportError",value:function(a){this.error(a)}},{key:"use",value:function(a){var b=this;if("function"!=typeof a)throw new Error("plugins must be a function");var c=a.bind(this)(this);if("object"!==_typeof(c))throw new Error("plugins must return an object");if(c.features){if("object"!==_typeof(c.features))throw new Error("features must be an object");var d=function(a){var d=c.features[a];if("function"!=typeof d)throw new Error("feature ".concat(a," is not a function"));if(isReservedFeature(a))throw new Error("feature ".concat(a," is a reserved name"));b[a]=d};Object.keys(c.features).forEach(function(a){return d(a)})}return this.plugins.push(c),c.onPlugin&&"function"==typeof c.onPlugin&&c.onPlugin.bind(this)(this),this}},{key:"onCustomCommand",value:function(a,b){var c,d,e,f,g,h=this;if("string"==typeof a?(c=a,d=b):(c=a.command,d=a.handler,e=a.title,f=a.description,g=a.args),!c)throw new Error("A command is required");if(!d)throw new Error("A handler is required for command \"".concat(c,"\""));var i=this.customCommands.filter(function(a){return a.command===c});if(0<i.length&&i.forEach(function(a){console.log(a),h.customCommands=h.customCommands.filter(function(b){return b.id!==a.id}),h.send("customCommand.unregister",{id:a.id,command:a.command})}),g){var j=[];g.forEach(function(a){if(!a.name)throw new Error("A arg on the command \"".concat(c,"\" is missing a name"));if(-1<j.indexOf(a.name))throw new Error("A arg with the name \"".concat(a.name,"\" already exists in the command \"").concat(c,"\""));j.push(a.name)})}var k={id:this.customCommandLatestId,command:c,handler:d,title:e,description:f,args:g};return this.customCommandLatestId+=1,this.customCommands.push(k),this.send("customCommand.register",{id:k.id,command:k.command,title:k.title,description:k.description,args:k.args}),function(){h.customCommands=h.customCommands.filter(function(a){return a.id!==k.id}),h.send("customCommand.unregister",{id:k.id,command:k.command})}}}]),a}();function createClient(a){var b=new ReactotronImpl;return b.configure(a),b}exports.ReactotronImpl=ReactotronImpl,exports.corePlugins=corePlugins,exports.createClient=createClient; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread2(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}var isCreateSocketValid=function(a){return"undefined"!=typeof a&&null!==a},isHostValid=function(a){return"string"==typeof a&&a&&""!==a},isPortValid=function(a){return"number"==typeof a&&1<=a&&65535>=a},onCommandValid=function(a){return"function"==typeof a},validate=function(a){var b=a.createSocket,c=a.host,d=a.port,e=a.onCommand;if(!isCreateSocketValid(b))throw new Error("invalid createSocket function");if(!isHostValid(c))throw new Error("invalid host");if(!isPortValid(d))throw new Error("invalid port");if(!onCommandValid(e))throw new Error("invalid onCommand handler")},logger=function(){return function(a){return{features:{log:function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c&&1===c.length?c[0]:c;a.send("log",{level:"debug",message:e},!1)},logImportant:function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c&&1===c.length?c[0]:c;a.send("log",{level:"debug",message:e},!0)},debug:function(b){var c=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return a.send("log",{level:"debug",message:b},!!c)},warn:function(b){return a.send("log",{level:"warn",message:b},!0)},error:function(b,c){return a.send("log",{level:"error",message:b,stack:c},!0)}}}}},image=function(){return function(a){return{features:{image:function(b){var c=b.uri,d=b.preview,e=b.filename,f=b.width,g=b.height,h=b.caption;return a.send("image",{uri:c,preview:d,filename:e,width:f,height:g,caption:h})}}}}},benchmark=function(){return function(a){var b=a.startTimer;return{features:{benchmark:function(c){var d=[],e=b(),f=function(a){var b=0===d.length?0:d[d.length-1].time,c=e();d.push({title:a,time:c,delta:c-b})};d.push({title:c,time:0,delta:0});var g=function(b){f(b),a.send("benchmark.report",{title:c,steps:d})};return{step:f,stop:g,last:g}}}}}},stateResponses=function(){return function(a){return{features:{stateActionComplete:function(b,c){var d=!!(2<arguments.length&&arguments[2]!==void 0)&&arguments[2];return a.send("state.action.complete",{name:b,action:c},!!d)},stateValuesResponse:function(b,c){var d=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];return a.send("state.values.response",{path:b,value:c,valid:d})},stateKeysResponse:function(b,c){var d=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];return a.send("state.keys.response",{path:b,keys:c,valid:d})},stateValuesChange:function(b){return 0<b.length&&a.send("state.values.change",{changes:b})},stateBackupResponse:function(b){return a.send("state.backup.response",{state:b})}}}}},apiResponse=function(){return function(a){return{features:{apiResponse:function(b,c,d){var e=c&&c.status&&"number"==typeof c.status&&200<=c.status&&299>=c.status;a.send("api.response",{request:b,response:c,duration:d},!e)}}}}},clear=function(){return function(a){return{features:{clear:function(){return a.send("clear")}}}}},repl=function(){return function(reactotron){var myRepls={};return{onCommand:function(_ref){var type=_ref.type,payload=_ref.payload;if("repl."===type.substr(0,5))switch(type.substr(5)){case"ls":reactotron.send("repl.ls.response",Object.keys(myRepls));break;case"execute":reactotron.send("repl.execute.response",function(){return eval(payload)}.call(myRepls));}},features:{repl:function(a,b){if(!a)throw new Error("You must provide a name for your REPL");if(myRepls[a])throw new Error("You are already REPLing an item with that name");myRepls[a]=b}}}}},UNDEFINED="~~~ undefined ~~~",NULL="~~~ null ~~~",FALSE="~~~ false ~~~",ZERO="~~~ zero ~~~",EMPTY_STRING="~~~ empty string ~~~",CIRCULAR="~~~ Circular Reference ~~~",ANONYMOUS="~~~ anonymous function ~~~",INFINITY="~~~ Infinity ~~~",NEGATIVE_INFINITY="~~~ -Infinity ~~~";function getFunctionName(a){var b=a.name;return null===b||void 0===b||""===b?ANONYMOUS:"~~~ ".concat(b,"() ~~~")}function serialize(a){var b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1],c=[],d=[];return JSON.stringify(a,function(a){return function(e,f){if(!0===f)return!0;if(f===1/0)return INFINITY;if(f===-Infinity)return NEGATIVE_INFINITY;if(0===f)return ZERO;if(void 0===f)return UNDEFINED;if(null===f)return NULL;if(!1===f)return FALSE;if(-0===f)return ZERO;if(""===f)return EMPTY_STRING;if(b&&"object"===_typeof(f)&&f.nativeEvent)return f.nativeEvent;switch(_typeof(f)){case"string":return f;case"number":return f;case"function":return getFunctionName(f);}if(f[Symbol.iterator]&&!Array.isArray(f))return _toConsumableArray(f);if(0<c.length){var g=c.indexOf(this);~g?c.splice(g+1):c.push(this),~g?d.splice(g,1/0,e):d.push(e),~c.indexOf(f)&&(f=CIRCULAR)}else c.push(f);return null==a?f:a.call(this,e,f)}}(null))}var defaultPerformanceNow=function(){return Date.now()},nativePerformance="undefined"!=typeof window&&window&&(window.performance||window.msPerformance||window.webkitPerformance),performanceNow=defaultPerformanceNow,delta=function(a){return performanceNow()-a};global.nativePerformanceNow?performanceNow=global.nativePerformanceNow:nativePerformance&&(performanceNow=function(){return nativePerformance.now&&nativePerformance.now()});var start=function(){var a=performanceNow();return function(){return delta(a)}},corePlugins=[image(),logger(),benchmark(),stateResponses(),apiResponse(),clear(),repl()],DEFAULT_OPTIONS={createSocket:null,host:"localhost",port:9090,name:"reactotron-core-client",secure:!1,plugins:corePlugins,safeRecursion:!0,onCommand:function(){return null},onConnect:function(){return null},onDisconnect:function(){return null}},reservedFeatures=["options","connected","socket","plugins","configure","connect","send","use","startTimer"],isReservedFeature=function(a){return reservedFeatures.some(function(b){return b===a})};function emptyPromise(){return Promise.resolve("")}exports.ArgType=void 0,function(a){a.String="string"}(exports.ArgType||(exports.ArgType={}));var ReactotronImpl=function(){function a(){var b=this;_classCallCheck(this,a),_defineProperty(this,"options",Object.assign({},DEFAULT_OPTIONS)),_defineProperty(this,"connected",!1),_defineProperty(this,"socket",null),_defineProperty(this,"plugins",[]),_defineProperty(this,"sendQueue",[]),_defineProperty(this,"isReady",!1),_defineProperty(this,"lastMessageDate",new Date),_defineProperty(this,"customCommands",[]),_defineProperty(this,"customCommandLatestId",1),_defineProperty(this,"startTimer",function(){return start()}),_defineProperty(this,"send",function(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},d=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2],e=new Date,f=e.getTime()-b.lastMessageDate.getTime();0>f&&(f=0),b.lastMessageDate=e;var g={type:a,payload:c,important:!!d,date:e.toISOString(),deltaTime:f},h=serialize(g,b.options.proxyHack);if(b.isReady)try{b.socket.send(h)}catch(a){b.isReady=!1,console.log("An error occured communicating with reactotron. Please reload your app")}else b.sendQueue.push(h)})}return _createClass(a,[{key:"configure",value:function(){var a=this,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=Object.assign({},this.options,b);return validate(c),this.options=c,Array.isArray(this.options.plugins)&&this.options.plugins.forEach(function(b){return a.use(b)}),this}},{key:"close",value:function(){this.connected=!1,this.socket&&this.socket.close&&this.socket.close()}},{key:"connect",value:function(){var a=this;this.connected=!0;var b=this.options,c=b.createSocket,d=b.secure,e=b.host,f=b.environment,g=b.port,i=b.name,j=b.client,k=void 0===j?{}:j,l=b.getClientId,m=this.options,n=m.onCommand,o=m.onConnect,p=m.onDisconnect,q=d?"wss":"ws",r=c("".concat(q,"://").concat(e,":").concat(g)),s=function(){o&&o(),a.plugins.forEach(function(a){return a.onConnect&&a.onConnect()});(l||emptyPromise)().then(function(b){for(a.isReady=!0,a.send("client.intro",_objectSpread2(_objectSpread2({environment:f},k),{},{name:i,clientId:b,reactotronCoreClientVersion:"2.8.11-beta.3"}));0<a.sendQueue.length;){var c=a.sendQueue[0];a.sendQueue=a.sendQueue.slice(1),a.socket.send(c)}})},t=function(){a.isReady=!1,p&&p(),a.plugins.forEach(function(a){return a.onDisconnect&&a.onDisconnect()})},u=function(a){return"string"==typeof a?JSON.parse(a):Buffer.isBuffer(a)?JSON.parse(a.toString()):a},v=function(b){var c=u(b);n&&n(c),a.plugins.forEach(function(a){return a.onCommand&&a.onCommand(c)}),"custom"===c.type?a.customCommands.filter(function(a){return"string"==typeof c.payload?a.command===c.payload:a.command===c.payload.command}).forEach(function(a){return a.handler("object"===_typeof(c.payload)?c.payload.args:void 0)}):"setClientId"===c.type&&a.options.setClientId&&a.options.setClientId(c.payload)};if(r.on){var w=r;w.on("open",s),w.on("close",t),w.on("message",v)}else r.onopen=s,r.onclose=t,r.onmessage=function(a){return v(a.data)};return this.socket=r,this}},{key:"display",value:function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=a.name,c=a.value,d=a.preview,e=a.image,f=a.important;this.send("display",{name:b,value:c||null,preview:d||null,image:e||null},void 0!==f&&f)}},{key:"reportError",value:function(a){this.error(a)}},{key:"use",value:function(a){var b=this;if("function"!=typeof a)throw new Error("plugins must be a function");var c=a.bind(this)(this);if("object"!==_typeof(c))throw new Error("plugins must return an object");if(c.features){if("object"!==_typeof(c.features))throw new Error("features must be an object");var d=function(a){var d=c.features[a];if("function"!=typeof d)throw new Error("feature ".concat(a," is not a function"));if(isReservedFeature(a))throw new Error("feature ".concat(a," is a reserved name"));b[a]=d};Object.keys(c.features).forEach(function(a){return d(a)})}return this.plugins.push(c),c.onPlugin&&"function"==typeof c.onPlugin&&c.onPlugin.bind(this)(this),this}},{key:"onCustomCommand",value:function(a,b){var c,d,e,f,g,h=this;if("string"==typeof a?(c=a,d=b):(c=a.command,d=a.handler,e=a.title,f=a.description,g=a.args),!c)throw new Error("A command is required");if(!d)throw new Error("A handler is required for command \"".concat(c,"\""));var i=this.customCommands.filter(function(a){return a.command===c});if(0<i.length&&i.forEach(function(a){console.log(a),h.customCommands=h.customCommands.filter(function(b){return b.id!==a.id}),h.send("customCommand.unregister",{id:a.id,command:a.command})}),g){var j=[];g.forEach(function(a){if(!a.name)throw new Error("A arg on the command \"".concat(c,"\" is missing a name"));if(-1<j.indexOf(a.name))throw new Error("A arg with the name \"".concat(a.name,"\" already exists in the command \"").concat(c,"\""));j.push(a.name)})}var k={id:this.customCommandLatestId,command:c,handler:d,title:e,description:f,args:g};return this.customCommandLatestId+=1,this.customCommands.push(k),this.send("customCommand.register",{id:k.id,command:k.command,title:k.title,description:k.description,args:k.args}),function(){h.customCommands=h.customCommands.filter(function(a){return a.id!==k.id}),h.send("customCommand.unregister",{id:k.id,command:k.command})}}}]),a}();function createClient(a){var b=new ReactotronImpl;return b.configure(a),b}exports.ReactotronImpl=ReactotronImpl,exports.corePlugins=corePlugins,exports.createClient=createClient; |
{ | ||
"name": "reactotron-core-client", | ||
"version": "2.8.11-beta.2", | ||
"version": "2.8.11-beta.3", | ||
"description": "Grants Reactotron clients the ability to talk to a Reactotron server.", | ||
@@ -5,0 +5,0 @@ "author": "Infinite Red", |
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
45091
0