starchart/web/dist/js/752.0fa9b066.js

2 lines
7.7 KiB
JavaScript

"use strict";(self["webpackChunkstarchart"]=self["webpackChunkstarchart"]||[]).push([[752],{2752:function(t,e,i){i.d(e,{g:function(){return T}});i(7658);function n(t){return n="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},n(t)}function r(t,e){if("object"!==n(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,e||"default");if("object"!==n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function o(t){var e=r(t,"string");return"symbol"===n(e)?e:String(e)}function s(t,e,i){return e=o(e),e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}i(6229),i(7330),i(2062);const a="http://localhost".replace(/\/+$/,"");class c{constructor(t={}){s(this,"configuration",void 0),this.configuration=t}set config(t){this.configuration=t}get basePath(){return null!=this.configuration.basePath?this.configuration.basePath:a}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||m}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const t=this.configuration.apiKey;if(t)return"function"===typeof t?t:()=>t}get accessToken(){const t=this.configuration.accessToken;if(t)return"function"===typeof t?t:async()=>t}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const u=new c;class l{constructor(t=u){s(this,"configuration",void 0),s(this,"middleware",void 0),s(this,"fetchApi",(async(t,e)=>{let i,n={url:t,init:e};for(const o of this.middleware)o.pre&&(n=await o.pre({fetch:this.fetchApi,...n})||n);try{i=await(this.configuration.fetchApi||fetch)(n.url,n.init)}catch(r){for(const t of this.middleware)t.onError&&(i=await t.onError({fetch:this.fetchApi,url:n.url,init:n.init,error:r,response:i?i.clone():void 0})||i);if(void 0===i)throw r instanceof Error?new p(r,"The request failed and the interceptors did not return an alternative response"):r}for(const o of this.middleware)o.post&&(i=await o.post({fetch:this.fetchApi,url:n.url,init:n.init,response:i.clone()})||i);return i})),this.configuration=t,this.middleware=t.middleware}withMiddleware(...t){const e=this.clone();return e.middleware=e.middleware.concat(...t),e}withPreMiddleware(...t){const e=t.map((t=>({pre:t})));return this.withMiddleware(...e)}withPostMiddleware(...t){const e=t.map((t=>({post:t})));return this.withMiddleware(...e)}isJsonMime(t){return!!t&&l.jsonRegex.test(t)}async request(t,e){const{url:i,init:n}=await this.createFetchParams(t,e),r=await this.fetchApi(i,n);if(r&&r.status>=200&&r.status<300)return r;throw new f(r,"Response returned an error code")}async createFetchParams(t,e){let i=this.configuration.basePath+t.path;void 0!==t.query&&0!==Object.keys(t.query).length&&(i+="?"+this.configuration.queryParamsStringify(t.query));const n=Object.assign({},this.configuration.headers,t.headers);Object.keys(n).forEach((t=>void 0===n[t]?delete n[t]:{}));const r="function"===typeof e?e:async()=>e,o={method:t.method,headers:n,body:t.body,credentials:this.configuration.credentials},s={...o,...await r({init:o,context:t})},a={...s,body:d(s.body)||s.body instanceof URLSearchParams||h(s.body)?s.body:JSON.stringify(s.body)};return{url:i,init:a}}clone(){const t=this.constructor,e=new t(this.configuration);return e.middleware=this.middleware.slice(),e}}function h(t){return"undefined"!==typeof Blob&&t instanceof Blob}function d(t){return"undefined"!==typeof FormData&&t instanceof FormData}s(l,"jsonRegex",new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$","i"));class f extends Error{constructor(t,e){super(e),s(this,"response",void 0),s(this,"name","ResponseError"),this.response=t}}class p extends Error{constructor(t,e){super(e),s(this,"cause",void 0),s(this,"name","FetchError"),this.cause=t}}class w extends Error{constructor(t,e){super(e),s(this,"field",void 0),s(this,"name","RequiredError"),this.field=t}}function m(t,e=""){return Object.keys(t).map((i=>g(i,t[i],e))).filter((t=>t.length>0)).join("&")}function g(t,e,i=""){const n=i+(i.length?`[${t}]`:t);if(e instanceof Array){const t=e.map((t=>encodeURIComponent(String(t)))).join(`&${encodeURIComponent(n)}=`);return`${encodeURIComponent(n)}=${t}`}if(e instanceof Set){const n=Array.from(e);return g(t,n,i)}return e instanceof Date?`${encodeURIComponent(n)}=${encodeURIComponent(e.toISOString())}`:e instanceof Object?m(e,n):`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`}class y{constructor(t,e=(t=>t)){s(this,"raw",void 0),s(this,"transformer",void 0),this.raw=t,this.transformer=e}async value(){return this.transformer(await this.raw.json())}}class v{constructor(t){s(this,"raw",void 0),this.raw=t}async value(){return await this.raw.text()}}function b(t){if(void 0!==t)return null===t?null:{color:t.color}}function R(t){return q(t,!1)}function q(t,e){return t}function I(t){return P(t,!1)}function P(t,e){return void 0===t||null===t?t:{bottom:t["bottom"],right:t["right"],width:t["width"]}}function S(t){return j(t,!1)}function j(t,e){return void 0===t||null===t?t:{color:t["color"],id:t["id"]}}function E(t){return k(t,!1)}function k(t,e){return void 0===t||null===t?t:{largeItem:t["large_item"],largeItemMultiplier:t["large_item_multiplier"],smallItem:t["small_item"],smallItemMultiplier:t["small_item_multiplier"]}}function C(t){return A(t,!1)}function A(t,e){return void 0===t||null===t?t:{core:S(t["core"]),description:t["description"],kind:R(t["kind"]),name:t["name"],position:I(t["position"]),size:E(t["size"])}}class $ extends l{async chartRaw(t){const e={},i={},n=await this.request({path:"/api/v1/stars/chart",method:"GET",headers:i,query:e},t);return this.isJsonMime(n.headers.get("content-type"))?new y(n):new v(n)}async chart(t){const e=await this.chartRaw(t);return await e.value()}async discoverRaw(t,e){if(null===t.discoveryLog||void 0===t.discoveryLog)throw new w("discoveryLog","Required parameter requestParameters.discoveryLog was null or undefined when calling discover.");const i={},n={"Content-Type":"application/json"},r=await this.request({path:"/api/v1/stars/discover",method:"POST",headers:n,query:i,body:b(t.discoveryLog)},e);return new y(r,(t=>C(t)))}async discover(t,e){const i=await this.discoverRaw(t,e);return await i.value()}async visitRaw(t,e){if(null===t.planetId||void 0===t.planetId)throw new w("planetId","Required parameter requestParameters.planetId was null or undefined when calling visit.");const i={};void 0!==t.planetId&&(i["planet_id"]=t.planetId);const n={},r=await this.request({path:"/api/v1/stars/visit/",method:"GET",headers:n,query:i},e);return new y(r,(t=>C(t)))}async visit(t,e){const i=await this.visitRaw(t,e);return await i.value()}}function x(){return!1}function M(){return new c({basePath:x()?"http://127.0.0.1:7056":window.location.origin})}var O=i(1020);const T=(0,O.Q_)({id:"chart",state:()=>({loading:!0,stars:[],visiting:void 0}),actions:{async fetchChart(){this.loading=!0,this.stars=await new $(M()).chart().catch((t=>(console.error(t),this.stars))).finally((()=>{this.loading=!1}))},async discover(t){this.loading=!0,await new $(M()).discover({discoveryLog:{color:t}}).then((t=>{this.stars.push(t),this.visiting=t})).catch((t=>{console.error(t)})).finally((()=>{this.loading=!1}))},async visit(t){const e=this.stars.filter((e=>e.core.id===t));e.length>=1?this.visiting=e.pop():(this.loading=!0,await new $(M()).visit({planetId:t}).then((t=>{this.stars.push(t),this.visiting=t})).catch((t=>{console.error(t)})).finally((()=>{this.loading=!1})))}}})}}]);
//# sourceMappingURL=752.0fa9b066.js.map