reactotron-core-client
Advanced tools
Comparing version 2.0.0-beta.4 to 2.0.0-beta.5
@@ -1,2 +0,2 @@ | ||
"use strict";function getFunctionName(e){var n=e.name;return null===n||void 0===n||""===n?ANONYMOUS:"~~~ "+n+"() ~~~"}function serialize(e){var n=[],t=[];return JSON.stringify(e,function(e){return function(r,o){if(!0===o)return!0;if(o===1/0)return INFINITY;if(o===-1/0)return NEGATIVE_INFINITY;if(0===o)return ZERO;if(void 0===o)return UNDEFINED;if(null===o)return NULL;if(!1===o)return FALSE;if(-0===o)return ZERO;if(""===o)return EMPTY_STRING;switch(typeof o){case"string":case"number":return o;case"function":return getFunctionName(o)}if(n.length>0){var i=n.indexOf(this);~i?n.splice(i+1):n.push(this),~i?t.splice(i,1/0,r):t.push(r),~n.indexOf(o)&&(o=CIRCULAR)}else n.push(o);return null==e?o:e.call(this,r,o)}}(null))}Object.defineProperty(exports,"__esModule",{value:!0});var isCreateSocketValid=function(e){return void 0!==e&&null!==e},isHostValid=function(e){return"string"==typeof e&&e&&""!==e},isPortValid=function(e){return"number"==typeof e&&e>=1&&e<=65535},onCommandValid=function(e){return"function"==typeof e},validate=function(e){var n=e.createSocket,t=e.host,r=e.port,o=e.onCommand;if(!isCreateSocketValid(n))throw new Error("invalid createSocket function");if(!isHostValid(t))throw new Error("invalid host");if(!isPortValid(r))throw new Error("invalid port");if(!onCommandValid(o))throw new Error("invalid onCommand handler")},logger=function(){return function(e){return{features:{log:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=n&&1===n.length?n[0]:n;e.send("log",{level:"debug",message:r},!1)},logImportant:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=n&&1===n.length?n[0]:n;e.send("log",{level:"debug",message:r},!0)},debug:function(n,t){return void 0===t&&(t=!1),e.send("log",{level:"debug",message:n},!!t)},warn:function(n){return e.send("log",{level:"warn",message:n},!0)},error:function(n,t){return e.send("log",{level:"error",message:n,stack:t},!0)}}}}},image=function(){return function(e){return{features:{image:function(n){var t=n.uri,r=n.preview,o=n.filename,i=n.width,s=n.height,u=n.caption;return e.send("image",{uri:t,preview:r,filename:o,width:i,height:s,caption:u})}}}}},benchmark=function(){return function(e){var n=e.startTimer;return{features:{benchmark:function(t){var r=[],o=n(),i=function(e){var n=0===r.length?0:r[r.length-1].time,t=o();r.push({title:e,time:t,delta:t-n})};r.push({title:t,time:0,delta:0});var s=function(n){i(n),e.send("benchmark.report",{title:t,steps:r})};return{step:i,stop:s,last:s}}}}}},stateResponses=function(){return function(e){return{features:{stateActionComplete:function(n,t,r){return void 0===r&&(r=!1),e.send("state.action.complete",{name:n,action:t},!!r)},stateValuesResponse:function(n,t,r){return void 0===r&&(r=!0),e.send("state.values.response",{path:n,value:t,valid:r})},stateKeysResponse:function(n,t,r){return void 0===r&&(r=!0),e.send("state.keys.response",{path:n,keys:t,valid:r})},stateValuesChange:function(n){return e.send("state.values.change",{changes:n})},stateBackupResponse:function(n){return e.send("state.backup.response",{state:n})}}}}},apiResponse=function(){return function(e){return{features:{apiResponse:function(n,t,r){var o=!(t&&t.status&&"number"==typeof t.status&&t.status>=200&&t.status<=299);e.send("api.response",{request:n,response:t,duration:r},o)}}}}},clear=function(){return function(e){return{features:{clear:function(){return e.send("clear")}}}}},UNDEFINED="~~~ undefined ~~~",NULL="~~~ null ~~~",FALSE="~~~ false ~~~",ZERO="~~~ zero ~~~",EMPTY_STRING="~~~ empty string ~~~",CIRCULAR="~~~ Circular Reference ~~~",ANONYMOUS="~~~ anonymous function ~~~",INFINITY="~~~ Infinity ~~~",NEGATIVE_INFINITY="~~~ -Infinity ~~~",hasHirezNodeTimer=!1,defaultPerformanceNow=function(e){return Date.now()},nativePerformance="undefined"!=typeof window&&window&&(window.performance||window.msPerformance||window.webkitPerformance),performanceNow=defaultPerformanceNow,delta=function(e){return performanceNow()-e};hasHirezNodeTimer?(performanceNow=process.hrtime,delta=function(e){return performanceNow(e)[1]/1e6}):global.nativePerformanceNow?performanceNow=global.nativePerformanceNow:nativePerformance&&(performanceNow=function(){return nativePerformance.now&&nativePerformance.now()});var start=function(){var e=performanceNow();return function(){return delta(e)}},corePlugins=[image(),logger(),benchmark(),stateResponses(),apiResponse(),clear()],DEFAULT_OPTIONS={createSocket:null,host:"localhost",port:9090,name:"reactotron-core-client",secure:!1,plugins:corePlugins,safeRecursion:!0,onCommand:function(e){return null},onConnect:function(){return null},onDisconnect:function(){return null}},reservedFeatures=["options","connected","socket","plugins","configure","connect","send","use","startTimer"],isReservedFeature=function(e){return reservedFeatures.some(function(n){return n===e})},Client=function(){function e(){var e=this;this.options=Object.assign({},DEFAULT_OPTIONS),this.connected=!1,this.socket=null,this.plugins=[],this.sendQueue=[],this.isReady=!1,this.lastMessageDate=new Date,this.startTimer=function(){return start()},this.send=function(n,t,r){if(void 0===t&&(t={}),void 0===r&&(r=!1),e.socket){var o=new Date,i=o.getTime()-e.lastMessageDate.getTime();i<0&&(i=0),e.lastMessageDate=o;var s=serialize({type:n,payload:t,important:!!r,date:o.toISOString(),deltaTime:i});e.isReady?e.socket.send(s):e.sendQueue.push(s)}}}return e.prototype.configure=function(e){var n=this;void 0===e&&(e={});var t=Object.assign({},this.options,e);return validate(t),this.options=t,Array.isArray(this.options.plugins)&&this.options.plugins.forEach(function(e){return n.use(e)}),this},e.prototype.connect=function(){var e=this;this.connected=!0;var n=this.options,t=n.createSocket,r=n.secure,o=n.host,i=n.port,s=n.name,u=n.userAgent,a=n.environment,c=n.reactotronVersion,f=this.options,l=f.onCommand,p=f.onConnect,d=f.onDisconnect,m=t((r?"wss":"ws")+"://"+o+":"+i),h=function(){for(p&&p(),e.plugins.forEach(function(e){return e.onConnect&&e.onConnect()}),e.isReady=!0,e.send("client.intro",{host:o,port:i,name:s,userAgent:u,reactotronVersion:c,environment:a});e.sendQueue.length>0;){var n=e.sendQueue[0];e.sendQueue=e.sendQueue.slice(1),e.socket.send(n)}},g=function(){e.isReady=!1,d&&d(),e.plugins.forEach(function(e){return e.onDisconnect&&e.onDisconnect()})},v=function(n){var t=JSON.parse(n);l&&l(t),e.plugins.forEach(function(e){return e.onCommand&&e.onCommand(t)})};return m.on?(m.on("open",h),m.on("close",g),m.on("message",v)):(m.onopen=h,m.onclose=g,m.onmessage=function(e){return v(e.data)}),this.socket=m,this},e.prototype.display=function(e){void 0===e&&(e={});var n=e.name,t=e.value,r=e.preview,o=e.image,i=e.important,s=void 0!==i&&i,u={name:n,value:t||null,preview:r||null,image:o||null};this.send("display",u,s)},e.prototype.reportError=function(e){this.error(e)},e.prototype.use=function(e){var n=this;if("function"!=typeof e)throw new Error("plugins must be a function");var t=e.bind(this)(this);if("object"!=typeof t)throw new Error("plugins must return an object");if(t.features){if("object"!=typeof t.features)throw new Error("features must be an object");var r=function(e){var r=t.features[e];if("function"!=typeof r)throw new Error("feature "+e+" is not a function");if(isReservedFeature(e))throw new Error("feature "+e+" is a reserved name");n[e]=r};Object.keys(t.features).forEach(function(e){return r(e)})}return this.plugins.push(t),t.onPlugin&&"function"==typeof t.onPlugin&&t.onPlugin.bind(this)(this),this},e}(),createClient=function(e){var n=new Client;return n.configure(e),n};exports.corePlugins=corePlugins,exports.Client=Client,exports.createClient=createClient; | ||
"use strict";function logger(){return function(e){return{features:{log:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=n&&1===n.length?n[0]:n;e.send("log",{level:"debug",message:r},!1)},logImportant:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=n&&1===n.length?n[0]:n;e.send("log",{level:"debug",message:r},!0)},debug:function(n,t){return void 0===t&&(t=!1),e.send("log",{level:"debug",message:n},!!t)},warn:function(n){return e.send("log",{level:"warn",message:n},!0)},error:function(n,t){return e.send("log",{level:"error",message:n,stack:t},!0)}}}}}function image(){return function(e){return{features:{image:function(n){var t=n.uri,r=n.preview,o=n.filename,i=n.width,s=n.height,a=n.caption;return e.send("image",{uri:t,preview:r,filename:o,width:i,height:s,caption:a})}}}}}function benchmark(){return function(e){var n=e.startTimer;return{features:{benchmark:function(t){var r=[],o=n(),i=function(e){var n=0===r.length?0:r[r.length-1].time,t=o();r.push({title:e,time:t,delta:t-n})};r.push({title:t,time:0,delta:0});var s=function(n){i(n),e.send("benchmark.report",{title:t,steps:r})};return{step:i,stop:s,last:s}}}}}}function stateResponses(){return function(e){return{features:{stateActionComplete:function(n,t,r){return void 0===r&&(r=!1),e.send("state.action.complete",{name:n,action:t},!!r)},stateValuesResponse:function(n,t,r){return void 0===r&&(r=!0),e.send("state.values.response",{path:n,value:t,valid:r})},stateKeysResponse:function(n,t,r){return void 0===r&&(r=!0),e.send("state.keys.response",{path:n,keys:t,valid:r})},stateValuesChange:function(n){return e.send("state.values.change",{changes:n})},stateBackupResponse:function(n){return e.send("state.backup.response",{state:n})}}}}}function apiResponse(){return function(e){return{features:{apiResponse:function(n,t,r){var o=!(t&&t.status&&"number"==typeof t.status&&t.status>=200&&t.status<=299);e.send("api.response",{request:n,response:t,duration:r},o)}}}}}function clear(){return function(e){return{features:{clear:function(){return e.send("clear")}}}}}function getFunctionName(e){var n=e.name;return null===n||void 0===n||""===n?ANONYMOUS:"~~~ "+n+"() ~~~"}function serialize(e){var n=[];return JSON.stringify(e,function(e){return function(t,r){if(!0===r)return!0;if(r===1/0)return INFINITY;if(r===-1/0)return NEGATIVE_INFINITY;if(0===r)return ZERO;if(void 0===r)return UNDEFINED;if(null===r)return NULL;if(!1===r)return FALSE;if(-0===r)return ZERO;if(""===r)return EMPTY_STRING;switch(typeof r){case"string":case"number":return r;case"function":return getFunctionName(r)}if(n.length>0){var o=n.indexOf(this);~o?n.splice(o+1):n.push(this),~n.indexOf(r)&&(r=CIRCULAR)}else n.push(r);return null==e?r:e.call(this,t,r)}}(null))}function emptyPromise(){return Promise.resolve("")}function createClient(e){var n=new Client;return n.configure(e),n}Object.defineProperty(exports,"__esModule",{value:!0});var isCreateSocketValid=function(e){return void 0!==e&&null!==e},isHostValid=function(e){return"string"==typeof e&&e&&""!==e},isPortValid=function(e){return"number"==typeof e&&e>=1&&e<=65535},onCommandValid=function(e){return"function"==typeof e},validate=function(e){var n=e.createSocket,t=e.host,r=e.port,o=e.onCommand;if(!isCreateSocketValid(n))throw new Error("invalid createSocket function");if(!isHostValid(t))throw new Error("invalid host");if(!isPortValid(r))throw new Error("invalid port");if(!onCommandValid(o))throw new Error("invalid onCommand handler")},UNDEFINED="~~~ undefined ~~~",NULL="~~~ null ~~~",FALSE="~~~ false ~~~",ZERO="~~~ zero ~~~",EMPTY_STRING="~~~ empty string ~~~",CIRCULAR="~~~ Circular Reference ~~~",ANONYMOUS="~~~ anonymous function ~~~",INFINITY="~~~ Infinity ~~~",NEGATIVE_INFINITY="~~~ -Infinity ~~~",hasHirezNodeTimer=!1,defaultPerformanceNow=function(e){return Date.now()},nativePerformance="undefined"!=typeof window&&window&&(window.performance||window.msPerformance||window.webkitPerformance),performanceNow=defaultPerformanceNow,delta=function(e){return performanceNow()-e};hasHirezNodeTimer?(performanceNow=process.hrtime,delta=function(e){return performanceNow(e)[1]/1e6}):global.nativePerformanceNow?performanceNow=global.nativePerformanceNow:nativePerformance&&(performanceNow=function(){return nativePerformance.now&&nativePerformance.now()});var start=function(){var e=performanceNow();return function(){return delta(e)}},__assign=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++){n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},corePlugins=[image(),logger(),benchmark(),stateResponses(),apiResponse(),clear()],DEFAULT_OPTIONS={createSocket:null,host:"localhost",port:9090,name:"reactotron-core-client",secure:!1,plugins:corePlugins,safeRecursion:!0,onCommand:function(e){return null},onConnect:function(){return null},onDisconnect:function(){return null}},reservedFeatures=["options","connected","socket","plugins","configure","connect","send","use","startTimer"],isReservedFeature=function(e){return reservedFeatures.some(function(n){return n===e})},Client=function(){function e(){var e=this;this.options=Object.assign({},DEFAULT_OPTIONS),this.connected=!1,this.socket=null,this.plugins=[],this.sendQueue=[],this.isReady=!1,this.lastMessageDate=new Date,this.customCommands=[],this.customCommandLatestId=1,this.startTimer=function(){return start()},this.send=function(n,t,r){if(void 0===t&&(t={}),void 0===r&&(r=!1),e.socket){var o=new Date,i=o.getTime()-e.lastMessageDate.getTime();i<0&&(i=0),e.lastMessageDate=o;var s=serialize({type:n,payload:t,important:!!r,date:o.toISOString(),deltaTime:i});e.isReady?e.socket.send(s):e.sendQueue.push(s)}}}return e.prototype.configure=function(e){var n=this;void 0===e&&(e={});var t=Object.assign({},this.options,e);return validate(t),this.options=t,Array.isArray(this.options.plugins)&&this.options.plugins.forEach(function(e){return n.use(e)}),this},e.prototype.close=function(){this.connected=!1,this.socket&&this.socket.close&&this.socket.close()},e.prototype.connect=function(){var e=this;this.connected=!0;var n=this.options,t=n.createSocket,r=n.secure,o=n.host,i=n.environment,s=n.port,a=n.name,u=n.client,c=void 0===u?{}:u,f=n.getClientId,l=this.options,d=l.onCommand,m=l.onConnect,p=l.onDisconnect,h=t((r?"wss":"ws")+"://"+o+":"+s),g=function(){m&&m(),e.plugins.forEach(function(e){return e.onConnect&&e.onConnect()}),(f||emptyPromise)().then(function(n){for(e.isReady=!0,e.send("client.intro",__assign({environment:i},c,{name:a,clientId:n,reactotronCoreClientVersion:"2.0.0-beta.4"}));e.sendQueue.length>0;){var t=e.sendQueue[0];e.sendQueue=e.sendQueue.slice(1),e.socket.send(t)}})},v=function(){e.isReady=!1,p&&p(),e.plugins.forEach(function(e){return e.onDisconnect&&e.onDisconnect()})},w=function(n){var t=JSON.parse(n);d&&d(t),e.plugins.forEach(function(e){return e.onCommand&&e.onCommand(t)}),"custom"===t.type?e.customCommands.filter(function(e){return e.command===t.payload}).forEach(function(e){return e.handler()}):"setClientId"===t.type&&e.options.setClientId&&e.options.setClientId(t.payload)};return h.on?(h.on("open",g),h.on("close",v),h.on("message",w)):(h.onopen=g,h.onclose=v,h.onmessage=function(e){return w(e.data)}),this.socket=h,this},e.prototype.display=function(e){void 0===e&&(e={});var n=e.name,t=e.value,r=e.preview,o=e.image,i=e.important,s=void 0!==i&&i,a={name:n,value:t||null,preview:r||null,image:o||null};this.send("display",a,s)},e.prototype.reportError=function(e){this.error(e)},e.prototype.use=function(e){var n=this;if("function"!=typeof e)throw new Error("plugins must be a function");var t=e.bind(this)(this);if("object"!=typeof t)throw new Error("plugins must return an object");if(t.features){if("object"!=typeof t.features)throw new Error("features must be an object");var r=function(e){var r=t.features[e];if("function"!=typeof r)throw new Error("feature "+e+" is not a function");if(isReservedFeature(e))throw new Error("feature "+e+" is a reserved name");n[e]=r};Object.keys(t.features).forEach(function(e){return r(e)})}return this.plugins.push(t),t.onPlugin&&"function"==typeof t.onPlugin&&t.onPlugin.bind(this)(this),this},e.prototype.onCustomCommand=function(e,n){var t=this,r={id:this.customCommandLatestId,command:e,handler:n};return this.customCommandLatestId+=1,this.customCommands.push(r),this.send("customCommand.register",{id:r.id,command:r.command}),function(){t.customCommands=t.customCommands.filter(function(e){return e.id!==r.id}),t.send("customCommand.unregister",{id:r.id,command:r.command})}},e}();exports.corePlugins=corePlugins,exports.Client=Client,exports.createClient=createClient; | ||
//# sourceMappingURL=reactotron-core-client.js.map |
@@ -56,13 +56,17 @@ /** | ||
/** | ||
* Deprecated. | ||
* The NODE_ENV environment, if any. | ||
*/ | ||
userAgent?: string; | ||
environment?: string; | ||
/** | ||
* Deprecated. | ||
* A way for the client libraries to identify themselves. | ||
*/ | ||
environment?: string; | ||
client?: any; | ||
/** | ||
* Deprecated. | ||
* Save the client id provided by the server | ||
*/ | ||
reactotronVersion?: string; | ||
setClientId?: (clientId) => Promise<void>; | ||
/** | ||
* Get the client id provided by the server | ||
*/ | ||
getClientId?: () => Promise<string>; | ||
} |
@@ -48,2 +48,7 @@ /// <reference types="ws" /> | ||
}))[]; | ||
export interface CustomCommand { | ||
id: number; | ||
command: string; | ||
handler: () => void; | ||
} | ||
export declare class Client { | ||
@@ -76,2 +81,10 @@ options: ClientOptions; | ||
/** | ||
* The registered custom commands | ||
*/ | ||
customCommands: CustomCommand[]; | ||
/** | ||
* The current ID for custom commands | ||
*/ | ||
customCommandLatestId: number; | ||
/** | ||
* Starts a timer and returns a function you can call to stop it and return the elapsed time. | ||
@@ -84,2 +97,3 @@ */ | ||
configure(options?: ClientOptions): Client; | ||
close(): void; | ||
/** | ||
@@ -105,3 +119,4 @@ * Connect to the Reactotron server. | ||
use(pluginCreator?: (client: Client) => any): Client; | ||
onCustomCommand(command: string, handler: () => void): () => void; | ||
} | ||
export declare const createClient: (options?: ClientOptions) => Client; | ||
export declare function createClient(options?: ClientOptions): Client; |
{ | ||
"name": "reactotron-core-client", | ||
"version": "2.0.0-beta.4", | ||
"version": "2.0.0-beta.5", | ||
"description": "Grants Reactotron clients the ability to talk to a Reactotron server.", | ||
@@ -16,5 +16,5 @@ "files": [ | ||
"format": "prettier --write {**,.}/*.ts && tslint -p . --fix", | ||
"compile": "tsc", | ||
"compile": "NODE_ENV=production tsc", | ||
"lint": "tslint -p .", | ||
"rollup": "rollup -c", | ||
"rollup": "NODE_ENV=production rollup -c", | ||
"test": "jest" | ||
@@ -35,5 +35,6 @@ }, | ||
"prettier": "^1.7.4", | ||
"rollup": "^0.50.0", | ||
"rollup": "^0.58.2", | ||
"rollup-plugin-commonjs": "^8.2.1", | ||
"rollup-plugin-filesize": "^1.4.2", | ||
"rollup-plugin-filesize": "^1.5.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
@@ -40,0 +41,0 @@ "rollup-plugin-uglify": "^2.0.1", |
Sorry, the diff of this file is not supported yet
58225
297
21