@simplr-sh/swapi-sdk
Version:
A simple Typescript SDK for the Simplr's Star Wars API (SWAPI) service that provides a simple, typesafe interface to interact with the API.
2 lines (1 loc) • 5.03 kB
JavaScript
var F=Object.defineProperty;var o=(e,r)=>{for(var i in r)F(e,i,{get:r[i],enumerable:!0})};var t=(e,r,i)=>new Promise((P,c)=>{var j=n=>{try{a(i.next(n))}catch(p){c(p)}},$=n=>{try{a(i.throw(n))}catch(p){c(p)}},a=n=>n.done?P(n.value):Promise.resolve(n.value).then(j,$);a((i=i.apply(e,r)).next())});var y={};o(y,{getFilmById:()=>E,getFilmSchema:()=>v,getFilms:()=>g,searchFilms:()=>k});var s="https://sw.simplr.sh/api";function g(){return t(this,null,function*(){let e=yield fetch(`${s}/films/all.json`);if(!e.ok)throw new Error("Failed to fetch films");return e.json()})}function E(e){return t(this,null,function*(){let r=yield fetch(`${s}/films/${e}.json`);if(!r.ok)throw new Error("Failed to fetch film, ensure the ID is correct & exists");return r.json()})}function v(){return t(this,null,function*(){let e=yield fetch(`${s}/films/schema.json`);if(!e.ok)throw new Error("Failed to fetch film schema");return e.json()})}function k(e){return t(this,null,function*(){return(yield g()).filter(i=>i.title.toLowerCase().includes(e.toLowerCase()))})}var h={};o(h,{getPeople:()=>l,getPersonById:()=>L,getPersonSchema:()=>I,searchPeople:()=>b});function l(){return t(this,null,function*(){let e=yield fetch(`${s}/people/all.json`);if(!e.ok)throw new Error("Failed to fetch people");return e.json()})}function L(e){return t(this,null,function*(){let r=yield fetch(`${s}/people/${e}.json`);if(!r.ok)throw new Error("Failed to fetch person, ensure the ID is correct & exists");return r.json()})}function I(){return t(this,null,function*(){let e=yield fetch(`${s}/people/schema.json`);if(!e.ok)throw new Error("Failed to fetch person schema");return e.json()})}function b(e){return t(this,null,function*(){return(yield l()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var f={};o(f,{getPlanetById:()=>B,getPlanetSchema:()=>R,getPlanets:()=>m,searchPlanets:()=>C});function m(){return t(this,null,function*(){let e=yield fetch(`${s}/planets/all.json`);if(!e.ok)throw new Error("Failed to fetch planets");return e.json()})}function B(e){return t(this,null,function*(){let r=yield fetch(`${s}/planets/${e}.json`);if(!r.ok)throw new Error("Failed to fetch planet, ensure the ID is correct & exists");return r.json()})}function R(){return t(this,null,function*(){let e=yield fetch(`${s}/planets/schema.json`);if(!e.ok)throw new Error("Failed to fetch planet schema");return e.json()})}function C(e){return t(this,null,function*(){return(yield m()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var d={};o(d,{getRoot:()=>V});function V(){return t(this,null,function*(){let e=yield fetch(`${s}/root.json`);if(!e.ok)throw new Error("Failed to fetch root endpoints");return e.json()})}var w={};o(w,{getSpecies:()=>u,getSpeciesById:()=>U,getSpeciesSchema:()=>q,searchSpecies:()=>D});function u(){return t(this,null,function*(){let e=yield fetch(`${s}/species/all.json`);if(!e.ok)throw new Error("Failed to fetch species");return e.json()})}function U(e){return t(this,null,function*(){let r=yield fetch(`${s}/species/${e}.json`);if(!r.ok)throw new Error("Failed to fetch species, ensure the ID is correct & exists");return r.json()})}function q(){return t(this,null,function*(){let e=yield fetch(`${s}/species/schema.json`);if(!e.ok)throw new Error("Failed to fetch species schema");return e.json()})}function D(e){return t(this,null,function*(){return(yield u()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var A={};o(A,{getStarshipById:()=>G,getStarshipSchema:()=>M,getStarships:()=>_,searchStarships:()=>T});function _(){return t(this,null,function*(){let e=yield fetch(`${s}/starships/all.json`);if(!e.ok)throw new Error("Failed to fetch starships");return e.json()})}function G(e){return t(this,null,function*(){let r=yield fetch(`${s}/starships/${e}.json`);if(!r.ok)throw new Error("Failed to fetch starship, ensure the ID is correct & exists");return r.json()})}function M(){return t(this,null,function*(){let e=yield fetch(`${s}/starships/schema.json`);if(!e.ok)throw new Error("Failed to fetch starship schema");return e.json()})}function T(e){return t(this,null,function*(){return(yield _()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var S={};o(S,{getVehicleById:()=>z,getVehicleSchema:()=>H,getVehicles:()=>x,searchVehicles:()=>J});function x(){return t(this,null,function*(){let e=yield fetch(`${s}/vehicles/all.json`);if(!e.ok)throw new Error("Failed to fetch vehicles");return e.json()})}function z(e){return t(this,null,function*(){let r=yield fetch(`${s}/vehicles/${e}.json`);if(!r.ok)throw new Error("Failed to fetch vehicle, ensure the ID is correct & exists");return r.json()})}function H(){return t(this,null,function*(){let e=yield fetch(`${s}/vehicles/schema.json`);if(!e.ok)throw new Error("Failed to fetch vehicle schema");return e.json()})}function J(e){return t(this,null,function*(){return(yield x()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}export{y as films,h as people,f as planets,d as root,w as species,A as starships,S as vehicles};