UNPKG

@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.47 kB
"use strict";var y=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var o=(e,t)=>{for(var i in t)y(e,i,{get:t[i],enumerable:!0})},L=(e,t,i,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!k.call(e,n)&&n!==i&&y(e,n,{get:()=>t[n],enumerable:!(p=E(t,n))||p.enumerable});return e};var I=e=>L(y({},"__esModule",{value:!0}),e);var r=(e,t,i)=>new Promise((p,n)=>{var $=a=>{try{c(i.next(a))}catch(g){n(g)}},F=a=>{try{c(i.throw(a))}catch(g){n(g)}},c=a=>a.done?p(a.value):Promise.resolve(a.value).then($,F);c((i=i.apply(e,t)).next())});var X={};o(X,{films:()=>l,people:()=>h,planets:()=>m,root:()=>f,species:()=>d,starships:()=>u,vehicles:()=>w});module.exports=I(X);var l={};o(l,{getFilmById:()=>b,getFilmSchema:()=>B,getFilms:()=>_,searchFilms:()=>R});var s="https://sw.simplr.sh/api";function _(){return r(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 b(e){return r(this,null,function*(){let t=yield fetch(`${s}/films/${e}.json`);if(!t.ok)throw new Error("Failed to fetch film, ensure the ID is correct & exists");return t.json()})}function B(){return r(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 R(e){return r(this,null,function*(){return(yield _()).filter(i=>i.title.toLowerCase().includes(e.toLowerCase()))})}var h={};o(h,{getPeople:()=>A,getPersonById:()=>C,getPersonSchema:()=>V,searchPeople:()=>U});function A(){return r(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 C(e){return r(this,null,function*(){let t=yield fetch(`${s}/people/${e}.json`);if(!t.ok)throw new Error("Failed to fetch person, ensure the ID is correct & exists");return t.json()})}function V(){return r(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 U(e){return r(this,null,function*(){return(yield A()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var m={};o(m,{getPlanetById:()=>q,getPlanetSchema:()=>D,getPlanets:()=>x,searchPlanets:()=>G});function x(){return r(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 q(e){return r(this,null,function*(){let t=yield fetch(`${s}/planets/${e}.json`);if(!t.ok)throw new Error("Failed to fetch planet, ensure the ID is correct & exists");return t.json()})}function D(){return r(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 G(e){return r(this,null,function*(){return(yield x()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var f={};o(f,{getRoot:()=>M});function M(){return r(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 d={};o(d,{getSpecies:()=>S,getSpeciesById:()=>T,getSpeciesSchema:()=>z,searchSpecies:()=>H});function S(){return r(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 T(e){return r(this,null,function*(){let t=yield fetch(`${s}/species/${e}.json`);if(!t.ok)throw new Error("Failed to fetch species, ensure the ID is correct & exists");return t.json()})}function z(){return r(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 H(e){return r(this,null,function*(){return(yield S()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var u={};o(u,{getStarshipById:()=>J,getStarshipSchema:()=>K,getStarships:()=>P,searchStarships:()=>N});function P(){return r(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 J(e){return r(this,null,function*(){let t=yield fetch(`${s}/starships/${e}.json`);if(!t.ok)throw new Error("Failed to fetch starship, ensure the ID is correct & exists");return t.json()})}function K(){return r(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 N(e){return r(this,null,function*(){return(yield P()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}var w={};o(w,{getVehicleById:()=>O,getVehicleSchema:()=>Q,getVehicles:()=>j,searchVehicles:()=>W});function j(){return r(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 O(e){return r(this,null,function*(){let t=yield fetch(`${s}/vehicles/${e}.json`);if(!t.ok)throw new Error("Failed to fetch vehicle, ensure the ID is correct & exists");return t.json()})}function Q(){return r(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 W(e){return r(this,null,function*(){return(yield j()).filter(i=>i.name.toLowerCase().includes(e.toLowerCase()))})}0&&(module.exports={films,people,planets,root,species,starships,vehicles});