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sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/jsonrpc-dispatch@2.3.0/lib/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\n\nvar _freeze = require('babel-runtime/core-js/object/freeze');\n\nvar _freeze2 = _interopRequireDefault(_freeze);\n\nvar _promise = require('babel-runtime/core-js/promise');\n\nvar _promise2 = _interopRequireDefault(_promise);\n\nvar _extends2 = require('babel-runtime/helpers/extends');\n\nvar _extends3 = _interopRequireDefault(_extends2);\n\nvar _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');\n\nvar _classCallCheck3 = _interopRequireDefault(_classCallCheck2);\n\nvar _createClass2 = require('babel-runtime/helpers/createClass');\n\nvar _createClass3 = _interopRequireDefault(_createClass2);\n\nvar _uuid = require('uuid');\n\nvar _uuid2 = _interopRequireDefault(_uuid);\n\nvar _errors = require('./errors');\n\nvar _errors2 = _interopRequireDefault(_errors);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar JSONRPCVersion = '2.0';\n\n/**\n * JSONRPC class based on the JSONRPC specification[0]. This object handles creating JSONRPC\n * requests and notification objects and managing resolving responses.\n *\n * @see {@link  http://json-rpc.org/wiki/specification}\n */\n\nvar JSONRPC = function () {\n  /**\n   * Initializes a JSONRPC instance.\n   * @param {function} dispatcher - A function which takes a single argument for\n   *                                the JSONRPC object to send to the RPC server.\n   * @param {object} methods - The JSONRPC methods to handle.\n   */\n  function JSONRPC(dispatcher) {\n    var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n    (0, _classCallCheck3.default)(this, JSONRPC);\n\n    this.version = JSONRPCVersion;\n    this.deferreds = {};\n    this.methods = methods;\n    this.dispatcher = dispatcher;\n  }\n\n  /**\n   * Sends the given JSONPRC message using the dispatcher provided.\n   * @param {object} message - A JSONPRC 2.0 message object.\n   */\n\n\n  (0, _createClass3.default)(JSONRPC, [{\n    key: 'send',\n    value: function send(message) {\n      var data = (0, _extends3.default)({}, message);\n      data.jsonrpc = this.version;\n\n      this.dispatcher(data);\n    }\n\n    /**\n     * Create a notification object for the given method and params.\n     * @see {@link  http://www.jsonrpc.org/specification#notification|JSONRPC Notifications}\n     *\n     * @param {string} method - The RPC method to execute\n     * @param {object[]} params - The parameters to execute with the method.\n     * @returns {object} JSONRPC notification object\n     */\n\n  }, {\n    key: 'notification',\n    value: function notification(method) {\n      var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n\n      this.send({ method: method, params: params });\n    }\n\n    /**\n     * Create a request object for the given method and params and passes the result to\n     * next(err, result).\n     * @see {@link  http://www.jsonrpc.org/specification#request_object|JSONRPC Requests}\n     *\n     * @param {string} method - The RPC method to execute\n     * @param {object[]} params - The parameters to execute with the method.\n     * @returns {Promise} which is resolved with the response value.\n     */\n\n  }, {\n    key: 'request',\n    value: function request(method) {\n      var _this = this;\n\n      var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n\n      return new _promise2.default(function (resolve, reject) {\n        var id = _uuid2.default.v4();\n\n        // Save the resolve/reject callbacks as a deferred. We do this because\n        // the response may not occur within the scope of the dispatch method. Example\n        // Cross-Domain messaging is sent over postMessage but received via the\n        // message event.\n        _this.deferreds[id] = { resolve: resolve, reject: reject };\n\n        _this.send({ id: id, method: method, params: params });\n      });\n    }\n\n    /**\n    * Handles a JSONRPC message for the following scenarios:\n    * request - Executes the method defined and passes the result to dispatch\n    * response - Resolves the promise associated with the id on the response\n    * notification - Executes the method defined\n    *\n    * @param {object} message - The JSONRPC message to handle.\n    */\n\n  }, {\n    key: 'handle',\n    value: function handle(message) {\n      // Requests and notifications have methods defined.\n      if (message.method) {\n        // Requests have ids\n        if (message.id) {\n          this.handleRequest(message);\n\n          // Notifications have no ids\n        } else {\n          this.handleNotification(message);\n        }\n\n        // Responses have no methods, but have an id\n      } else if (message.id) {\n        this.handleResponse(message);\n      }\n    }\n\n    /**\n    * Handle a JSONRPC response object and resolve the promise associated to the\n    * originating request.\n    * @param {object} response - The JSONRPC response object to handle.\n    */\n\n  }, {\n    key: 'handleResponse',\n    value: function handleResponse(response) {\n      var deferred = this.deferreds[response.id];\n      if (deferred === undefined) {\n        return;\n      }\n\n      if (response.error) {\n        deferred.reject(response.error);\n      } else {\n        deferred.resolve(response.result);\n      }\n\n      delete this.deferreds[response.id];\n    }\n\n    /**\n    * Handle a JSONRPC request object and execute the method it specifies sending\n    * the result to the dispatcher.\n    * @param {object} request - The JSONRPC request object to handle.\n    */\n\n  }, {\n    key: 'handleRequest',\n    value: function handleRequest(request) {\n      var _this2 = this;\n\n      var method = this.methods[request.method];\n      if (typeof method !== 'function') {\n        var error = {\n          message: 'The method ' + method + ' was not found.',\n          code: _errors2.default.METHOD_NOT_FOUND\n        };\n        this.send({ id: request.id, error: error });\n        return;\n      }\n      // Success\n      method.apply(request, request.params).then(function (result) {\n        _this2.send({ id: request.id, result: result });\n        // Error\n      }).catch(function (message) {\n        var error = { message: message, code: _errors2.default.INTERNAL_ERROR };\n        _this2.send({ id: request.id, error: error });\n      });\n    }\n\n    /**\n    * Handle a JSONRPC notification request and execute the method it specifies.\n    * @param {object} request - The JSONRPC notification object to handle.\n    */\n\n  }, {\n    key: 'handleNotification',\n    value: function handleNotification(request) {\n      var method = this.methods[request.method];\n      if (method && typeof method === 'function') {\n        method.apply(request, request.params);\n      }\n    }\n  }]);\n  return JSONRPC;\n}();\n\nexports.default = (0, _freeze2.default)(JSONRPC);"]}