diff --git a/client/dist/http.js b/client/dist/http.js index 2065a6f..5e849b5 100644 --- a/client/dist/http.js +++ b/client/dist/http.js @@ -1,312 +1,73 @@ -/** - * Transpiled for legacy browsers - */ - -function _typeof(obj) { - "@babel/helpers - typeof"; - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function _typeof(obj) { - return typeof obj; - }; - } else { - _typeof = function _typeof(obj) { - return obj && typeof Symbol === "function" && - obj.constructor === Symbol && obj !== Symbol.prototype - ? "symbol" - : typeof obj; - }; - } - return _typeof(obj); -} +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || - _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } -function _nonIterableSpread() { - throw new TypeError( - "Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", - ); -} +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } -function _iterableToArray(iter) { - if ( - typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || - iter["@@iterator"] != null - ) { - return Array.from(iter); - } -} +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } -function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - if (enumerableOnly) { - symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - }); - } - keys.push.apply(keys, symbols); - } - return keys; -} +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } -function _objectSpread(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - if (i % 2) { - ownKeys(Object(source), true).forEach(function (key) { - _defineProperty(target, key, source[key]); - }); - } else if (Object.getOwnPropertyDescriptors) { - Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - } else { - ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty( - target, - key, - Object.getOwnPropertyDescriptor(source, key), - ); - }); - } - } - return target; -} +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } -function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } -} +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } -function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; -} +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } -function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -} +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function"); - } - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { value: subClass, writable: true, configurable: true }, - }); - if (superClass) _setPrototypeOf(subClass, superClass); -} +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _createSuper(Derived) { - var hasNativeReflectConstruct = _isNativeReflectConstruct(); - return function _createSuperInternal() { - var Super = _getPrototypeOf(Derived), result; - if (hasNativeReflectConstruct) { - var NewTarget = _getPrototypeOf(this).constructor; - result = Reflect.construct(Super, arguments, NewTarget); - } else result = Super.apply(this, arguments); - return _possibleConstructorReturn(this, result); - }; -} +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } -function _possibleConstructorReturn(self, call) { - if (call && (_typeof(call) === "object" || typeof call === "function")) { - return call; - } else if (call !== void 0) { - throw new TypeError( - "Derived constructors may only return object or undefined", - ); - } - return _assertThisInitialized(self); -} +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } -function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError( - "this hasn't been initialised - super() hasn't been called", - ); - } - return self; -} +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _wrapNativeSuper(Class) { - var _cache = typeof Map === "function" ? new Map() : undefined; - _wrapNativeSuper = function _wrapNativeSuper(Class) { - if (Class === null || !_isNativeFunction(Class)) return Class; - if (typeof Class !== "function") { - throw new TypeError("Super expression must either be null or a function"); - } - if (typeof _cache !== "undefined") { - if (_cache.has(Class)) return _cache.get(Class); - _cache.set(Class, Wrapper); - } - function Wrapper() { - return _construct(Class, arguments, _getPrototypeOf(this).constructor); - } - Wrapper.prototype = Object.create(Class.prototype, { - constructor: { - value: Wrapper, - enumerable: false, - writable: true, - configurable: true, - }, - }); - return _setPrototypeOf(Wrapper, Class); - }; - return _wrapNativeSuper(Class); -} +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } -function _construct(Parent, args, Class) { - if (_isNativeReflectConstruct()) _construct = Reflect.construct; - else { - _construct = function _construct(Parent, args, Class) { - var a = [null]; - a.push.apply(a, args); - var Constructor = Function.bind.apply(Parent, a); - var instance = new Constructor(); - if (Class) _setPrototypeOf(instance, Class.prototype); - return instance; - }; - } - return _construct.apply(null, arguments); -} +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } -function _isNativeReflectConstruct() { - if (typeof Reflect === "undefined" || !Reflect.construct) return false; - if (Reflect.construct.sham) return false; - if (typeof Proxy === "function") return true; - try { - Boolean.prototype.valueOf.call( - Reflect.construct(Boolean, [], function () {}), - ); - return true; - } catch (e) { - return false; - } -} +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } -function _isNativeFunction(fn) { - return Function.toString.call(fn).indexOf("[native code]") !== -1; -} +function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } -function _setPrototypeOf(o, p) { - _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { - o.__proto__ = p; - return o; - }; - return _setPrototypeOf(o, p); -} +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } -function _getPrototypeOf(o) { - _getPrototypeOf = Object.setPrototypeOf - ? Object.getPrototypeOf - : function _getPrototypeOf(o) { - return o.__proto__ || Object.getPrototypeOf(o); - }; - return _getPrototypeOf(o); -} +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true, - }); - } else obj[key] = value; - return obj; -} +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } -function _slicedToArray(arr, i) { - return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || - _unsupportedIterableToArray(arr, i) || _nonIterableRest(); -} +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } -function _nonIterableRest() { - throw new TypeError( - "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", - ); -} +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(o); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) { - return _arrayLikeToArray(o, minLen); - } -} +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; - return arr2; -} +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } -function _iterableToArrayLimit(arr, i) { - var _i = arr == null - ? null - : typeof Symbol !== "undefined" && arr[Symbol.iterator] || - arr["@@iterator"]; - if (_i == null) return; - var _arr = []; - var _n = true; - var _d = false; - var _s, _e; - try { - for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - return _arr; -} +function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } -function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; -} +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +// deno-fmt-ignore-file +// deno-lint-ignore-file +// This code was bundled using `deno bundle` and it's not recommended to edit it manually function generateId() { - return window.crypto.getRandomValues(new Uint32Array(1))[0].toString(16); + return crypto.getRandomValues(new Uint32Array(1))[0].toString(16); } function createRequest(_ref) { var method = _ref.method, - params = _ref.params, - _ref$isNotification = _ref.isNotification, - isNotification = _ref$isNotification === void 0 - ? false - : _ref$isNotification, - id = _ref.id; + params = _ref.params, + _ref$isNotification = _ref.isNotification, + isNotification = _ref$isNotification === void 0 ? false : _ref$isNotification, + id = _ref.id; var rpcRequest = { jsonrpc: "2.0", - method: method, + method: method }; params && (rpcRequest.params = params); id = isNotification ? undefined : id !== undefined ? id : generateId(); @@ -315,40 +76,36 @@ function createRequest(_ref) { } function createRequestBatch(batchObj) { - var isNotification = arguments.length > 1 && arguments[1] !== undefined - ? arguments[1] - : false; - return Array.isArray(batchObj) - ? batchObj.map(function (el) { - return Object.entries(el).map(function (_ref2) { - var _ref3 = _slicedToArray(_ref2, 2), + var isNotification = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + return Array.isArray(batchObj) ? batchObj.map(function (el) { + return Object.entries(el).map(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), method = _ref3[0], arr = _ref3[1]; - return arr.map(function (params) { - return createRequest({ - method: method, - params: params, - isNotification: isNotification, - }); + return arr.map(function (params) { + return createRequest({ + method: method, + params: params, + isNotification: isNotification }); }); - }).flat(2) - : Object.entries(batchObj).map(function (_ref4) { - var _ref5 = _slicedToArray(_ref4, 2), + }); + }).flat(2) : Object.entries(batchObj).map(function (_ref4) { + var _ref5 = _slicedToArray(_ref4, 2), key = _ref5[0], value = _ref5[1]; - return createRequest({ - method: value[0], - params: value[1], - isNotification: isNotification, - id: key, - }); + return createRequest({ + method: value[0], + params: value[1], + isNotification: isNotification, + id: key }); + }); } -var BadServerDataError = /*#__PURE__*/ function (_Error) { +var BadServerDataError = /*#__PURE__*/function (_Error) { _inherits(BadServerDataError, _Error); var _super = _createSuper(BadServerDataError); @@ -373,13 +130,11 @@ var BadServerDataError = /*#__PURE__*/ function (_Error) { return _this; } - return BadServerDataError; -}(/*#__PURE__*/ _wrapNativeSuper(Error)); + return _createClass(BadServerDataError); +}( /*#__PURE__*/_wrapNativeSuper(Error)); function validateRpcBasis(data) { - return (data === null || data === void 0 ? void 0 : data.jsonrpc) === "2.0" && - (typeof data.id === "number" || typeof data.id === "string" || - data.id === null); + return (data === null || data === void 0 ? void 0 : data.jsonrpc) === "2.0" && (typeof data.id === "number" || typeof data.id === "string" || data.id === null); } function validateRpcSuccess(data) { @@ -389,62 +144,40 @@ function validateRpcSuccess(data) { function validateRpcFailure(data) { var _data$error; - return typeof (data === null || data === void 0 - ? void 0 - : (_data$error = data.error) === null || _data$error === void 0 - ? void 0 - : _data$error.code) === "number" && - typeof data.error.message === "string"; + return typeof (data === null || data === void 0 ? void 0 : (_data$error = data.error) === null || _data$error === void 0 ? void 0 : _data$error.code) === "number" && typeof data.error.message === "string"; } function validateResponse(data, isNotification) { if (isNotification && data !== undefined) { - throw new BadServerDataError( - null, - "The server's response to the notification contains unexpected data.", - ); + throw new BadServerDataError(null, "The server's response to the notification contains unexpected data."); } if (validateRpcBasis(data)) { - if (validateRpcSuccess(data)) return data; - else if (validateRpcFailure(data)) { - throw new BadServerDataError( - data.id, - data.error.message, - data.error.code, - data.error.data, - ); + if (validateRpcSuccess(data)) return data;else if (validateRpcFailure(data)) { + throw new BadServerDataError(data.id, data.error.message, data.error.code, data.error.data); } } - throw new BadServerDataError( - null, - "The received data is no valid JSON-RPC 2.0 Response object.", - ); + throw new BadServerDataError(null, "The received data is no valid JSON-RPC 2.0 Response object."); } function send(resource, fetchInit) { - return fetch(resource instanceof URL ? resource.href : resource, fetchInit) - .then(function (res) { - return res.status === 204 || res.headers.get("content-length") === "0" - ? undefined - : res.text().then(function (text) { - return text ? JSON.parse(text) : undefined; - })["catch"](function (err) { - return Promise.reject( - new BadServerDataError(null, "The received data is invalid JSON."), - ); - }); + return fetch(resource instanceof URL ? resource.href : resource, fetchInit).then(function (res) { + return res.status === 204 || res.headers.get("content-length") === "0" ? undefined : res.text().then(function (text) { + return text ? JSON.parse(text) : undefined; + })["catch"](function (err) { + return Promise.reject(new BadServerDataError(null, "The received data is invalid JSON.")); }); + }); } -function processBatchArray1(rpcResponseBatch, isNotification) { +function processBatchArray(rpcResponseBatch, isNotification) { return rpcResponseBatch.map(function (rpcResponse) { return validateResponse(rpcResponse, isNotification).result; }); } -function processBatchObject1(rpcResponseBatch, isNotification) { +function processBatchObject(rpcResponseBatch, isNotification) { return rpcResponseBatch.reduce(function (acc, rpcResponse) { var rpcSuccess = validateResponse(rpcResponse, isNotification); @@ -452,116 +185,70 @@ function processBatchObject1(rpcResponseBatch, isNotification) { acc[rpcSuccess.id] = rpcSuccess.result; return acc; } else { - throw new BadServerDataError( - null, - "Type 'null' cannot be used as an index type.", - ); + throw new BadServerDataError(null, "Type 'null' cannot be used as an index type."); } }, {}); } -var Remote1 = /*#__PURE__*/ function () { - function Remote1(resource) { - var options = arguments.length > 1 && arguments[1] !== undefined - ? arguments[1] - : {}; +var Remote = /*#__PURE__*/function () { + function Remote(resource) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - _classCallCheck(this, Remote1); + _classCallCheck(this, Remote); _defineProperty(this, "resource", void 0); _defineProperty(this, "fetchInit", void 0); - var headers = options.headers === undefined - ? new Headers() - : options.headers instanceof Headers - ? options.headers - : new Headers(options.headers); + var headers = options.headers === undefined ? new Headers() : options.headers instanceof Headers ? options.headers : new Headers(options.headers); headers.set("Content-Type", "application/json"); this.fetchInit = _objectSpread(_objectSpread({}, options), {}, { method: "POST", - headers: headers, + headers: headers }); this.resource = resource; } - _createClass(Remote1, [{ + _createClass(Remote, [{ key: "batch", value: function batch(batchObj) { - var _ref6 = arguments.length > 1 && arguments[1] !== undefined - ? arguments[1] - : {}, - isNotification = _ref6.isNotification, - jwt = _ref6.jwt; - - return send( - this.resource, - _objectSpread(_objectSpread({}, this.fetchInit), {}, { - headers: jwt - ? new Headers( - [].concat(_toConsumableArray(this.fetchInit.headers.entries()), [[ - "Authorization", - "Bearer ".concat(jwt), - ]]), - ) - : this.fetchInit.headers, - body: JSON.stringify(createRequestBatch(batchObj, isNotification)), - }), - ).then(function (rpcResponseBatch) { + var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + isNotification = _ref6.isNotification, + jwt = _ref6.jwt; + + return send(this.resource, _objectSpread(_objectSpread({}, this.fetchInit), {}, { + headers: jwt ? new Headers([].concat(_toConsumableArray(this.fetchInit.headers.entries()), [["Authorization", "Bearer ".concat(jwt)]])) : this.fetchInit.headers, + body: JSON.stringify(createRequestBatch(batchObj, isNotification)) + })).then(function (rpcResponseBatch) { if (rpcResponseBatch === undefined && isNotification) { return rpcResponseBatch; - } else if ( - Array.isArray(rpcResponseBatch) && rpcResponseBatch.length > 0 - ) { - return Array.isArray(batchObj) - ? processBatchArray1(rpcResponseBatch, isNotification) - : processBatchObject1(rpcResponseBatch, isNotification); + } else if (Array.isArray(rpcResponseBatch) && rpcResponseBatch.length > 0) { + return Array.isArray(batchObj) ? processBatchArray(rpcResponseBatch, isNotification) : processBatchObject(rpcResponseBatch, isNotification); } else { - throw new BadServerDataError( - null, - "The server returned an invalid batch response.", - ); + throw new BadServerDataError(null, "The server returned an invalid batch response."); } }); - }, + } }, { key: "call", value: function call(method, params) { - var _ref7 = arguments.length > 2 && arguments[2] !== undefined - ? arguments[2] - : {}, - isNotification = _ref7.isNotification, - jwt = _ref7.jwt; + var _ref7 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + isNotification = _ref7.isNotification, + jwt = _ref7.jwt; var rpcRequestObj = createRequest({ method: method, params: params, - isNotification: isNotification, + isNotification: isNotification }); - return send( - this.resource, - _objectSpread(_objectSpread({}, this.fetchInit), {}, { - headers: jwt - ? new Headers( - [].concat(_toConsumableArray(this.fetchInit.headers.entries()), [[ - "Authorization", - "Bearer ".concat(jwt), - ]]), - ) - : this.fetchInit.headers, - body: JSON.stringify(rpcRequestObj), - }), - ).then(function (rpcResponse) { - return rpcResponse === undefined && isNotification - ? undefined - : validateResponse(rpcResponse, isNotification).result; + return send(this.resource, _objectSpread(_objectSpread({}, this.fetchInit), {}, { + headers: jwt ? new Headers([].concat(_toConsumableArray(this.fetchInit.headers.entries()), [["Authorization", "Bearer ".concat(jwt)]])) : this.fetchInit.headers, + body: JSON.stringify(rpcRequestObj) + })).then(function (rpcResponse) { + return rpcResponse === undefined && isNotification ? undefined : validateResponse(rpcResponse, isNotification).result; }); - }, + } }]); - return Remote1; + return Remote; }(); - -export { processBatchArray1 as processBatchArray }; -export { processBatchObject1 as processBatchObject }; -export { Remote1 as Remote }; diff --git a/client/dist/remote.js b/client/dist/remote.js index 3a773fd..f51d587 100644 --- a/client/dist/remote.js +++ b/client/dist/remote.js @@ -1,385 +1,322 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file +// This code was bundled using `deno bundle` and it's not recommended to edit it manually + function generateId() { - return window.crypto.getRandomValues(new Uint32Array(1))[0].toString(16); + return crypto.getRandomValues(new Uint32Array(1))[0].toString(16); } -function createRequest({ method, params, isNotification = false, id }) { - const rpcRequest = { - jsonrpc: "2.0", - method, - }; - params && (rpcRequest.params = params); - id = isNotification ? undefined : id !== undefined ? id : generateId(); - id !== undefined && (rpcRequest.id = id); - return rpcRequest; +function createRequest({ method , params , isNotification =false , id }) { + const rpcRequest = { + jsonrpc: "2.0", + method + }; + params && (rpcRequest.params = params); + id = isNotification ? undefined : id !== undefined ? id : generateId(); + id !== undefined && (rpcRequest.id = id); + return rpcRequest; } function createRequestBatch(batchObj, isNotification = false) { - return Array.isArray(batchObj) - ? batchObj.map((el) => - Object.entries(el).map(([method, arr]) => - arr.map((params) => - createRequest({ - method, - params, + return Array.isArray(batchObj) ? batchObj.map((el)=>Object.entries(el).map(([method, arr])=>arr.map((params)=>createRequest({ + method, + params, + isNotification + })))).flat(2) : Object.entries(batchObj).map(([key, value])=>createRequest({ + method: value[0], + params: value[1], isNotification, - }) - ) - ) - ).flat(2) - : Object.entries(batchObj).map(([key, value]) => - createRequest({ - method: value[0], - params: value[1], - isNotification, - id: key, - }) - ); + id: key + })); } class BadServerDataError extends Error { - id; - code; - data; - constructor(id, message, errorCode, data) { - super(message); - this.name = this.constructor.name; - this.id = id; - this.code = errorCode; - this.data = data; - } + id; + code; + data; + constructor(id, message, errorCode, data){ + super(message); + this.name = this.constructor.name; + this.id = id; + this.code = errorCode; + this.data = data; + } } function validateRpcNotification(data) { - return data?.jsonrpc === "2.0" && typeof data.method === "string" && - typeof data.id === "undefined"; + return data?.jsonrpc === "2.0" && typeof data.method === "string" && typeof data.id === "undefined"; } function validateRpcBasis(data) { - return data?.jsonrpc === "2.0" && - (typeof data.id === "number" || typeof data.id === "string" || - data.id === null); + return data?.jsonrpc === "2.0" && (typeof data.id === "number" || typeof data.id === "string" || data.id === null); } function validateRpcSuccess(data) { - return "result" in data; + return "result" in data; } function validateRpcFailure(data) { - return typeof data?.error?.code === "number" && - typeof data.error.message === "string"; + return typeof data?.error?.code === "number" && typeof data.error.message === "string"; } function validateResponse(data, isNotification) { - if (isNotification && data !== undefined) { - throw new BadServerDataError( - null, - "The server's response to the notification contains unexpected data.", - ); - } - if (validateRpcBasis(data)) { - if (validateRpcSuccess(data)) return data; - else if (validateRpcFailure(data)) { - throw new BadServerDataError( - data.id, - data.error.message, - data.error.code, - data.error.data, - ); + if (isNotification && data !== undefined) { + throw new BadServerDataError(null, "The server's response to the notification contains unexpected data."); + } + if (validateRpcBasis(data)) { + if (validateRpcSuccess(data)) return data; + else if (validateRpcFailure(data)) { + throw new BadServerDataError(data.id, data.error.message, data.error.code, data.error.data); + } } - } - throw new BadServerDataError( - null, - "The received data is no valid JSON-RPC 2.0 Response object.", - ); + throw new BadServerDataError(null, "The received data is no valid JSON-RPC 2.0 Response object."); } function send(resource, fetchInit) { - return fetch(resource instanceof URL ? resource.href : resource, fetchInit) - .then((res) => - res.status === 204 || res.headers.get("content-length") === "0" - ? undefined - : res.text().then((text) => text ? JSON.parse(text) : undefined).catch(( - err, - ) => - Promise.reject( - new BadServerDataError(null, "The received data is invalid JSON."), - ) - ) - ); + return fetch(resource instanceof URL ? resource.href : resource, fetchInit).then((res)=>res.status === 204 || res.headers.get("content-length") === "0" ? undefined : res.text().then((text)=>text ? JSON.parse(text) : undefined).catch((err)=>Promise.reject(new BadServerDataError(null, "The received data is invalid JSON.")))); } function processBatchArray(rpcResponseBatch, isNotification) { - return rpcResponseBatch.map((rpcResponse) => - validateResponse(rpcResponse, isNotification).result - ); + return rpcResponseBatch.map((rpcResponse)=>validateResponse(rpcResponse, isNotification).result); } function processBatchObject(rpcResponseBatch, isNotification) { - return rpcResponseBatch.reduce((acc, rpcResponse) => { - const rpcSuccess = validateResponse(rpcResponse, isNotification); - if (rpcSuccess.id !== null) { - acc[rpcSuccess.id] = rpcSuccess.result; - return acc; - } else { - throw new BadServerDataError( - null, - "Type 'null' cannot be used as an index type.", - ); - } - }, {}); + return rpcResponseBatch.reduce((acc, rpcResponse)=>{ + const rpcSuccess = validateResponse(rpcResponse, isNotification); + if (rpcSuccess.id !== null) { + acc[rpcSuccess.id] = rpcSuccess.result; + return acc; + } else { + throw new BadServerDataError(null, "Type 'null' cannot be used as an index type."); + } + }, {}); } class Remote { - resource; - fetchInit; - constructor(resource, options = {}) { - const headers = options.headers === undefined - ? new Headers() - : options.headers instanceof Headers - ? options.headers - : new Headers(options.headers); - headers.set("Content-Type", "application/json"); - this.fetchInit = { - ...options, - method: "POST", - headers, - }; - this.resource = resource; - } - batch(batchObj, { isNotification, jwt } = {}) { - return send(this.resource, { - ...this.fetchInit, - headers: jwt - ? new Headers([ - ...this.fetchInit.headers.entries(), - [ - "Authorization", - `Bearer ${jwt}`, - ], - ]) - : this.fetchInit.headers, - body: JSON.stringify(createRequestBatch(batchObj, isNotification)), - }).then((rpcResponseBatch) => { - if (rpcResponseBatch === undefined && isNotification) { - return rpcResponseBatch; - } else if ( - Array.isArray(rpcResponseBatch) && rpcResponseBatch.length > 0 - ) { - return Array.isArray(batchObj) - ? processBatchArray(rpcResponseBatch, isNotification) - : processBatchObject(rpcResponseBatch, isNotification); - } else { - throw new BadServerDataError( - null, - "The server returned an invalid batch response.", - ); - } - }); - } - call(method, params, { isNotification, jwt } = {}) { - const rpcRequestObj = createRequest({ - method, - params, - isNotification, - }); - return send(this.resource, { - ...this.fetchInit, - headers: jwt - ? new Headers([ - ...this.fetchInit.headers.entries(), - [ - "Authorization", - `Bearer ${jwt}`, - ], - ]) - : this.fetchInit.headers, - body: JSON.stringify(rpcRequestObj), - }).then((rpcResponse) => - rpcResponse === undefined && isNotification - ? undefined - : validateResponse(rpcResponse, isNotification).result - ); - } + resource; + fetchInit; + constructor(resource, options = {}){ + const headers = options.headers === undefined ? new Headers() : options.headers instanceof Headers ? options.headers : new Headers(options.headers); + headers.set("Content-Type", "application/json"); + this.fetchInit = { + ...options, + method: "POST", + headers + }; + this.resource = resource; + } + batch(batchObj, { isNotification , jwt } = {}) { + return send(this.resource, { + ...this.fetchInit, + headers: jwt ? new Headers([ + ...this.fetchInit.headers.entries(), + [ + "Authorization", + `Bearer ${jwt}` + ], + ]) : this.fetchInit.headers, + body: JSON.stringify(createRequestBatch(batchObj, isNotification)) + }).then((rpcResponseBatch)=>{ + if (rpcResponseBatch === undefined && isNotification) { + return rpcResponseBatch; + } else if (Array.isArray(rpcResponseBatch) && rpcResponseBatch.length > 0) { + return Array.isArray(batchObj) ? processBatchArray(rpcResponseBatch, isNotification) : processBatchObject(rpcResponseBatch, isNotification); + } else { + throw new BadServerDataError(null, "The server returned an invalid batch response."); + } + }); + } + call(method, params, { isNotification , jwt } = {}) { + const rpcRequestObj = createRequest({ + method, + params, + isNotification + }); + return send(this.resource, { + ...this.fetchInit, + headers: jwt ? new Headers([ + ...this.fetchInit.headers.entries(), + [ + "Authorization", + `Bearer ${jwt}` + ], + ]) : this.fetchInit.headers, + body: JSON.stringify(rpcRequestObj) + }).then((rpcResponse)=>rpcResponse === undefined && isNotification ? undefined : validateResponse(rpcResponse, isNotification).result); + } } function isObject(obj) { - return obj !== null && typeof obj === "object" && - Array.isArray(obj) === false; + return obj !== null && typeof obj === "object" && Array.isArray(obj) === false; } class Remote1 { - textDecoder; - payloadData; - payloadQueue = []; - socket; - constructor(socket) { - this.socket = socket; - this.getPayloadData(socket); - } - async getPayloadData(socket) { - this.payloadData = new Promise((resolve, reject) => { - if (this.payloadQueue.length > 0) { - const payload = this.payloadQueue.shift(); - resolve(payload); - return; - } - let isResolved = false; - socket.onmessage = async (event) => { - let msg; - if (event.data instanceof Blob) { - msg = this.getTextDecoder().decode(await event.data.arrayBuffer()); - } else if (event.data instanceof ArrayBuffer) { - msg = this.getTextDecoder().decode(event.data); - } else { - msg = event.data; - } - try { - const payload = JSON.parse(msg); - if (isResolved) { - this.payloadQueue.push(payload); - return; - } - resolve(payload); - isResolved = true; - } catch (err) { - reject( - new BadServerDataError(null, "The received data is invalid JSON."), - ); - } - }; - socket.onclose = () => resolve(null); - }); - await this.payloadData; - if (socket.readyState < 2) { - this.getPayloadData(socket); + textDecoder; + payloadData; + payloadQueue = []; + socket; + constructor(socket){ + this.socket = socket; + this.getPayloadData(socket); } - } - getTextDecoder() { - return this.textDecoder || (this.textDecoder = new TextDecoder()); - } - async *iterateRequests(rpcRequest) { - while (this.socket.readyState < 2) { - try { - const payloadData = await this.payloadData; - if (payloadData === null) { - break; - } - if (validateRpcNotification(payloadData)) { - continue; - } - const rpcResponse = validateResponse(payloadData); - if (rpcResponse.id !== rpcRequest.id) { - continue; - } - yield rpcResponse.result; - break; - } catch (err) { - if (err.id === rpcRequest.id || err.id === null) { - yield Promise.reject(err); - break; + async getPayloadData(socket) { + this.payloadData = new Promise((resolve, reject)=>{ + if (this.payloadQueue.length > 0) { + const payload = this.payloadQueue.shift(); + resolve(payload); + return; + } + let isResolved = false; + socket.onmessage = async (event)=>{ + let msg; + if (event.data instanceof Blob) { + msg = this.getTextDecoder().decode(await event.data.arrayBuffer()); + } else if (event.data instanceof ArrayBuffer) { + msg = this.getTextDecoder().decode(event.data); + } else { + msg = event.data; + } + try { + const payload = JSON.parse(msg); + if (isResolved) { + this.payloadQueue.push(payload); + return; + } + resolve(payload); + isResolved = true; + } catch (err) { + reject(new BadServerDataError(null, "The received data is invalid JSON.")); + } + }; + socket.onclose = ()=>resolve(null); + }); + await this.payloadData; + if (socket.readyState < 2) { + this.getPayloadData(socket); } - } } - } - async *iterateSubscriptions(rpcRequest) { - while (this.socket.readyState < 2) { - try { - const payloadData = await this.payloadData; - if (payloadData === null) { - break; - } - if (validateRpcNotification(payloadData)) { - continue; - } - const rpcResponse = validateResponse(payloadData); - if (rpcResponse.id !== rpcRequest.id) { - continue; - } - if ( - isObject(rpcResponse.result) && - rpcResponse.result.id === rpcRequest.id - ) { - if (rpcResponse.result.event === "subscribed") { - continue; - } else if (rpcResponse.result.event === "unsubscribed") { - break; - } else if (rpcResponse.result.event === "emitted") { - continue; - } - } else { - yield rpcResponse.result; - continue; + getTextDecoder() { + return this.textDecoder || (this.textDecoder = new TextDecoder()); + } + async *iterateRequests(rpcRequest) { + while(this.socket.readyState < 2){ + try { + const payloadData = await this.payloadData; + if (payloadData === null) { + break; + } + if (validateRpcNotification(payloadData)) { + continue; + } + const rpcResponse = validateResponse(payloadData); + if (rpcResponse.id !== rpcRequest.id) { + continue; + } + yield rpcResponse.result; + break; + } catch (err) { + if (err.id === rpcRequest.id || err.id === null) { + yield Promise.reject(err); + break; + } + } } - } catch (err) { - if (err.id === rpcRequest.id || err.id === null) { - yield Promise.reject(err); - break; + } + async *iterateSubscriptions(rpcRequest) { + while(this.socket.readyState < 2){ + try { + const payloadData = await this.payloadData; + if (payloadData === null) { + break; + } + if (validateRpcNotification(payloadData)) { + continue; + } + const rpcResponse = validateResponse(payloadData); + if (rpcResponse.id !== rpcRequest.id) { + continue; + } + if (isObject(rpcResponse.result) && rpcResponse.result.id === rpcRequest.id) { + if (rpcResponse.result.event === "subscribed") { + continue; + } else if (rpcResponse.result.event === "unsubscribed") { + break; + } else if (rpcResponse.result.event === "emitted") { + continue; + } + } else { + yield rpcResponse.result; + continue; + } + } catch (err) { + if (err.id === rpcRequest.id || err.id === null) { + yield Promise.reject(err); + break; + } + } } - } } - } - async *iterateNotifications(eventName) { - while (this.socket.readyState < 2) { - const payloadData = await this.payloadData; - if (payloadData === null) { - break; - } - if (validateRpcNotification(payloadData)) { - const rpcNotification = payloadData; - if (rpcNotification.method === eventName) { - yield rpcNotification.params || null; + async *iterateNotifications(eventName) { + while(this.socket.readyState < 2){ + const payloadData = await this.payloadData; + if (payloadData === null) { + break; + } + if (validateRpcNotification(payloadData)) { + const rpcNotification = payloadData; + if (rpcNotification.method === eventName) { + yield rpcNotification.params || null; + } + } } - } } - } - call(method, params, { isNotification } = {}) { - const rpcRequest = createRequest({ - method, - params, - isNotification, - }); - this.socket.send(JSON.stringify(rpcRequest)); - if (isNotification) return Promise.resolve(undefined); - const generator = this.iterateRequests(rpcRequest); - return generator.next().then((p) => p.value); - } - subscribe(method) { - const rpcRequest = createRequest({ - method: "subscribe", - }); - this.socket.send(JSON.stringify({ - ...rpcRequest, - params: { - method, - id: rpcRequest.id, - }, - })); - return { - generator: this.iterateSubscriptions(rpcRequest), - unsubscribe: (params) => { - const rpcRequestUnsubscription = createRequest({ - method: "unsubscribe", - params: { - method, - id: rpcRequest.id, - }, - }); - return this.socket.send(JSON.stringify(rpcRequestUnsubscription)); - }, - emit: (params) => { - return this.socket.send(JSON.stringify({ - ...rpcRequest, - method: "emit", - params: { + call(method, params, { isNotification } = {}) { + const rpcRequest = createRequest({ method, params, - id: rpcRequest.id, - }, + isNotification + }); + this.socket.send(JSON.stringify(rpcRequest)); + if (isNotification) return Promise.resolve(undefined); + const generator = this.iterateRequests(rpcRequest); + return generator.next().then((p)=>p.value); + } + subscribe(method) { + const rpcRequest = createRequest({ + method: "subscribe" + }); + this.socket.send(JSON.stringify({ + ...rpcRequest, + params: { + method, + id: rpcRequest.id + } })); - }, - }; - } - listen(eventName) { - return { - generator: this.iterateNotifications(eventName), - }; - } + return { + generator: this.iterateSubscriptions(rpcRequest), + unsubscribe: (params)=>{ + const rpcRequestUnsubscription = createRequest({ + method: "unsubscribe", + params: { + method, + id: rpcRequest.id + } + }); + return this.socket.send(JSON.stringify(rpcRequestUnsubscription)); + }, + emit: (params)=>{ + return this.socket.send(JSON.stringify({ + ...rpcRequest, + method: "emit", + params: { + method, + params, + id: rpcRequest.id + } + })); + } + }; + } + listen(eventName) { + return { + generator: this.iterateNotifications(eventName) + }; + } } function listen(socket) { - return new Promise((resolve, reject) => { - socket.onopen = () => resolve(socket); - socket.onerror = (err) => reject(err); - }); + return new Promise((resolve, reject)=>{ + socket.onopen = ()=>resolve(socket); + socket.onerror = (err)=>reject(err); + }); } -function createRemote1(resourceOrSocket, options) { - return resourceOrSocket instanceof WebSocket - ? listen(resourceOrSocket).then((socket) => new Remote1(socket)) - : new Remote(resourceOrSocket, options); +function createRemote(resourceOrSocket, options) { + return resourceOrSocket instanceof WebSocket ? listen(resourceOrSocket).then((socket)=>new Remote1(socket)) : new Remote(resourceOrSocket, options); } -export { createRemote1 as createRemote }; +export { createRemote as createRemote }; +