New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rockets-client

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rockets-client - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

CHANGELOG.md

18

dist/bundles/rockets-client.umd.js

@@ -22,4 +22,3 @@ (function (global, factory) {

var CANCEL = 'cancel';
var PROGRESS = 'progress';
var ROCKETS_WS_PROTOCOL = 'rockets'; // Request events
var PROGRESS = 'progress'; // Request events

@@ -948,4 +947,3 @@ var PROGRESS_EVENT = 'progress'; // Custom error codes

return Promise.reject(error);
})); // TODO: Make these notification objects
}));
this.notifications = this.json.pipe(operators.filter(isJsonRpcNotification), operators.map(toNotification)); // Create a connection with the socket on init;

@@ -982,11 +980,5 @@ // notifications cannot be sent unless there is at least one subscription.

};
/**
* Make a JSON RPC notification
* @param method
* @param params
*/
Client.prototype.notify = function (method, params) {
var notification = new Notification(method, params);
Client.prototype.notify = function (methodOrNotification, params) {
var notification = methodOrNotification instanceof Notification ? methodOrNotification : new Notification(methodOrNotification, params);
var data = this.serialize(notification);

@@ -1172,3 +1164,3 @@ this.ws.next(data);

url: url,
protocol: [ROCKETS_WS_PROTOCOL],
protocol: config.protocol,
// Override rxjs' default mechanism to JSON.stringify()

@@ -1175,0 +1167,0 @@ serializer: function serializer(message) {

@@ -1,2 +0,2 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("rxjs"),require("rxjs/operators"),require("rxjs/webSocket")):"function"==typeof define&&define.amd?define(["exports","rxjs","rxjs/operators","rxjs/webSocket"],n):n(t.rocketsClient={},t.rxjs,t.rxjs.operators,t.rxjs.webSocket)}(this,function(t,d,v,i){"use strict";var y="2.0",m=-32600,j="cancel",u="rockets",w="progress",n=-30100,c=-30101,s="http",a="https",f="ws",p="wss";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var r=function(t,n){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(t,n)};var o=function(){return(o=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)};function l(i,u,c,s){return new(c||(c=Promise))(function(t,n){function e(t){try{o(s.next(t))}catch(t){n(t)}}function r(t){try{o(s.throw(t))}catch(t){n(t)}}function o(n){n.done?t(n.value):new c(function(t){t(n.value)}).then(e,r)}o((s=s.apply(i,u||[])).next())})}function h(e,r){var o,i,u,t,c={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return t={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function n(n){return function(t){return function(n){if(o)throw new TypeError("Generator is already executing.");for(;c;)try{if(o=1,i&&(u=2&n[0]?i.return:n[0]?i.throw||((u=i.return)&&u.call(i),0):i.next)&&!(u=u.call(i,n[1])).done)return u;switch(i=0,u&&(n=[2&n[0],u.value]),n[0]){case 0:case 1:u=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,i=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(!(u=0<(u=c.trys).length&&u[u.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!u||n[1]>u[0]&&n[1]<u[3])){c.label=n[1];break}if(6===n[0]&&c.label<u[1]){c.label=u[1],u=n;break}if(u&&c.label<u[2]){c.label=u[2],c.ops.push(n);break}u[2]&&c.ops.pop(),c.trys.pop();continue}n=r.call(e,c)}catch(t){n=[6,t],i=0}finally{o=u=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,t])}}}function b(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||0<n--)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}function O(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(b(arguments[n]));return t}var S=function(i){function u(t){var n=t.code,e=t.message,r=t.data,o=i.call(this,e)||this;return Object.setPrototypeOf(o,u.prototype),o.code=n,o.data=r,o}return function(t,n){function e(){this.constructor=t}r(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}(u,i),u}(Error),g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},x="object"==e(g)&&g&&g.Object===Object&&g,P="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,E=(x||P||Function("return this")()).Symbol,_=Object.prototype,R=_.hasOwnProperty,A=_.toString,N=E?E.toStringTag:void 0;var T=function(t){var n=R.call(t,N),e=t[N];try{t[N]=void 0}catch(t){}var r=A.call(t);return n?t[N]=e:delete t[N],r},k=Object.prototype.toString;var I=function(t){return k.call(t)},z=E?E.toStringTag:void 0;var C=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":z&&z in Object(t)?T(t):I(t)},J=Array.isArray;var q=function(t){return null!=t&&"object"==e(t)};var D=function(t){return"string"==typeof t||!J(t)&&q(t)&&"[object String]"==C(t)};var M=function(t){var n=e(t);return null!=t&&("object"==n||"function"==n)};var F=function(t){return"number"==typeof t||q(t)&&"[object Number]"==C(t)};function L(t){return M(t)&&t.jsonrpc===y&&D(t.method)&&!t.hasOwnProperty("id")}function U(t){return M(t)&&F(t.code)&&D(t.message)}function W(t,n){(M(n)||Array.isArray(n))&&Object.assign(t,{params:n})}var V=function(){function t(t,n){this.method=t,this.jsonrpc=y,W(this,n)}return t.fromJson=function(t){return new this(t.method,t.params)},t.prototype.isOfType=function(t){return this.method===t},t.prototype[Symbol.iterator]=function(){var n,e,r,o;return h(this,function(t){switch(t.label){case 0:for(e in n=[],this)n.push(e);r=0,t.label=1;case 1:return r<n.length?(o=n[r],this.hasOwnProperty(o)?[4,[o,this[o]]]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:return r++,[3,1];case 4:return[2]}})},t.prototype.toJSON=function(){return o({},this)},t}();function K(t){void 0===t&&(t=12);var n,e,r,o=(n=new Uint8Array(t),crypto.getRandomValues(n),n);return(e=o,r=String.fromCharCode.apply(String,O(e)),btoa(r)).replace(/=+$/,"").replace(/\+/g,"-").replace(/\//g,"_")}var B=function(){function t(t,n){this.method=t,this.jsonrpc=y,this.id=K(6),W(this,n)}return t.prototype[Symbol.iterator]=function(){var n,e,r,o;return h(this,function(t){switch(t.label){case 0:for(e in n=[],this)n.push(e);r=0,t.label=1;case 1:return r<n.length?(o=n[r],this.hasOwnProperty(o)?[4,[o,this[o]]]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:return r++,[3,1];case 4:return[2]}})},t.prototype.toJSON=function(){return o({},this)},t}(),G=function(){function t(t){this.jsonrpc=y,this.id=t.id,Object.defineProperty(this,"response",{enumerable:!1,value:t})}return t.prototype.json=function(){return l(this,void 0,void 0,function(){var n,e,r;return h(this,function(t){if(n=this.response,e=n.error,!(r=n.result))throw new S(e);return[2,r]})})},t.prototype[Symbol.iterator]=function(){var n,e,r,o;return h(this,function(t){switch(t.label){case 0:for(e in n=[],this)n.push(e);r=0,t.label=1;case 1:return r<n.length?(o=n[r],this.hasOwnProperty(o)?[4,[o,this[o]]]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:return r++,[3,1];case 4:return[2]}})},t.prototype.toJSON=function(){return o({},this)},t}();var H=function(t){if(!M(t))return!1;var n=C(t);return"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n},Q={code:n,message:"Socket connection closed"},Y=function(){function t(t){var n,e,r,o;this.options=t,this.ws=(n=this.options,e=n.onConnected,r=n.onClosed,o=function(t){{if(t.startsWith(f)||t.startsWith(p))return t;if(t.startsWith(s))return t.replace(s,f);if(t.startsWith(a))return t.replace(a,p);if(t.startsWith("://"))return""+f+t}return f+"://"+t}(n.url),i.webSocket({url:o,protocol:[u],serializer:function(t){return t},deserializer:function(t){return t},openObserver:{next:function(){H(e)&&e()}},closeObserver:{next:function(t){H(r)&&r(t)}}})),this.serialize=function(t){var n=t.serializer;if(H(n))return n;return tt}(this.options),this.deserialize=function(t){var n=t.deserializer;if(H(n))return n;return Z}(this.options),this.json=this.ws.pipe(v.mergeMap(this.deserialize),v.filter(nt),v.catchError(function(t){var n=M(t)&&F(t.code)&&D(t.reason)?it(Q):it({code:c,message:"Socket pipe broken"});return Promise.reject(n)})),this.notifications=this.json.pipe(v.filter(L),v.map(ut)),this.sub=this.json.subscribe({error:d.noop})}return t.create=function(t){return new this(t)},t.prototype.subscribe=function(t,n,e){return this.notifications.subscribe(t,n,e)},t.prototype.asObservable=function(){return this.notifications},t.prototype.notify=function(t,n){var e=new V(t,n),r=this.serialize(e);this.ws.next(r)},t.prototype.request=function(t,n){var e,i,r,u=this,o=rt(t)?t:new B(t,n),c=o.id,s=(e=c,function(t){return M(t)&&t.jsonrpc===y&&D(t.id)&&t.id===e}),a=$(c),f=new Promise(function(r,o){u.json.pipe(v.filter(s),v.take(1),v.tap(function(){i=!0})).subscribe(function(t){var n=t.result,e=t.error;U(e)?o(it(e)):r(n)},function(t){o(t)},function(){var t=it(Q);o(t)})}),p=new d.ReplaySubject(1),l=this.json.pipe(v.filter(a),v.map(X)).subscribe(function(t){p.next(t),1<=t.amount&&l.unsubscribe()},d.noop);f.then(function(){p.complete()},function(t){p.error(t)});var h=this.serialize(o);return this.ws.next(h),{request:o,then:function(t,n){return f.then(t,n)},on:function(t){return t===w?p.asObservable():d.EMPTY},cancel:function(){i||r||(r=!0,u.notify(j,{id:c}))}}},t.prototype.batch=function(){for(var r=this,e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n,o,i,u,c,s=e.filter(rt),a=0<s.length,f=(n=s,function(t){return Array.isArray(t)&&t.every(ot)&&n.every(function(n){return-1!==t.findIndex(function(t){return t.id===n.id})})}),p=new Promise(function(n,e){r.json.pipe(v.filter(f),v.take(1),v.tap(function(){o=!0})).subscribe(function(t){n(t.map(function(t){return new G(t)}))},function(t){e(t)},function(){var t=it(Q);e(t)})}),l=new d.ReplaySubject(1),h=(u=s,c=[],function(n){var t=c.findIndex(function(t){return t.params.id===n.params.id});-1!==t?c.splice(t,1,n):c.push(n);var e=c.map(X).map(function(t){return t.amount}).reduce(function(t,n){return t+n},0),r=e/u.length;return r}),y=d.merge.apply(void 0,O(s.map(function(t){return $(t.id)}).map(function(t){return r.json.pipe(v.filter(t),v.map(h))}))).pipe(v.distinct()).subscribe(function(t){l.next({amount:t}),1<=t&&y.unsubscribe()},d.noop);p.then(function(){l.complete()},function(t){l.error(t)});var b=this.serialize(e);return this.ws.next(b),{then:function(t,n){return(e.length?a?p:Promise.resolve(void 0):Promise.reject(it({code:m,message:"Invalid request"}))).then(t,n)},on:function(t){return t===w&&a?l.asObservable():d.EMPTY},cancel:function(){if(!o&&!i&&a){i=!0;var t=s.map(function(t){var n=t.id;return new V(j,{id:n})});r.batch.apply(r,O(t))}}}},t.prototype.disconnect=function(){this.ws.error({code:1e3,reason:"Client wanted disconnect"})},t}();function $(n){return function(t){return M(t)&&t.jsonrpc===y&&"progress"===t.method&&M(t.params)&&t.params.id===n}}function X(t){var n=t.params;return{amount:n.amount,operation:n.operation}}function Z(n){return l(this,void 0,void 0,function(){return h(this,function(t){try{return[2,JSON.parse(n.data)]}catch(t){return[2]}return[2]})})}function tt(t){return JSON.stringify(t)}function nt(t){return Array.isArray(t)&&0<t.length&&t.every(et)||et(t)}function et(t){return L(t)||ot(t)}function rt(t){return t instanceof B}function ot(t){return M(t)&&t.jsonrpc===y&&(D(t.id)||F(t.id)||null===t.id)&&(void 0!==t.result||U(t.error))}function it(t){return new S(t)}function ut(t){return V.fromJson(t)}t.HTTP_ERROR=-31003,t.INTERNAL_ERROR=-32603,t.INVALID_JSON_RESPONSE=-31001,t.INVALID_PARAMS=-32602,t.INVALID_REQUEST=m,t.METHOD_NOT_FOUND=-32601,t.PARSE_ERROR=-32700,t.REQUEST_ABORTED=-31002,t.SOCKET_CLOSED=n,t.SOCKET_PIPE_BROKEN=c,t.JsonRpcError=S,t.Notification=V,t.Request=B,t.Response=G,t.Client=Y,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("rxjs"),require("rxjs/operators"),require("rxjs/webSocket")):"function"==typeof define&&define.amd?define(["exports","rxjs","rxjs/operators","rxjs/webSocket"],n):n(t.rocketsClient={},t.rxjs,t.rxjs.operators,t.rxjs.webSocket)}(this,function(t,d,v,i){"use strict";var y="2.0",m=-32600,j="cancel",w="progress",n=-30100,u=-30101,c="http",s="https",a="ws",f="wss";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var r=function(t,n){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(t,n)};var o=function(){return(o=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)};function p(i,u,c,s){return new(c||(c=Promise))(function(t,n){function e(t){try{o(s.next(t))}catch(t){n(t)}}function r(t){try{o(s.throw(t))}catch(t){n(t)}}function o(n){n.done?t(n.value):new c(function(t){t(n.value)}).then(e,r)}o((s=s.apply(i,u||[])).next())})}function l(e,r){var o,i,u,t,c={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return t={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function n(n){return function(t){return function(n){if(o)throw new TypeError("Generator is already executing.");for(;c;)try{if(o=1,i&&(u=2&n[0]?i.return:n[0]?i.throw||((u=i.return)&&u.call(i),0):i.next)&&!(u=u.call(i,n[1])).done)return u;switch(i=0,u&&(n=[2&n[0],u.value]),n[0]){case 0:case 1:u=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,i=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(!(u=0<(u=c.trys).length&&u[u.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!u||n[1]>u[0]&&n[1]<u[3])){c.label=n[1];break}if(6===n[0]&&c.label<u[1]){c.label=u[1],u=n;break}if(u&&c.label<u[2]){c.label=u[2],c.ops.push(n);break}u[2]&&c.ops.pop(),c.trys.pop();continue}n=r.call(e,c)}catch(t){n=[6,t],i=0}finally{o=u=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,t])}}}function h(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||0<n--)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}function O(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(h(arguments[n]));return t}var b=function(i){function u(t){var n=t.code,e=t.message,r=t.data,o=i.call(this,e)||this;return Object.setPrototypeOf(o,u.prototype),o.code=n,o.data=r,o}return function(t,n){function e(){this.constructor=t}r(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}(u,i),u}(Error),S="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},g="object"==e(S)&&S&&S.Object===Object&&S,x="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,P=(g||x||Function("return this")()).Symbol,E=Object.prototype,_=E.hasOwnProperty,R=E.toString,A=P?P.toStringTag:void 0;var N=function(t){var n=_.call(t,A),e=t[A];try{t[A]=void 0}catch(t){}var r=R.call(t);return n?t[A]=e:delete t[A],r},T=Object.prototype.toString;var k=function(t){return T.call(t)},I=P?P.toStringTag:void 0;var z=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":I&&I in Object(t)?N(t):k(t)},C=Array.isArray;var J=function(t){return null!=t&&"object"==e(t)};var q=function(t){return"string"==typeof t||!C(t)&&J(t)&&"[object String]"==z(t)};var D=function(t){var n=e(t);return null!=t&&("object"==n||"function"==n)};var M=function(t){return"number"==typeof t||J(t)&&"[object Number]"==z(t)};function F(t){return D(t)&&t.jsonrpc===y&&q(t.method)&&!t.hasOwnProperty("id")}function L(t){return D(t)&&M(t.code)&&q(t.message)}function U(t,n){(D(n)||Array.isArray(n))&&Object.assign(t,{params:n})}var W=function(){function t(t,n){this.method=t,this.jsonrpc=y,U(this,n)}return t.fromJson=function(t){return new this(t.method,t.params)},t.prototype.isOfType=function(t){return this.method===t},t.prototype[Symbol.iterator]=function(){var n,e,r,o;return l(this,function(t){switch(t.label){case 0:for(e in n=[],this)n.push(e);r=0,t.label=1;case 1:return r<n.length?(o=n[r],this.hasOwnProperty(o)?[4,[o,this[o]]]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:return r++,[3,1];case 4:return[2]}})},t.prototype.toJSON=function(){return o({},this)},t}();function V(t){void 0===t&&(t=12);var n,e,r,o=(n=new Uint8Array(t),crypto.getRandomValues(n),n);return(e=o,r=String.fromCharCode.apply(String,O(e)),btoa(r)).replace(/=+$/,"").replace(/\+/g,"-").replace(/\//g,"_")}var K=function(){function t(t,n){this.method=t,this.jsonrpc=y,this.id=V(6),U(this,n)}return t.prototype[Symbol.iterator]=function(){var n,e,r,o;return l(this,function(t){switch(t.label){case 0:for(e in n=[],this)n.push(e);r=0,t.label=1;case 1:return r<n.length?(o=n[r],this.hasOwnProperty(o)?[4,[o,this[o]]]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:return r++,[3,1];case 4:return[2]}})},t.prototype.toJSON=function(){return o({},this)},t}(),B=function(){function t(t){this.jsonrpc=y,this.id=t.id,Object.defineProperty(this,"response",{enumerable:!1,value:t})}return t.prototype.json=function(){return p(this,void 0,void 0,function(){var n,e,r;return l(this,function(t){if(n=this.response,e=n.error,!(r=n.result))throw new b(e);return[2,r]})})},t.prototype[Symbol.iterator]=function(){var n,e,r,o;return l(this,function(t){switch(t.label){case 0:for(e in n=[],this)n.push(e);r=0,t.label=1;case 1:return r<n.length?(o=n[r],this.hasOwnProperty(o)?[4,[o,this[o]]]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:return r++,[3,1];case 4:return[2]}})},t.prototype.toJSON=function(){return o({},this)},t}();var G=function(t){if(!D(t))return!1;var n=z(t);return"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n},H={code:n,message:"Socket connection closed"},Q=function(){function t(t){var n,e,r,o;this.options=t,this.ws=(n=this.options,e=n.onConnected,r=n.onClosed,o=function(t){{if(t.startsWith(a)||t.startsWith(f))return t;if(t.startsWith(c))return t.replace(c,a);if(t.startsWith(s))return t.replace(s,f);if(t.startsWith("://"))return""+a+t}return a+"://"+t}(n.url),i.webSocket({url:o,protocol:n.protocol,serializer:function(t){return t},deserializer:function(t){return t},openObserver:{next:function(){G(e)&&e()}},closeObserver:{next:function(t){G(r)&&r(t)}}})),this.serialize=function(t){var n=t.serializer;if(G(n))return n;return Z}(this.options),this.deserialize=function(t){var n=t.deserializer;if(G(n))return n;return X}(this.options),this.json=this.ws.pipe(v.mergeMap(this.deserialize),v.filter(tt),v.catchError(function(t){var n=D(t)&&M(t.code)&&q(t.reason)?ot(H):ot({code:u,message:"Socket pipe broken"});return Promise.reject(n)})),this.notifications=this.json.pipe(v.filter(F),v.map(it)),this.sub=this.json.subscribe({error:d.noop})}return t.create=function(t){return new this(t)},t.prototype.subscribe=function(t,n,e){return this.notifications.subscribe(t,n,e)},t.prototype.asObservable=function(){return this.notifications},t.prototype.notify=function(t,n){var e=t instanceof W?t:new W(t,n),r=this.serialize(e);this.ws.next(r)},t.prototype.request=function(t,n){var e,i,r,u=this,o=et(t)?t:new K(t,n),c=o.id,s=(e=c,function(t){return D(t)&&t.jsonrpc===y&&q(t.id)&&t.id===e}),a=Y(c),f=new Promise(function(r,o){u.json.pipe(v.filter(s),v.take(1),v.tap(function(){i=!0})).subscribe(function(t){var n=t.result,e=t.error;L(e)?o(ot(e)):r(n)},function(t){o(t)},function(){var t=ot(H);o(t)})}),p=new d.ReplaySubject(1),l=this.json.pipe(v.filter(a),v.map($)).subscribe(function(t){p.next(t),1<=t.amount&&l.unsubscribe()},d.noop);f.then(function(){p.complete()},function(t){p.error(t)});var h=this.serialize(o);return this.ws.next(h),{request:o,then:function(t,n){return f.then(t,n)},on:function(t){return t===w?p.asObservable():d.EMPTY},cancel:function(){i||r||(r=!0,u.notify(j,{id:c}))}}},t.prototype.batch=function(){for(var r=this,e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n,o,i,u,c,s=e.filter(et),a=0<s.length,f=(n=s,function(t){return Array.isArray(t)&&t.every(rt)&&n.every(function(n){return-1!==t.findIndex(function(t){return t.id===n.id})})}),p=new Promise(function(n,e){r.json.pipe(v.filter(f),v.take(1),v.tap(function(){o=!0})).subscribe(function(t){n(t.map(function(t){return new B(t)}))},function(t){e(t)},function(){var t=ot(H);e(t)})}),l=new d.ReplaySubject(1),h=(u=s,c=[],function(n){var t=c.findIndex(function(t){return t.params.id===n.params.id});-1!==t?c.splice(t,1,n):c.push(n);var e=c.map($).map(function(t){return t.amount}).reduce(function(t,n){return t+n},0),r=e/u.length;return r}),y=d.merge.apply(void 0,O(s.map(function(t){return Y(t.id)}).map(function(t){return r.json.pipe(v.filter(t),v.map(h))}))).pipe(v.distinct()).subscribe(function(t){l.next({amount:t}),1<=t&&y.unsubscribe()},d.noop);p.then(function(){l.complete()},function(t){l.error(t)});var b=this.serialize(e);return this.ws.next(b),{then:function(t,n){return(e.length?a?p:Promise.resolve(void 0):Promise.reject(ot({code:m,message:"Invalid request"}))).then(t,n)},on:function(t){return t===w&&a?l.asObservable():d.EMPTY},cancel:function(){if(!o&&!i&&a){i=!0;var t=s.map(function(t){var n=t.id;return new W(j,{id:n})});r.batch.apply(r,O(t))}}}},t.prototype.disconnect=function(){this.ws.error({code:1e3,reason:"Client wanted disconnect"})},t}();function Y(n){return function(t){return D(t)&&t.jsonrpc===y&&"progress"===t.method&&D(t.params)&&t.params.id===n}}function $(t){var n=t.params;return{amount:n.amount,operation:n.operation}}function X(n){return p(this,void 0,void 0,function(){return l(this,function(t){try{return[2,JSON.parse(n.data)]}catch(t){return[2]}return[2]})})}function Z(t){return JSON.stringify(t)}function tt(t){return Array.isArray(t)&&0<t.length&&t.every(nt)||nt(t)}function nt(t){return F(t)||rt(t)}function et(t){return t instanceof K}function rt(t){return D(t)&&t.jsonrpc===y&&(q(t.id)||M(t.id)||null===t.id)&&(void 0!==t.result||L(t.error))}function ot(t){return new b(t)}function it(t){return W.fromJson(t)}t.HTTP_ERROR=-31003,t.INTERNAL_ERROR=-32603,t.INVALID_JSON_RESPONSE=-31001,t.INVALID_PARAMS=-32602,t.INVALID_REQUEST=m,t.METHOD_NOT_FOUND=-32601,t.PARSE_ERROR=-32700,t.REQUEST_ABORTED=-31002,t.SOCKET_CLOSED=n,t.SOCKET_PIPE_BROKEN=u,t.JsonRpcError=b,t.Notification=W,t.Request=K,t.Response=B,t.Client=Q,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=rockets-client.umd.min.js.map

@@ -38,2 +38,3 @@ import { Observable, PartialObserver, Subscribable, Subscription } from 'rxjs';

*/
notify<P>(notification: Notification<P>): void;
notify<P>(method: string, params?: P): void;

@@ -64,3 +65,3 @@ /**

}
export interface ClientOptions extends Pick<WebSocketSubjectConfig<any>, 'url'> {
export interface ClientOptions extends Pick<WebSocketSubjectConfig<any>, 'url' | 'protocol'> {
onConnected?(): void;

@@ -67,0 +68,0 @@ onClosed?(evt: CloseEvent): void;

@@ -92,3 +92,2 @@ "use strict";

}));
// TODO: Make these notification objects
this.notifications = this.json.pipe(operators_1.filter(utils_1.isJsonRpcNotification), operators_1.map(toNotification));

@@ -118,9 +117,6 @@ // Create a connection with the socket on init;

};
/**
* Make a JSON RPC notification
* @param method
* @param params
*/
Client.prototype.notify = function (method, params) {
var notification = new notification_1.Notification(method, params);
Client.prototype.notify = function (methodOrNotification, params) {
var notification = methodOrNotification instanceof notification_1.Notification
? methodOrNotification
: new notification_1.Notification(methodOrNotification, params);
var data = this.serialize(notification);

@@ -292,3 +288,3 @@ this.ws.next(data);

url: url,
protocol: [constants_1.ROCKETS_WS_PROTOCOL],
protocol: config.protocol,
// Override rxjs' default mechanism to JSON.stringify()

@@ -295,0 +291,0 @@ serializer: function (message) { return message; },

@@ -13,3 +13,2 @@ export declare const JSON_RPC_VERSION = "2.0";

export declare const PROGRESS = "progress";
export declare const ROCKETS_WS_PROTOCOL = "rockets";
export declare const PROGRESS_EVENT = "progress";

@@ -16,0 +15,0 @@ export declare type PROGRESS_EVENT_TYPE = typeof PROGRESS_EVENT;

@@ -19,3 +19,2 @@ "use strict";

exports.PROGRESS = 'progress';
exports.ROCKETS_WS_PROTOCOL = 'rockets';
// Request events

@@ -22,0 +21,0 @@ exports.PROGRESS_EVENT = 'progress';

@@ -6,3 +6,3 @@ import * as tslib_1 from "tslib";

import { webSocket } from 'rxjs/webSocket';
import { CANCEL, HTTP, HTTPS, INVALID_REQUEST, JSON_RPC_VERSION, PROGRESS, PROGRESS_EVENT, ROCKETS_WS_PROTOCOL, SOCKET_CLOSED, SOCKET_PIPE_BROKEN, WS, WSS } from './constants';
import { CANCEL, HTTP, HTTPS, INVALID_REQUEST, JSON_RPC_VERSION, PROGRESS, PROGRESS_EVENT, SOCKET_CLOSED, SOCKET_PIPE_BROKEN, WS, WSS } from './constants';
import { JsonRpcError } from './error';

@@ -37,3 +37,2 @@ import { Notification } from './notification';

}));
// TODO: Make these notification objects
this.notifications = this.json.pipe(filter(isJsonRpcNotification), map(toNotification));

@@ -63,9 +62,6 @@ // Create a connection with the socket on init;

}
/**
* Make a JSON RPC notification
* @param method
* @param params
*/
notify(method, params) {
const notification = new Notification(method, params);
notify(methodOrNotification, params) {
const notification = methodOrNotification instanceof Notification
? methodOrNotification
: new Notification(methodOrNotification, params);
const data = this.serialize(notification);

@@ -224,3 +220,3 @@ this.ws.next(data);

url,
protocol: [ROCKETS_WS_PROTOCOL],
protocol: config.protocol,
// Override rxjs' default mechanism to JSON.stringify()

@@ -227,0 +223,0 @@ serializer: (message) => message,

@@ -17,3 +17,2 @@ // https://www.jsonrpc.org/specification#compatibility

export const PROGRESS = 'progress';
export const ROCKETS_WS_PROTOCOL = 'rockets';
// Request events

@@ -20,0 +19,0 @@ export const PROGRESS_EVENT = 'progress';

@@ -6,3 +6,3 @@ import * as tslib_1 from "tslib";

import { webSocket } from 'rxjs/webSocket';
import { CANCEL, HTTP, HTTPS, INVALID_REQUEST, JSON_RPC_VERSION, PROGRESS, PROGRESS_EVENT, ROCKETS_WS_PROTOCOL, SOCKET_CLOSED, SOCKET_PIPE_BROKEN, WS, WSS } from './constants';
import { CANCEL, HTTP, HTTPS, INVALID_REQUEST, JSON_RPC_VERSION, PROGRESS, PROGRESS_EVENT, SOCKET_CLOSED, SOCKET_PIPE_BROKEN, WS, WSS } from './constants';
import { JsonRpcError } from './error';

@@ -37,3 +37,2 @@ import { Notification } from './notification';

}));
// TODO: Make these notification objects
this.notifications = this.json.pipe(filter(isJsonRpcNotification), map(toNotification));

@@ -63,9 +62,6 @@ // Create a connection with the socket on init;

};
/**
* Make a JSON RPC notification
* @param method
* @param params
*/
Client.prototype.notify = function (method, params) {
var notification = new Notification(method, params);
Client.prototype.notify = function (methodOrNotification, params) {
var notification = methodOrNotification instanceof Notification
? methodOrNotification
: new Notification(methodOrNotification, params);
var data = this.serialize(notification);

@@ -237,3 +233,3 @@ this.ws.next(data);

url: url,
protocol: [ROCKETS_WS_PROTOCOL],
protocol: config.protocol,
// Override rxjs' default mechanism to JSON.stringify()

@@ -240,0 +236,0 @@ serializer: function (message) { return message; },

@@ -17,3 +17,2 @@ // https://www.jsonrpc.org/specification#compatibility

export var PROGRESS = 'progress';
export var ROCKETS_WS_PROTOCOL = 'rockets';
// Request events

@@ -20,0 +19,0 @@ export var PROGRESS_EVENT = 'progress';

{
"name": "rockets-client",
"version": "0.1.1",
"description": "",
"main": "./dist/index.js",
"module": "./dist/es5/index.js",
"es2015": "./dist/es2015/index.js",
"typings": "./dist/index.d.ts",
"keywords": [
"rockets",
"websocket",
"json-rpc",
"client"
],
"homepage": "https://github.com/BlueBrain/Rockets",
"license": "LGPL-3.0+",
"author": {
"name": "Roland Groza",
"email": "roland.groza@epfl.ch"
},
"repository": {
"type": "git",
"url": "https://github.com/BlueBrain/Rockets"
},
"name": "rockets-client",
"version": "0.2.0",
"description": "",
"main": "./dist/index.js",
"module": "./dist/es5/index.js",
"es2015": "./dist/es2015/index.js",
"typings": "./dist/index.d.ts",
"keywords": [
"rockets",
"websocket",
"json-rpc",
"client"
],
"homepage": "https://github.com/BlueBrain/Rockets",
"license": "LGPL-3.0+",
"author": {
"name": "Roland Groza",
"email": "roland.groza@epfl.ch"
},
"repository": {
"type": "git",
"url": "https://github.com/BlueBrain/Rockets"
},
"scripts": {
"prebuild": "yarn run clean",
"build": "npm-run-all -s compile build:umd",
"build:umd": "rollup -c ./rollup.config.js",
"compile": "npm-run-all -p compile:es2015 compile:es5 compile:cjs compile:types",
"compile:es2015": "tsc -p ./tsconfig.es2015.json",
"compile:es5": "tsc -p ./tsconfig.es5.json",
"compile:cjs": "tsc -p ./tsconfig.cjs.json",
"compile:types": "tsc -p ./tsconfig.types.json",
"clean": "rm -rf dist/*",
"docs": "typedoc --out docs/ ./ --mode file --exclude *.spec.ts --excludeExternals --excludePrivate",
"lint": "tslint -c tslint.json -p ./tsconfig.spec.json -t stylish",
"lint:fix": "yarn run lint -- --fix",
"pretest:cov": "yarn run lint",
"test:cov": "jest --coverage",
"test": "jest --watch",
"release": "standard-version"
},
"standard-version": {
"message": "chore(js): Release v%s :tada:",
"scripts": {
"prebuild": "yarn run clean",
"build": "npm-run-all -s compile build:umd",
"build:umd": "rollup -c ./rollup.config.js",
"compile": "npm-run-all -p compile:es2015 compile:es5 compile:cjs compile:types",
"compile:es2015": "tsc -p ./tsconfig.es2015.json",
"compile:es5": "tsc -p ./tsconfig.es5.json",
"compile:cjs": "tsc -p ./tsconfig.cjs.json",
"compile:types": "tsc -p ./tsconfig.types.json",
"clean": "rm -rf dist/*",
"docs": "typedoc --out docs/ ./ --mode file --exclude *.spec.ts --excludeExternals --excludePrivate",
"lint": "tslint -c tslint.json -p ./tsconfig.spec.json -t stylish",
"lint:fix": "yarn run lint -- --fix",
"pretest:cov": "yarn run lint",
"test:cov": "jest --coverage",
"test": "jest --watch"
"prerelease": "$(yarn bin)/npm-run-all -p test:cov build"
},
"dependencies": {
"crypto-uid": "^0.3.0",
"lodash": "^4.17.10",
"tslib": "^1.9.0"
},
"peerDependencies": {
"rxjs": ">= 6.2"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@trust/webcrypto": "^0.9.2",
"@types/jest": "^23.3.1",
"@types/lodash": "^4.14.116",
"@types/node": "^9.4.5",
"babel-core": "^7.0.0-0",
"babel-plugin-lodash": "^3.3.4",
"babel-jest": "^23.4.0",
"camelcase": "^4.1.0",
"jest": "^23.5.0",
"mock-socket": "^8.0.1",
"npm-run-all": "^4.1.3",
"rollup": "^0.65.0",
"rollup-plugin-babel": "latest",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^4.0.0",
"rxjs": "^6.2.1",
"ts-jest": "^23.1.4",
"tslint": "^5.9.1",
"typedoc": "^0.11.1",
"typescript": "2.8.3"
},
"engines": {
"node": ">= 7.9"
"skip": {
"tag": true
}
},
"dependencies": {
"crypto-uid": "^0.3.0",
"lodash": "^4.17.10",
"tslib": "^1.9.0"
},
"peerDependencies": {
"rxjs": ">= 6.2"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@trust/webcrypto": "^0.9.2",
"@types/jest": "^23.3.1",
"@types/lodash": "^4.14.116",
"@types/node": "^9.4.5",
"babel-core": "^7.0.0-0",
"babel-plugin-lodash": "^3.3.4",
"babel-jest": "^23.4.0",
"camelcase": "^4.1.0",
"jest": "^23.5.0",
"mock-socket": "^8.0.1",
"npm-run-all": "^4.1.3",
"rollup": "^0.65.0",
"rollup-plugin-babel": "latest",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^4.0.0",
"rxjs": "^6.2.1",
"standard-version": "^4.4.0",
"ts-jest": "^23.1.4",
"tslint": "^5.9.1",
"typedoc": "^0.11.1",
"typescript": "2.8.3"
},
"engines": {
"node": ">= 7.9"
}
}

@@ -16,2 +16,3 @@ # Rockets JS Client

* [Batching](#batching)
* [Release](#release)
* [Learning Material](#learning-material)

@@ -107,2 +108,15 @@

Send a notification using the `Notification` object:
```ts
import {Client, Notification} from 'rockets-client';
const rockets = new Client({url: 'myhost'});
const notification = new Notification('mymethod', {
ping: true
});
rockets.notify(notification);
```
#### Requests

@@ -121,2 +135,6 @@ Make a request:

**NOTE**: There is no need to wait for a connection to be established with the socket as requests will be buffered and sent once the connection is alive.
In case of a socket error, the request promise will reject.
The same is true for batch requests and notifications.
Or make a request using the `Request` object:

@@ -235,3 +253,3 @@ ```ts

const request = new Request('mymethod');
const task = await rockets.batch(request);
const task = rockets.batch(request);

@@ -250,3 +268,3 @@ task.cancel();

const request = new Request('mymethod');
const task = await rockets.batch(request);
const task = rockets.batch(request);

@@ -260,2 +278,17 @@ task.on('progress')

### Release
-----------
If you're a contributor and wish to make a release of this package use:
```bash
# Cut a minor release
yarn release --release-as minor
```
See [release as a target type imperatively like npm-version](https://github.com/conventional-changelog/standard-version#release-as-a-target-type-imperatively-like-npm-version) for more release options.
After the changes land in master, the new version will be automatically published by the CI.
**IMPORTANT**: Follow the [semver](https://semver.org) for versioning.
### Learning Material

@@ -262,0 +295,0 @@ ---------------------

@@ -40,3 +40,2 @@ import {

PROGRESS_EVENT_TYPE,
ROCKETS_WS_PROTOCOL,
SOCKET_CLOSED,

@@ -98,3 +97,2 @@ SOCKET_PIPE_BROKEN,

// TODO: Make these notification objects
private notifications: Observable<Notification> = this.json.pipe(

@@ -137,4 +135,8 @@ filter(isJsonRpcNotification),

*/
notify<P>(method: string, params?: P): void {
const notification = new Notification(method, params);
notify<P>(notification: Notification<P>): void;
notify<P>(method: string, params?: P): void;
notify<P>(methodOrNotification: string | Notification, params?: P): void {
const notification = methodOrNotification instanceof Notification
? methodOrNotification
: new Notification(methodOrNotification, params);
const data = this.serialize(notification);

@@ -332,3 +334,3 @@ this.ws.next(data);

export interface ClientOptions extends Pick<WebSocketSubjectConfig<any>, 'url'> {
export interface ClientOptions extends Pick<WebSocketSubjectConfig<any>, 'url' | 'protocol'> {
onConnected?(): void;

@@ -366,3 +368,3 @@ onClosed?(evt: CloseEvent): void;

url,
protocol: [ROCKETS_WS_PROTOCOL],
protocol: config.protocol,
// Override rxjs' default mechanism to JSON.stringify()

@@ -369,0 +371,0 @@ serializer: (message: any) => message,

@@ -22,4 +22,2 @@ // https://www.jsonrpc.org/specification#compatibility

export const ROCKETS_WS_PROTOCOL = 'rockets';
// Request events

@@ -26,0 +24,0 @@ export const PROGRESS_EVENT = 'progress';

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc