add error. linting
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "tmdb-ts",
|
"name": "tmdb-ts",
|
||||||
"version": "1.5.0",
|
"version": "1.6.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "tmdb-ts",
|
"name": "tmdb-ts",
|
||||||
"version": "1.5.0",
|
"version": "1.6.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cross-fetch": "^3.1.4"
|
"cross-fetch": "^3.1.4"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tmdb-ts",
|
"name": "tmdb-ts",
|
||||||
"version": "1.6.0",
|
"version": "1.6.1",
|
||||||
"description": "TMDB v3 library wrapper",
|
"description": "TMDB v3 library wrapper",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import fetch from 'cross-fetch';
|
import fetch from 'cross-fetch';
|
||||||
import { parseOptions } from './utils';
|
import { parseOptions } from './utils';
|
||||||
|
import { ErrorResponse } from './types';
|
||||||
|
|
||||||
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
|
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
|
||||||
|
|
||||||
@@ -17,6 +18,11 @@ export class Api {
|
|||||||
'Content-Type': 'application/json;charset=utf-8',
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return Promise.reject((await response.json()) as ErrorResponse);
|
||||||
|
}
|
||||||
|
|
||||||
return (await response.json()) as T;
|
return (await response.json()) as T;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ export class CollectionsEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async images(id: number, options?: CollectionImageOptions): Promise<ImageCollection> {
|
async images(
|
||||||
|
id: number,
|
||||||
|
options?: CollectionImageOptions
|
||||||
|
): Promise<ImageCollection> {
|
||||||
const computedOptions = {
|
const computedOptions = {
|
||||||
include_image_language: options?.include_image_language?.join(','),
|
include_image_language: options?.include_image_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export interface MoviesImageSearchOptions extends LanguageOption {
|
|||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_image_language?: string[],
|
include_image_language?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MoviesEndpoint extends BaseEndpoint {
|
export class MoviesEndpoint extends BaseEndpoint {
|
||||||
@@ -85,12 +85,18 @@ export class MoviesEndpoint extends BaseEndpoint {
|
|||||||
return await this.api.get<ExternalIds>(`${BASE_MOVIE}/${id}/external_ids`);
|
return await this.api.get<ExternalIds>(`${BASE_MOVIE}/${id}/external_ids`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async images(id: number, options?: MoviesImageSearchOptions): Promise<Images> {
|
async images(
|
||||||
|
id: number,
|
||||||
|
options?: MoviesImageSearchOptions
|
||||||
|
): Promise<Images> {
|
||||||
const computedOptions = {
|
const computedOptions = {
|
||||||
include_image_language: options?.include_image_language?.join(','),
|
include_image_language: options?.include_image_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
};
|
};
|
||||||
return await this.api.get<Images>(`${BASE_MOVIE}/${id}/images`, computedOptions);
|
return await this.api.get<Images>(
|
||||||
|
`${BASE_MOVIE}/${id}/images`,
|
||||||
|
computedOptions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async keywords(id: number): Promise<Keywords> {
|
async keywords(id: number): Promise<Keywords> {
|
||||||
@@ -120,11 +126,17 @@ export class MoviesEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reviews(id: number, options?: LanguageOption & PageOption): Promise<Reviews> {
|
async reviews(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption & PageOption
|
||||||
|
): Promise<Reviews> {
|
||||||
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews`, options);
|
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews`, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async similar(id: number, options?: LanguageOption & PageOption): Promise<SimilarMovies> {
|
async similar(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption & PageOption
|
||||||
|
): Promise<SimilarMovies> {
|
||||||
return await this.api.get<SimilarMovies>(
|
return await this.api.get<SimilarMovies>(
|
||||||
`${BASE_MOVIE}/${id}/similar`,
|
`${BASE_MOVIE}/${id}/similar`,
|
||||||
options
|
options
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class PeopleEndpoint extends BaseEndpoint {
|
|||||||
append_to_response: appendToResponse
|
append_to_response: appendToResponse
|
||||||
? appendToResponse.join(',')
|
? appendToResponse.join(',')
|
||||||
: undefined,
|
: undefined,
|
||||||
language: language
|
language: language,
|
||||||
};
|
};
|
||||||
return await this.api.get<AppendToResponse<PersonDetails, T, 'person'>>(
|
return await this.api.get<AppendToResponse<PersonDetails, T, 'person'>>(
|
||||||
`${BASE_PERSON}/${id}`,
|
`${BASE_PERSON}/${id}`,
|
||||||
@@ -52,21 +52,30 @@ export class PeopleEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async movieCredits(id: number, options?: LanguageOption): Promise<PersonMovieCredit> {
|
async movieCredits(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption
|
||||||
|
): Promise<PersonMovieCredit> {
|
||||||
return await this.api.get<PersonMovieCredit>(
|
return await this.api.get<PersonMovieCredit>(
|
||||||
`${BASE_PERSON}/${id}/movie_credits`,
|
`${BASE_PERSON}/${id}/movie_credits`,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async tvShowCredits(id: number, options?: LanguageOption): Promise<PersonTvShowCredit> {
|
async tvShowCredits(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption
|
||||||
|
): Promise<PersonTvShowCredit> {
|
||||||
return await this.api.get<PersonTvShowCredit>(
|
return await this.api.get<PersonTvShowCredit>(
|
||||||
`${BASE_PERSON}/${id}/tv_credits`,
|
`${BASE_PERSON}/${id}/tv_credits`,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async combinedCredits(id: number, options?: LanguageOption): Promise<PersonCombinedCredits> {
|
async combinedCredits(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption
|
||||||
|
): Promise<PersonCombinedCredits> {
|
||||||
return await this.api.get<PersonCombinedCredits>(
|
return await this.api.get<PersonCombinedCredits>(
|
||||||
`${BASE_PERSON}/${id}/combined_credits`,
|
`${BASE_PERSON}/${id}/combined_credits`,
|
||||||
options
|
options
|
||||||
@@ -98,7 +107,9 @@ export class PeopleEndpoint extends BaseEndpoint {
|
|||||||
return await this.api.get<PersonDetails>(`${BASE_PERSON}/latest`);
|
return await this.api.get<PersonDetails>(`${BASE_PERSON}/latest`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async popular(options?: LanguageOption & PageOption): Promise<PopularPersons> {
|
async popular(
|
||||||
|
options?: LanguageOption & PageOption
|
||||||
|
): Promise<PopularPersons> {
|
||||||
return await this.api.get<PopularPersons>(
|
return await this.api.get<PopularPersons>(
|
||||||
`${BASE_PERSON}/popular`,
|
`${BASE_PERSON}/popular`,
|
||||||
options
|
options
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
import { BaseEndpoint } from './base';
|
import { BaseEndpoint } from './base';
|
||||||
import { MultiSearchResult, Search } from '../types/search';
|
import { MultiSearchResult, Search } from '../types/search';
|
||||||
import { Collection, Company, LanguageOption, Movie, PageOption, Person, RegionOption, TV } from '../types';
|
import {
|
||||||
|
Collection,
|
||||||
|
Company,
|
||||||
|
LanguageOption,
|
||||||
|
Movie,
|
||||||
|
PageOption,
|
||||||
|
Person,
|
||||||
|
RegionOption,
|
||||||
|
TV,
|
||||||
|
} from '../types';
|
||||||
|
|
||||||
const BASE_SEARCH = '/search';
|
const BASE_SEARCH = '/search';
|
||||||
|
|
||||||
@@ -9,27 +18,44 @@ export interface SearchOptions {
|
|||||||
page?: number;
|
page?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MovieSearchOptions extends SearchOptions, LanguageOption, PageOption, RegionOption {
|
export interface MovieSearchOptions
|
||||||
|
extends SearchOptions,
|
||||||
|
LanguageOption,
|
||||||
|
PageOption,
|
||||||
|
RegionOption {
|
||||||
include_adult?: boolean;
|
include_adult?: boolean;
|
||||||
year?: number;
|
year?: number;
|
||||||
primary_release_year?: number;
|
primary_release_year?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollectionSearchOptions extends SearchOptions, LanguageOption, PageOption, RegionOption {
|
export interface CollectionSearchOptions
|
||||||
|
extends SearchOptions,
|
||||||
|
LanguageOption,
|
||||||
|
PageOption,
|
||||||
|
RegionOption {
|
||||||
include_adult?: boolean;
|
include_adult?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TvSearchOptions extends SearchOptions, LanguageOption, PageOption {
|
export interface TvSearchOptions
|
||||||
|
extends SearchOptions,
|
||||||
|
LanguageOption,
|
||||||
|
PageOption {
|
||||||
include_adult?: boolean;
|
include_adult?: boolean;
|
||||||
year?: number;
|
year?: number;
|
||||||
first_air_date_year?: number;
|
first_air_date_year?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PeopleSearchOptions extends SearchOptions, LanguageOption, PageOption {
|
export interface PeopleSearchOptions
|
||||||
|
extends SearchOptions,
|
||||||
|
LanguageOption,
|
||||||
|
PageOption {
|
||||||
include_adult?: boolean;
|
include_adult?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MultiSearchOptions extends SearchOptions, LanguageOption, PageOption {
|
export interface MultiSearchOptions
|
||||||
|
extends SearchOptions,
|
||||||
|
LanguageOption,
|
||||||
|
PageOption {
|
||||||
include_adult?: boolean;
|
include_adult?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { TrendingMediaType, TimeWindow, TrendingResults, LanguageOption } from '../types';
|
import {
|
||||||
|
TrendingMediaType,
|
||||||
|
TimeWindow,
|
||||||
|
TrendingResults,
|
||||||
|
LanguageOption,
|
||||||
|
} from '../types';
|
||||||
import { BaseEndpoint } from './base';
|
import { BaseEndpoint } from './base';
|
||||||
|
|
||||||
export class TrendingEndpoint extends BaseEndpoint {
|
export class TrendingEndpoint extends BaseEndpoint {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
Images,
|
Images,
|
||||||
TvEpisodeTranslations,
|
TvEpisodeTranslations,
|
||||||
Videos,
|
Videos,
|
||||||
AppendToResponseMovieKey,
|
|
||||||
AppendToResponse,
|
AppendToResponse,
|
||||||
Changes,
|
Changes,
|
||||||
TvEpisodeChangeValue,
|
TvEpisodeChangeValue,
|
||||||
@@ -24,14 +23,14 @@ export interface TvEpisodeImageSearchOptions extends LanguageOption {
|
|||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_image_language?: string[],
|
include_image_language?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TvEpisodeVideoSearchOptions extends LanguageOption {
|
export interface TvEpisodeVideoSearchOptions extends LanguageOption {
|
||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_video_language?: string[],
|
include_video_language?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TvEpisodesEndpoint extends BaseEndpoint {
|
export class TvEpisodesEndpoint extends BaseEndpoint {
|
||||||
@@ -76,7 +75,10 @@ export class TvEpisodesEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async images(episodeSelection: EpisodeSelection, options?: TvEpisodeImageSearchOptions) {
|
async images(
|
||||||
|
episodeSelection: EpisodeSelection,
|
||||||
|
options?: TvEpisodeImageSearchOptions
|
||||||
|
) {
|
||||||
const computedOptions = {
|
const computedOptions = {
|
||||||
include_image_language: options?.include_image_language?.join(','),
|
include_image_language: options?.include_image_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
@@ -93,7 +95,10 @@ export class TvEpisodesEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async videos(episodeSelection: EpisodeSelection, options?: TvEpisodeVideoSearchOptions) {
|
async videos(
|
||||||
|
episodeSelection: EpisodeSelection,
|
||||||
|
options?: TvEpisodeVideoSearchOptions
|
||||||
|
) {
|
||||||
const computedOptions = {
|
const computedOptions = {
|
||||||
include_video_language: options?.include_video_language?.join(','),
|
include_video_language: options?.include_video_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ export interface TvSeasonImageSearchOptions extends LanguageOption {
|
|||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_image_language?: string[],
|
include_image_language?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TvSeasonVideoSearchOptions extends LanguageOption {
|
export interface TvSeasonVideoSearchOptions extends LanguageOption {
|
||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_video_language?: string[],
|
include_video_language?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TvSeasonsEndpoint extends BaseEndpoint {
|
export class TvSeasonsEndpoint extends BaseEndpoint {
|
||||||
@@ -91,7 +91,10 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async images(seasonSelection: SeasonSelection, options?: TvSeasonImageSearchOptions) {
|
async images(
|
||||||
|
seasonSelection: SeasonSelection,
|
||||||
|
options?: TvSeasonImageSearchOptions
|
||||||
|
) {
|
||||||
const computedOptions = {
|
const computedOptions = {
|
||||||
include_image_language: options?.include_image_language?.join(','),
|
include_image_language: options?.include_image_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
@@ -102,7 +105,10 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async videos(seasonSelection: SeasonSelection, options?: TvSeasonVideoSearchOptions) {
|
async videos(
|
||||||
|
seasonSelection: SeasonSelection,
|
||||||
|
options?: TvSeasonVideoSearchOptions
|
||||||
|
) {
|
||||||
const computedOptions = {
|
const computedOptions = {
|
||||||
include_video_language: options?.include_video_language?.join(','),
|
include_video_language: options?.include_video_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async aggregateCredits(id: number, options?: LanguageOption): Promise<AggregateCredits> {
|
async aggregateCredits(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption
|
||||||
|
): Promise<AggregateCredits> {
|
||||||
return await this.api.get<AggregateCredits>(
|
return await this.api.get<AggregateCredits>(
|
||||||
`${BASE_TV}/${id}/aggregate_credits`,
|
`${BASE_TV}/${id}/aggregate_credits`,
|
||||||
options
|
options
|
||||||
@@ -110,7 +113,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
|||||||
include_image_language: options?.include_image_language?.join(','),
|
include_image_language: options?.include_image_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
};
|
};
|
||||||
return await this.api.get<Images>(`${BASE_TV}/${id}/images`, computedOptions);
|
return await this.api.get<Images>(
|
||||||
|
`${BASE_TV}/${id}/images`,
|
||||||
|
computedOptions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async keywords(id: number): Promise<Keywords> {
|
async keywords(id: number): Promise<Keywords> {
|
||||||
@@ -127,7 +133,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reviews(id: number, options?: LanguageOption & PageOption): Promise<Reviews> {
|
async reviews(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption & PageOption
|
||||||
|
): Promise<Reviews> {
|
||||||
return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews`, options);
|
return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews`, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +146,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async similar(id: number, options?: LanguageOption & PageOption): Promise<SimilarTvShows> {
|
async similar(
|
||||||
|
id: number,
|
||||||
|
options?: LanguageOption & PageOption
|
||||||
|
): Promise<SimilarTvShows> {
|
||||||
return await this.api.get<SimilarTvShows>(
|
return await this.api.get<SimilarTvShows>(
|
||||||
`${BASE_TV}/${id}/similar`,
|
`${BASE_TV}/${id}/similar`,
|
||||||
options
|
options
|
||||||
@@ -153,7 +165,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
|||||||
include_video_language: options?.include_video_language?.join(','),
|
include_video_language: options?.include_video_language?.join(','),
|
||||||
language: options?.language,
|
language: options?.language,
|
||||||
};
|
};
|
||||||
return await this.api.get<Videos>(`${BASE_TV}/${id}/videos`, computedOptions);
|
return await this.api.get<Videos>(
|
||||||
|
`${BASE_TV}/${id}/videos`,
|
||||||
|
computedOptions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ export interface CollectionImageOptions extends LanguageOption {
|
|||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_image_language?: string[],
|
include_image_language?: string[];
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,12 @@ export * from './collections';
|
|||||||
export * from './tv-episode';
|
export * from './tv-episode';
|
||||||
export * from './tv-seasons';
|
export * from './tv-seasons';
|
||||||
|
|
||||||
|
export interface ErrorResponse {
|
||||||
|
status_code: number;
|
||||||
|
status_message: string;
|
||||||
|
success: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export type MediaType = 'movie' | 'tv' | 'person';
|
export type MediaType = 'movie' | 'tv' | 'person';
|
||||||
|
|
||||||
export interface AuthorDetails {
|
export interface AuthorDetails {
|
||||||
|
|||||||
@@ -279,12 +279,12 @@ export interface TvShowImageOptions extends LanguageOption {
|
|||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_image_language?: string[],
|
include_image_language?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TvShowVideoOptions extends LanguageOption {
|
export interface TvShowVideoOptions extends LanguageOption {
|
||||||
/**
|
/**
|
||||||
* a list of ISO-639-1 values to query
|
* a list of ISO-639-1 values to query
|
||||||
*/
|
*/
|
||||||
include_video_language?: string[],
|
include_video_language?: string[];
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user