UNPKG

tempus-api-graphql

Version:

A GraphQL wrapper for the tempus api (tempus2.xyz)

264 lines (212 loc) 10.3 kB
"use strict"; 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); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _base_model = _interopRequireDefault(require("./base_model")); var _player = _interopRequireDefault(require("./player")); var _map = _interopRequireDefault(require("./map")); var _demo = _interopRequireDefault(require("./demo")); var _zone = _interopRequireDefault(require("./zone")); var _server = _interopRequireDefault(require("./server")); var _split = _interopRequireDefault(require("./split")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } 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 _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var Record = /*#__PURE__*/function (_BaseModel) { _inherits(Record, _BaseModel); var _super = _createSuper(Record); function Record() { _classCallCheck(this, Record); return _super.apply(this, arguments); } _createClass(Record, [{ key: "fetchRecord", value: function fetchRecord() { return this.context.tempus.recordsById.load(this.attrs.id); } }, { key: "id", value: function id() { return this.attrs.id; } }, { key: "player", value: function player() { var _this = this; if (this.attrs.player_info) return new _player["default"](this.context, this.attrs.player_info); return this.access("player", function (r) { return new _player["default"](_this.context, r.player_info); }); } }, { key: "duration", value: function duration() { return this.access("duration", function (r) { return r.record_info.duration; }); } }, { key: "date", value: function date() { return this.access("date", function (r) { return r.record_info.date; }); } }, { key: "rank", value: function rank() { return this.access("rank", function (r) { return r.record_info.rank; }); } }, { key: "tiers", value: function tiers() { return this.access("tiers", function (r) { return r.tier_info; }); } }, { key: "map", value: function map() { var _this2 = this; if (this.attrs.map_info) return new _map["default"](this.context, this.attrs.map_info); return this.access("map", function (r) { return new _map["default"](_this2.context, r.map_info); }); } }, { key: "class", value: function _class() { if (this.attrs["class"]) return this.attrs["class"] === 3 ? "soldier" : "demoman"; return this.access(null, function (r) { return r.record_info["class"] === 3 ? "soldier" : "demoman"; }); } }, { key: "demo", value: function demo() { var _this3 = this; if (this.attrs.demo_info) return new _demo["default"](this.context, this.attrs.demo_info); return this.access("demo", function (r) { return r.demo_info && new _demo["default"](_this3.context, r.demo_info); }); } }, { key: "zone", value: function zone() { var _this4 = this; if (this.attrs.zone_info) return new _zone["default"](this.context, this.attrs.zone_info); return this.access("zone", function (r) { return r.zone_info && new _zone["default"](_this4.context, r.zone_info); }); } }, { key: "demoStartTick", value: function demoStartTick() { return this.access("demo_start_tick", function (r) { return r.record_info.demo_start_tick; }); } }, { key: "demoEndTick", value: function demoEndTick() { return this.access("demo_end_tick", function (r) { return r.record_info.demo_end_tick; }); } }, { key: "server", value: function server() { var _this5 = this; return this.access("server", function (r) { return new _server["default"](_this5.context, { id: r.record_info.server_id }); }); } }, { key: "splits", value: function () { var _splits = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var _this6 = this; var splits, rs, cls; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!(this.rank > 1)) { _context.next = 2; break; } return _context.abrupt("return", []); case 2: splits = this.attrs.splits; if (splits) { _context.next = 19; break; } rs = null; if (!(this.attrs.map_info.name || this.attrs.map.attrs.name)) { _context.next = 11; break; } _context.next = 8; return this.context.tempus.wrsByMapName.load(this.attrs.map_info.name || this.attrs.map.attrs.name); case 8: rs = _context.sent; _context.next = 14; break; case 11: _context.next = 13; return this.context.tempus.wrsByMapId.load(this.attrs.map_info.id || this.attrs.map.attrs.id); case 13: rs = _context.sent; case 14: cls = [3, "soldier"].includes(this.attrs["class"]) ? "soldier" : "demoman"; if (rs[cls]) { _context.next = 17; break; } return _context.abrupt("return", []); case 17: splits = JSON.parse(JSON.stringify(rs[cls].wr.splits)); splits.push({ type: "map", zoneindex: 1, duration: rs[cls].wr.duration, compared_duration: rs[cls].rank2 && rs[cls].rank2.duration }); case 19: return _context.abrupt("return", splits.map(function (split) { return new _split["default"](_this6.context, split); })); case 20: case "end": return _context.stop(); } } }, _callee, this); })); function splits() { return _splits.apply(this, arguments); } return splits; }() }]); return Record; }(_base_model["default"]); var _default = Record; exports["default"] = _default;