-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathjson-rpc.min.js
24 lines (20 loc) · 3.36 KB
/
json-rpc.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
The MIT License (MIT)
Copyright (c) 2014 Oliver Moran
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var JSON_RPC={}; (function(){var e=0;JSON_RPC.Request=function(a,c){this.jsonrpc="2.0";this.method=a;"undefined"!==typeof c&&(this.params=c);this.id=e++};Object.defineProperty(JSON_RPC.Request.prototype,"result",{get:function(){return this._result},set:function(a){delete this.method;delete this.params;delete this.error;this._result=a}});Object.defineProperty(JSON_RPC.Request.prototype,"error",{get:function(){return this._error},set:function(a){delete this.method;delete this.params;delete this.result;this._error=a}}); JSON_RPC.Request.prototype.toString=function(){var a={jsonrpc:this.jsonrpc,id:this.id};void 0!==this.method&&(a.method=this.method);void 0!==this.params&&(a.params=this.params);void 0!==this.result&&(a.result=this.result);void 0!==this.error&&(a.error=this.error);return JSON.stringify(a)};JSON_RPC.Notification=function(a,c){this.jsonrpc="2.0";this.method=a;"undefined"!==typeof c&&(this.params=c)};JSON_RPC.Notification.prototype.toString=function(){return JSON.stringify({jsonrpc:this.jsonrpc,method:this.method, params:this.params})};JSON_RPC.Error=function(a,c,d){this.code=a;"string"==typeof c&&(this.message=c);void 0!==d&&(this.data=d)};JSON_RPC.PARSE_ERROR=new JSON_RPC.Error(-32700,"An error occurred on the server while parsing the JSON text.");JSON_RPC.INVALID_REQUEST=new JSON_RPC.Error(-32600,"The JSON sent is not a valid Request object.");JSON_RPC.METHOD_NOT_FOUND=new JSON_RPC.Error(-32601,"The method does not exist / is not available.");JSON_RPC.INVALID_PARAMS=new JSON_RPC.Error(-32602,"Invalid method parameter(s)."); JSON_RPC.INTERNAL_ERROR=new JSON_RPC.Error(-32603,"Internal JSON-RPC error.");JSON_RPC.parse=function(a){if(a.constructor===Array){var c=[];a.forEach(function(a){c.push(JSON_RPC.parse(a))});return c}try{a=JSON.parse(a)}catch(d){var b=new JSON_RPC.Request();b.result=JSON_RPC.PARSE_ERROR;b.id=null;return b}if("2.0"!==a.jsonrpc)return b=new JSON_RPC.Request(),b.result=JSON_RPC.INVALID_REQUEST,b.id=null,b;b=void 0===a.id?new JSON_RPC.Notification(a.method,a.params):new JSON_RPC.Request(a.method,a.params);void 0!== a.id&&(b.id=a.id);void 0!==a.result&&(b.result=a.result);void 0!==a.error&&(b.error=new JSON_RPC.Error(a.error.code,a.error.message,a.error.data));return b}})();try{module.exports=JSON_RPC}catch(err$$1){};