rockets-client
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.3.0"></a> | ||
# 0.3.0 (2018-10-02) | ||
### Features | ||
* **js:** export more types and utils ([fa77f6f](https://github.com/BlueBrain/Rockets/commit/fa77f6f)) | ||
<a name="0.2.0"></a> | ||
@@ -12,2 +22,2 @@ # 0.2.0 (2018-10-01) | ||
* **js:** add javascript client ([b81fccc](https://github.com/BlueBrain/Rockets/commit/b81fccc)) | ||
* **js:** add javascript client ([256bcd4](https://github.com/BlueBrain/Rockets/commit/256bcd4)) |
@@ -574,2 +574,10 @@ (function (global, factory) { | ||
/** | ||
* Check if value is an RPC request | ||
* @param value | ||
*/ | ||
function isJsonRpcRequest(value) { | ||
return isObject_1(value) && value.jsonrpc === JSON_RPC_VERSION && isString_1(value.method) && (isString_1(value.id) || isNumber_1(value.id)); | ||
} | ||
/** | ||
* Check if value is an RPC error | ||
@@ -1390,4 +1398,6 @@ * @param value | ||
exports.INVALID_REQUEST = INVALID_REQUEST; | ||
exports.JSON_RPC_VERSION = JSON_RPC_VERSION; | ||
exports.METHOD_NOT_FOUND = METHOD_NOT_FOUND; | ||
exports.PARSE_ERROR = PARSE_ERROR; | ||
exports.PROGRESS_EVENT = PROGRESS_EVENT; | ||
exports.REQUEST_ABORTED = REQUEST_ABORTED; | ||
@@ -1401,2 +1411,4 @@ exports.SOCKET_CLOSED = SOCKET_CLOSED; | ||
exports.Client = Client; | ||
exports.isJsonRpcNotification = isJsonRpcNotification; | ||
exports.isJsonRpcRequest = isJsonRpcRequest; | ||
@@ -1403,0 +1415,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -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",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})}); | ||
!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,R="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,x=(g||R||Function("return this")()).Symbol,E=Object.prototype,P=E.hasOwnProperty,_=E.toString,N=x?x.toStringTag:void 0;var A=function(t){var n=P.call(t,N),e=t[N];try{t[N]=void 0}catch(t){}var r=_.call(t);return n?t[N]=e:delete t[N],r},T=Object.prototype.toString;var k=function(t){return T.call(t)},I=x?x.toStringTag:void 0;var J=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":I&&I in Object(t)?A(t):k(t)},C=Array.isArray;var z=function(t){return null!=t&&"object"==e(t)};var q=function(t){return"string"==typeof t||!C(t)&&z(t)&&"[object String]"==J(t)};var D=function(t){var n=e(t);return null!=t&&("object"==n||"function"==n)};var M=function(t){return"number"==typeof t||z(t)&&"[object Number]"==J(t)};function V(t){return D(t)&&t.jsonrpc===y&&q(t.method)&&!t.hasOwnProperty("id")}function F(t){return D(t)&&M(t.code)&&q(t.message)}function L(t,n){(D(n)||Array.isArray(n))&&Object.assign(t,{params:n})}var U=function(){function t(t,n){this.method=t,this.jsonrpc=y,L(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 W(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 G=function(){function t(t,n){this.method=t,this.jsonrpc=y,this.id=W(6),L(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}(),K=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 B=function(t){if(!D(t))return!1;var n=J(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(){B(e)&&e()}},closeObserver:{next:function(t){B(r)&&r(t)}}})),this.serialize=function(t){var n=t.serializer;if(B(n))return n;return Z}(this.options),this.deserialize=function(t){var n=t.deserializer;if(B(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(V),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 U?t:new U(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 G(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;F(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 K(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 U(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 V(t)||rt(t)}function et(t){return t instanceof G}function rt(t){return D(t)&&t.jsonrpc===y&&(q(t.id)||M(t.id)||null===t.id)&&(void 0!==t.result||F(t.error))}function ot(t){return new b(t)}function it(t){return U.fromJson(t)}t.HTTP_ERROR=-31003,t.INTERNAL_ERROR=-32603,t.INVALID_JSON_RESPONSE=-31001,t.INVALID_PARAMS=-32602,t.INVALID_REQUEST=m,t.JSON_RPC_VERSION=y,t.METHOD_NOT_FOUND=-32601,t.PARSE_ERROR=-32700,t.PROGRESS_EVENT=w,t.REQUEST_ABORTED=-31002,t.SOCKET_CLOSED=n,t.SOCKET_PIPE_BROKEN=u,t.JsonRpcError=b,t.Notification=U,t.Request=G,t.Response=K,t.Client=Q,t.isJsonRpcNotification=V,t.isJsonRpcRequest=function(t){return D(t)&&t.jsonrpc===y&&q(t.method)&&(q(t.id)||M(t.id))},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=rockets-client.umd.min.js.map |
@@ -1,2 +0,2 @@ | ||
export { HTTP_ERROR, INTERNAL_ERROR, INVALID_JSON_RESPONSE, INVALID_PARAMS, INVALID_REQUEST, METHOD_NOT_FOUND, PARSE_ERROR, REQUEST_ABORTED, SOCKET_CLOSED, SOCKET_PIPE_BROKEN } from './constants'; | ||
export { HTTP_ERROR, INTERNAL_ERROR, INVALID_JSON_RESPONSE, INVALID_PARAMS, INVALID_REQUEST, JSON_RPC_VERSION, METHOD_NOT_FOUND, PARSE_ERROR, PROGRESS_EVENT, REQUEST_ABORTED, SOCKET_CLOSED, SOCKET_PIPE_BROKEN } from './constants'; | ||
export { JsonRpcError } from './error'; | ||
@@ -7,2 +7,3 @@ export { Notification } from './notification'; | ||
export { Client } from './client'; | ||
export { isJsonRpcNotification, isJsonRpcRequest } from './utils'; | ||
//# sourceMappingURL=index.js.map |
@@ -14,2 +14,12 @@ import { isNumber, isObject, isString } from 'lodash'; | ||
/** | ||
* Check if value is an RPC request | ||
* @param value | ||
*/ | ||
export function isJsonRpcRequest(value) { | ||
return isObject(value) | ||
&& value.jsonrpc === JSON_RPC_VERSION | ||
&& isString(value.method) | ||
&& (isString(value.id) || isNumber(value.id)); | ||
} | ||
/** | ||
* Check if value is an RPC error | ||
@@ -16,0 +26,0 @@ * @param value |
@@ -1,2 +0,2 @@ | ||
export { HTTP_ERROR, INTERNAL_ERROR, INVALID_JSON_RESPONSE, INVALID_PARAMS, INVALID_REQUEST, METHOD_NOT_FOUND, PARSE_ERROR, REQUEST_ABORTED, SOCKET_CLOSED, SOCKET_PIPE_BROKEN } from './constants'; | ||
export { HTTP_ERROR, INTERNAL_ERROR, INVALID_JSON_RESPONSE, INVALID_PARAMS, INVALID_REQUEST, JSON_RPC_VERSION, METHOD_NOT_FOUND, PARSE_ERROR, PROGRESS_EVENT, REQUEST_ABORTED, SOCKET_CLOSED, SOCKET_PIPE_BROKEN } from './constants'; | ||
export { JsonRpcError } from './error'; | ||
@@ -7,2 +7,3 @@ export { Notification } from './notification'; | ||
export { Client } from './client'; | ||
export { isJsonRpcNotification, isJsonRpcRequest } from './utils'; | ||
//# sourceMappingURL=index.js.map |
@@ -14,2 +14,12 @@ import { isNumber, isObject, isString } from 'lodash'; | ||
/** | ||
* Check if value is an RPC request | ||
* @param value | ||
*/ | ||
export function isJsonRpcRequest(value) { | ||
return isObject(value) | ||
&& value.jsonrpc === JSON_RPC_VERSION | ||
&& isString(value.method) | ||
&& (isString(value.id) || isNumber(value.id)); | ||
} | ||
/** | ||
* Check if value is an RPC error | ||
@@ -16,0 +26,0 @@ * @param value |
@@ -1,2 +0,2 @@ | ||
export { HTTP_ERROR, INTERNAL_ERROR, INVALID_JSON_RESPONSE, INVALID_PARAMS, INVALID_REQUEST, METHOD_NOT_FOUND, PARSE_ERROR, REQUEST_ABORTED, SOCKET_CLOSED, SOCKET_PIPE_BROKEN } from './constants'; | ||
export { HTTP_ERROR, INTERNAL_ERROR, INVALID_JSON_RESPONSE, INVALID_PARAMS, INVALID_REQUEST, JSON_RPC_VERSION, METHOD_NOT_FOUND, PARSE_ERROR, PROGRESS_EVENT, REQUEST_ABORTED, SOCKET_CLOSED, SOCKET_PIPE_BROKEN } from './constants'; | ||
export { JsonRpcError } from './error'; | ||
@@ -6,3 +6,4 @@ export { Notification } from './notification'; | ||
export { Response } from './response'; | ||
export { Progress } from './types'; | ||
export { BatchResponse, BatchTask, Client, ClientOptions, RequestTask, TaskEvent } from './client'; | ||
export { isJsonRpcNotification, isJsonRpcRequest } from './utils'; | ||
export { JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, Progress } from './types'; |
@@ -9,4 +9,6 @@ "use strict"; | ||
exports.INVALID_REQUEST = constants_1.INVALID_REQUEST; | ||
exports.JSON_RPC_VERSION = constants_1.JSON_RPC_VERSION; | ||
exports.METHOD_NOT_FOUND = constants_1.METHOD_NOT_FOUND; | ||
exports.PARSE_ERROR = constants_1.PARSE_ERROR; | ||
exports.PROGRESS_EVENT = constants_1.PROGRESS_EVENT; | ||
exports.REQUEST_ABORTED = constants_1.REQUEST_ABORTED; | ||
@@ -25,2 +27,5 @@ exports.SOCKET_CLOSED = constants_1.SOCKET_CLOSED; | ||
exports.Client = client_1.Client; | ||
var utils_1 = require("./utils"); | ||
exports.isJsonRpcNotification = utils_1.isJsonRpcNotification; | ||
exports.isJsonRpcRequest = utils_1.isJsonRpcRequest; | ||
//# sourceMappingURL=index.js.map |
import { Notification } from './notification'; | ||
import { Request } from './request'; | ||
import { JsonRpcErrorObject, JsonRpcNotification } from './types'; | ||
import { JsonRpcErrorObject, JsonRpcNotification, JsonRpcRequest } from './types'; | ||
/** | ||
@@ -10,2 +10,7 @@ * Check if value is a RPC notification | ||
/** | ||
* Check if value is an RPC request | ||
* @param value | ||
*/ | ||
export declare function isJsonRpcRequest<T>(value: any): value is JsonRpcRequest<T>; | ||
/** | ||
* Check if value is an RPC error | ||
@@ -12,0 +17,0 @@ * @param value |
@@ -17,2 +17,13 @@ "use strict"; | ||
/** | ||
* Check if value is an RPC request | ||
* @param value | ||
*/ | ||
function isJsonRpcRequest(value) { | ||
return lodash_1.isObject(value) | ||
&& value.jsonrpc === constants_1.JSON_RPC_VERSION | ||
&& lodash_1.isString(value.method) | ||
&& (lodash_1.isString(value.id) || lodash_1.isNumber(value.id)); | ||
} | ||
exports.isJsonRpcRequest = isJsonRpcRequest; | ||
/** | ||
* Check if value is an RPC error | ||
@@ -19,0 +30,0 @@ * @param value |
{ | ||
"name": "rockets-client", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -7,4 +7,6 @@ export { | ||
INVALID_REQUEST, | ||
JSON_RPC_VERSION, | ||
METHOD_NOT_FOUND, | ||
PARSE_ERROR, | ||
PROGRESS_EVENT, | ||
REQUEST_ABORTED, | ||
@@ -20,4 +22,2 @@ SOCKET_CLOSED, | ||
export {Progress} from './types'; | ||
export { | ||
@@ -31,1 +31,13 @@ BatchResponse, | ||
} from './client'; | ||
export { | ||
isJsonRpcNotification, | ||
isJsonRpcRequest | ||
} from './utils'; | ||
export { | ||
JsonRpcNotification, | ||
JsonRpcRequest, | ||
JsonRpcResponse, | ||
Progress | ||
} from './types'; |
import uid from 'crypto-uid'; | ||
import { | ||
isNumber, | ||
isObject, | ||
isString | ||
} from 'lodash'; | ||
import { | ||
JSON_RPC_VERSION, | ||
@@ -13,3 +8,2 @@ UID_BYTE_LENGTH | ||
JsonRpcNotification, | ||
JsonRpcRequest, | ||
JsonRpcResponse | ||
@@ -27,9 +21,2 @@ } from './types'; | ||
export function isJsonRpcRequest<T>(value: any): value is JsonRpcRequest<T> { | ||
return isObject(value) | ||
&& value.jsonrpc === JSON_RPC_VERSION | ||
&& isString(value.method) | ||
&& (isString(value.id) || isNumber(value.id)); | ||
} | ||
export function createJsonRpcNotification<T>(method: string, params?: T): JsonRpcNotification<T> { | ||
@@ -36,0 +23,0 @@ return { |
@@ -11,3 +11,4 @@ import { | ||
JsonRpcErrorObject, | ||
JsonRpcNotification | ||
JsonRpcNotification, | ||
JsonRpcRequest | ||
} from './types'; | ||
@@ -27,2 +28,13 @@ | ||
/** | ||
* Check if value is an RPC request | ||
* @param value | ||
*/ | ||
export function isJsonRpcRequest<T>(value: any): value is JsonRpcRequest<T> { | ||
return isObject(value) | ||
&& value.jsonrpc === JSON_RPC_VERSION | ||
&& isString(value.method) | ||
&& (isString(value.id) || isNumber(value.id)); | ||
} | ||
/** | ||
* Check if value is an RPC error | ||
@@ -29,0 +41,0 @@ * @param value |
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
313438
4511