@atsu/formidable-client
Version:
A client for Formidable servers written in TypeScript
1 lines • 6.46 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(self,(function(){return(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{FormidableAPI:()=>O,FormidableAPIInstance:()=>j});var n=function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{c(i.next(e))}catch(e){r(e)}}function s(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((i=i.apply(e,t||[])).next())}))};const i=e=>{const{get:t}=e;return{shipClass:e=>n(void 0,void 0,void 0,(function*(){return yield t({path:"/class",queries:{name:e}})})),hull:e=>n(void 0,void 0,void 0,(function*(){return yield t({path:"/hull",queries:{name:e}})})),id:e=>n(void 0,void 0,void 0,(function*(){return(yield t({path:"/id",queries:{code:e}}))[0]})),nationality:e=>n(void 0,void 0,void 0,(function*(){return yield t({path:"/nationality",queries:{name:e}})})),rarity:e=>n(void 0,void 0,void 0,(function*(){return yield t({path:"/rarity",queries:{name:e}})})),random:()=>n(void 0,void 0,void 0,(function*(){return yield t({path:"/random"})})),search:e=>n(void 0,void 0,void 0,(function*(){return yield t({path:"/search",queries:{name:e}})}))}};var o=function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{c(i.next(e))}catch(e){r(e)}}function s(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((i=i.apply(e,t||[])).next())}))};const r=e=>{const{get:t}=e;return{category:e=>o(void 0,void 0,void 0,(function*(){return yield t({path:"/category",queries:{name:e}})})),nationality:e=>o(void 0,void 0,void 0,(function*(){return yield t({path:"/nationality",queries:{name:e}})})),search:e=>o(void 0,void 0,void 0,(function*(){return yield t({path:"/search",queries:{name:e}})}))}};const a=e=>{const{get:t}=e;return{search:e=>{return n=void 0,i=void 0,r=function*(){return yield t({path:"/search",queries:{name:e}})},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,s)}c((r=r.apply(n,i||[])).next())}));var n,i,o,r}}};const s=e=>{const{get:t}=e;return{search:e=>{return n=void 0,i=void 0,r=function*(){return(yield t({path:"/search",queries:{name:e}}))[0]},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,s)}c((r=r.apply(n,i||[])).next())}));var n,i,o,r}}};const c=e=>{const{get:t}=e;return{ship:e=>{return n=void 0,i=void 0,r=function*(){return(yield t({path:"/ship",queries:{id:e}}))[0]},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,s)}c((r=r.apply(n,i||[])).next())}));var n,i,o,r}}},u=require("@atsu/taihou"),d=e=>!!Array.isArray(e),l=(e,t)=>e in t;var h;!function(e){e.update="update"}(h||(h={}));const p=e=>{let t={};return d(e)?e.forEach((e=>t[e.id]=e)):t[e.id]=e,t},f=require("@atsu/multi-env-impl"),v=require("@azurapi/azurapi");const y=e=>{const t=(0,v.useFetchAPI)({fetch:e.fetch,basePath:e.basePath,sharedOptions:e.sharedOptions,logger:(e,t)=>console.log(e,t)});return{get:n=>{return i=void 0,o=void 0,a=function*(){const{path:i,queries:o={}}=n,r=Object.keys(o).length>0?b(o):"",a=e.formidable.state[e.type];if(l("code",o)&&a[o.code])return console.log("Return by code: "+o.code),[a[o.code]];if(l("name",o)){const e=m(a,o);if(e)return e}const s=Object.assign(Object.assign({},e.sharedOptions),{path:`${i}${r}`});let c=yield t.get(s);return d(c)||(l("code",o)&&(c=Object.assign(Object.assign({},c),{id:o.code})),c=[c]),e.onCache(e.type,c),c},new((r=void 0)||(r=Promise))((function(e,t){function n(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var i;t.done?e(t.value):(i=t.value,i instanceof r?i:new r((function(e){e(i)}))).then(n,s)}c((a=a.apply(i,o||[])).next())}));var i,o,r,a}}},b=e=>{let t="?";return Object.keys(e).forEach(((n,i)=>{0!==i&&(t+="&"),t+=`${n}=${e[n]}`})),t},m=(e,t)=>{const n=Object.keys(e).map((t=>e[t])),{name:i}=t;return i&&(0,v.hasNames)(n)&&v.SharedAPI.getByNames(n).matchAll(i,["en","cn","jp"])||null},g={autoupdate:!0,rate:36e5,useTools:!1,localPath:"./",customToolsImpl:void 0,serverUrl:"https://formidable.herokuapp.com"};class O{constructor(e={}){const t=(e=>{const t=Object.assign(Object.assign({},g),e),n=(()=>{const{store:e}=(0,u.createStore)({formidable:(0,u.createSection)({state:{ships:{},barrages:{},equipments:{},voicelines:{},chapters:{}},actions:{update:({type:e,value:t},n)=>{const i=Object.assign(Object.assign({},n[e]),t);return Object.assign(Object.assign({},n),{[e]:Object.assign(Object.assign({},n[e]),i)})}}})});return e})(),o={sharedOptions:{serverUrl:t.serverUrl||g.serverUrl},fetch:f.ImplHandler.fetch,formidable:n.formidable,onCache:(e,t)=>n.formidable.commit(h.update,{type:e,value:p(t)})};return{api:{ships:i(y(Object.assign(Object.assign({},o),{type:"ships",basePath:"/ships"}))),equipments:r(y(Object.assign(Object.assign({},o),{type:"equipments",basePath:"/equipments"}))),chapters:s(y(Object.assign(Object.assign({},o),{type:"chapters",basePath:"/chapters"}))),voicelines:c(y(Object.assign(Object.assign({},o),{type:"voicelines",basePath:"/voicelines"}))),barrages:a(y(Object.assign(Object.assign({},o),{type:"barrages",basePath:"/barrages"})))},options:t,state:n.formidable.state}})(e);this.options=t.options,this.ships=t.api.ships,this.api=t.api,this.equipments=t.api.equipments,this.chapters=t.api.chapters,this.voicelines=t.api.voicelines,this.barrages=t.api.barrages,this.state=t.state,this.tools=t.tools}}const j=new O;return t})()}));