refactored change type
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import { ChangeOption, MediaChanges } from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
import { ChangeOptions, MediaChanges } from '../types/changes';
|
||||
|
||||
export class ChangeEndpoint extends BaseEndpoint {
|
||||
constructor(protected readonly accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async movies(options?: ChangeOptions): Promise<MediaChanges> {
|
||||
async movies(options?: ChangeOption): Promise<MediaChanges> {
|
||||
return await this.api.get<MediaChanges>(`/movie/changes`, options);
|
||||
}
|
||||
|
||||
async tvShows(options?: ChangeOptions): Promise<MediaChanges> {
|
||||
async tvShows(options?: ChangeOption): Promise<MediaChanges> {
|
||||
return await this.api.get<MediaChanges>(`/tv/changes`, options);
|
||||
}
|
||||
|
||||
async person(options?: ChangeOptions): Promise<MediaChanges> {
|
||||
async person(options?: ChangeOption): Promise<MediaChanges> {
|
||||
return await this.api.get<MediaChanges>(`/person/change`, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AlternativeTitles,
|
||||
AppendToResponse,
|
||||
AppendToResponseMovieKey,
|
||||
ChangeOptions,
|
||||
ChangeOption,
|
||||
Changes,
|
||||
Credits,
|
||||
ExternalIds,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Keywords,
|
||||
LanguageOption,
|
||||
LatestMovie,
|
||||
MovieChangeValue,
|
||||
MovieDetails,
|
||||
MovieLists,
|
||||
MoviesPlayingNow,
|
||||
@@ -57,8 +58,8 @@ export class MoviesEndpoint extends BaseEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<Changes> {
|
||||
return await this.api.get<Changes>(`${BASE_MOVIE}/${id}/changes`, options);
|
||||
async changes(id: number, options?: ChangeOption): Promise<Changes<MovieChangeValue>> {
|
||||
return await this.api.get<Changes<MovieChangeValue>>(`${BASE_MOVIE}/${id}/changes`, options);
|
||||
}
|
||||
|
||||
async credits(id: number): Promise<Credits> {
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import {
|
||||
AppendToResponse,
|
||||
AppendToResponsePersonKey,
|
||||
ChangeOptions,
|
||||
ChangeOption,
|
||||
ExternalIds,
|
||||
PageOption,
|
||||
PeopleImages,
|
||||
PersonTranslations,
|
||||
PersonChanges,
|
||||
PersonCombinedCredits,
|
||||
PersonDetails,
|
||||
PersonMovieCredit,
|
||||
PersonTvShowCredit,
|
||||
PopularPersons,
|
||||
TaggedImages,
|
||||
Changes,
|
||||
PersonChangeValue,
|
||||
} from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
@@ -38,8 +39,11 @@ export class PeopleEndpoint extends BaseEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<PersonChanges> {
|
||||
return await this.api.get<PersonChanges>(
|
||||
async changes(
|
||||
id: number,
|
||||
options?: ChangeOption
|
||||
): Promise<Changes<PersonChangeValue>> {
|
||||
return await this.api.get<Changes<PersonChangeValue>>(
|
||||
`${BASE_PERSON}/${id}/changes`,
|
||||
options
|
||||
);
|
||||
|
||||
@@ -1,83 +1,82 @@
|
||||
import {
|
||||
Episode,
|
||||
EpisodeSelection,
|
||||
LanguageOption,
|
||||
PageOption,
|
||||
ChangeOption,
|
||||
TvEpisodeChanges,
|
||||
TvEpisodeCredit,
|
||||
ExternalIds,
|
||||
Images,
|
||||
TvEpisodeTranslations,
|
||||
Videos,
|
||||
AppendToResponseMovieKey,
|
||||
AppendToResponse,
|
||||
} from '..';
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
const BASE_EPISODE = (episodeSelection: EpisodeSelection): string => {
|
||||
return `/tv/${episodeSelection.tvShowID}/season/${episodeSelection.seasonNumber}/episode/${episodeSelection.episodeNumber}`;
|
||||
};
|
||||
|
||||
export class TvEpisodesEndpoint extends BaseEndpoint {
|
||||
constructor(accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async details<T extends AppendToResponseMovieKey[] | undefined>(
|
||||
episodeSelection: EpisodeSelection,
|
||||
appendToResponse?: T,
|
||||
options?: LanguageOption
|
||||
) {
|
||||
const combinedOptions = {
|
||||
append_to_response: appendToResponse
|
||||
? appendToResponse.join(',')
|
||||
: undefined,
|
||||
...options,
|
||||
};
|
||||
|
||||
return await this.api.get<
|
||||
AppendToResponse<Omit<Episode, 'show_id'>, T, 'movie'>
|
||||
>(`${BASE_EPISODE(episodeSelection)}`, combinedOptions);
|
||||
}
|
||||
|
||||
async changes(episodeID: number, options?: PageOption & ChangeOption) {
|
||||
return await this.api.get<TvEpisodeChanges>(
|
||||
`/tv/episode/${episodeID}/changes`,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
async credits(episodeSelection: EpisodeSelection, options?: LanguageOption) {
|
||||
return await this.api.get<TvEpisodeCredit>(
|
||||
`${BASE_EPISODE(episodeSelection)}/credits`,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
async externalIds(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<ExternalIds>(
|
||||
`${BASE_EPISODE(episodeSelection)}/external_ids`
|
||||
);
|
||||
}
|
||||
|
||||
async images(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<Images>(
|
||||
`${BASE_EPISODE(episodeSelection)}/images`
|
||||
);
|
||||
}
|
||||
|
||||
async translations(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<TvEpisodeTranslations>(
|
||||
`${BASE_EPISODE(episodeSelection)}/translations`
|
||||
);
|
||||
}
|
||||
|
||||
async videos(episodeSelection: EpisodeSelection, options?: LanguageOption) {
|
||||
return await this.api.get<Videos>(
|
||||
`${BASE_EPISODE(episodeSelection)}/videos`,
|
||||
options
|
||||
);
|
||||
}
|
||||
Episode,
|
||||
EpisodeSelection,
|
||||
LanguageOption,
|
||||
ChangeOption,
|
||||
TvEpisodeCredit,
|
||||
ExternalIds,
|
||||
Images,
|
||||
TvEpisodeTranslations,
|
||||
Videos,
|
||||
AppendToResponseMovieKey,
|
||||
AppendToResponse,
|
||||
Changes,
|
||||
TvEpisodeChangeValue,
|
||||
} from '..';
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
const BASE_EPISODE = (episodeSelection: EpisodeSelection): string => {
|
||||
return `/tv/${episodeSelection.tvShowID}/season/${episodeSelection.seasonNumber}/episode/${episodeSelection.episodeNumber}`;
|
||||
};
|
||||
|
||||
export class TvEpisodesEndpoint extends BaseEndpoint {
|
||||
constructor(accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
|
||||
async details<T extends AppendToResponseMovieKey[] | undefined>(
|
||||
episodeSelection: EpisodeSelection,
|
||||
appendToResponse?: T,
|
||||
options?: LanguageOption
|
||||
) {
|
||||
const combinedOptions = {
|
||||
append_to_response: appendToResponse
|
||||
? appendToResponse.join(',')
|
||||
: undefined,
|
||||
...options,
|
||||
};
|
||||
|
||||
return await this.api.get<
|
||||
AppendToResponse<Omit<Episode, 'show_id'>, T, 'movie'>
|
||||
>(`${BASE_EPISODE(episodeSelection)}`, combinedOptions);
|
||||
}
|
||||
|
||||
async changes(episodeID: number, options?: ChangeOption) {
|
||||
return await this.api.get<Changes<TvEpisodeChangeValue>>(
|
||||
`/tv/episode/${episodeID}/changes`,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
async credits(episodeSelection: EpisodeSelection, options?: LanguageOption) {
|
||||
return await this.api.get<TvEpisodeCredit>(
|
||||
`${BASE_EPISODE(episodeSelection)}/credits`,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
async externalIds(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<ExternalIds>(
|
||||
`${BASE_EPISODE(episodeSelection)}/external_ids`
|
||||
);
|
||||
}
|
||||
|
||||
async images(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<Images>(
|
||||
`${BASE_EPISODE(episodeSelection)}/images`
|
||||
);
|
||||
}
|
||||
|
||||
async translations(episodeSelection: EpisodeSelection) {
|
||||
return await this.api.get<TvEpisodeTranslations>(
|
||||
`${BASE_EPISODE(episodeSelection)}/translations`
|
||||
);
|
||||
}
|
||||
|
||||
async videos(episodeSelection: EpisodeSelection, options?: LanguageOption) {
|
||||
return await this.api.get<Videos>(
|
||||
`${BASE_EPISODE(episodeSelection)}/videos`,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AlternativeTitles,
|
||||
AppendToResponse,
|
||||
AppendToResponseTvKey,
|
||||
ChangeOptions,
|
||||
ChangeOption,
|
||||
Changes,
|
||||
ContentRatings,
|
||||
Credits,
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
SimilarTvShows,
|
||||
TopRatedTvShows,
|
||||
Translations,
|
||||
TvShowChangeValue,
|
||||
TvShowDetails,
|
||||
TvShowsAiringToday,
|
||||
Videos,
|
||||
@@ -58,8 +59,8 @@ export class TvShowsEndpoint extends BaseEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<Changes> {
|
||||
return await this.api.get<Changes>(`${BASE_TV}/${id}/changes`, options);
|
||||
async changes(id: number, options?: ChangeOption): Promise<Changes<TvShowChangeValue>> {
|
||||
return await this.api.get<Changes<TvShowChangeValue>>(`${BASE_TV}/${id}/changes`, options);
|
||||
}
|
||||
|
||||
async contentRatings(id: number): Promise<ContentRatings> {
|
||||
|
||||
@@ -10,26 +10,20 @@ export interface MediaChanges {
|
||||
total_results: number;
|
||||
}
|
||||
|
||||
export interface ChangeOptions {
|
||||
end_date?: string;
|
||||
start_date?: string;
|
||||
page?: number;
|
||||
export interface Changes<T> {
|
||||
changes: Change<T>[];
|
||||
}
|
||||
|
||||
export interface Changes {
|
||||
changes: Change[];
|
||||
}
|
||||
|
||||
export interface Change {
|
||||
export interface Change<T> {
|
||||
key: string;
|
||||
items: ChangeItem[];
|
||||
items: ChangeItem<T>[];
|
||||
}
|
||||
|
||||
export interface ChangeItem {
|
||||
export interface ChangeItem<T> {
|
||||
id: string;
|
||||
action: string;
|
||||
time: string;
|
||||
value: Array<number>;
|
||||
value: T;
|
||||
iso_639_1: string;
|
||||
original_value: Array<number>;
|
||||
original_value: T;
|
||||
}
|
||||
|
||||
@@ -155,3 +155,14 @@ export interface UpcomingMovies {
|
||||
total_results: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export type MovieChangeValue =
|
||||
| string
|
||||
| {
|
||||
person_id: number;
|
||||
character: string;
|
||||
order: number;
|
||||
cast_id: number;
|
||||
credit_id: string;
|
||||
}
|
||||
| unknown;
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
MovieLists,
|
||||
PeopleImages,
|
||||
PersonTranslations,
|
||||
PersonChanges,
|
||||
PersonCombinedCredits,
|
||||
PersonMovieCredit,
|
||||
PersonTvShowCredit,
|
||||
@@ -24,6 +23,10 @@ import {
|
||||
Translations,
|
||||
Videos,
|
||||
WatchProviders,
|
||||
PersonChangeValue,
|
||||
MovieChangeValue,
|
||||
TvShowChangeValue,
|
||||
TvEpisodeChangeValue,
|
||||
} from '.';
|
||||
|
||||
export interface LanguageOption {
|
||||
@@ -125,9 +128,14 @@ export type AppendToResponse<
|
||||
: object) &
|
||||
('changes' extends T[number]
|
||||
? {
|
||||
changes: Omit<
|
||||
Media extends 'person' ? PersonChanges : Changes,
|
||||
'id'
|
||||
changes: Changes<
|
||||
Media extends 'person'
|
||||
? PersonChangeValue
|
||||
: Media extends 'movie'
|
||||
? MovieChangeValue
|
||||
: Media extends 'tvShow'
|
||||
? TvShowChangeValue
|
||||
: TvEpisodeChangeValue
|
||||
>;
|
||||
}
|
||||
: object) &
|
||||
@@ -147,7 +155,12 @@ export type AppendToResponse<
|
||||
? { external_ids: Omit<ExternalIds, 'id'> }
|
||||
: object) &
|
||||
('translations' extends T[number]
|
||||
? { translations: Omit<Media extends 'person' ? PersonTranslations : Translations, 'id'> }
|
||||
? {
|
||||
translations: Omit<
|
||||
Media extends 'person' ? PersonTranslations : Translations,
|
||||
'id'
|
||||
>;
|
||||
}
|
||||
: object) &
|
||||
('watch/providers' extends T[number]
|
||||
? { 'watch/providers': Omit<WatchProviders, 'id'> }
|
||||
|
||||
@@ -96,22 +96,13 @@ export interface PersonDetails {
|
||||
homepage: string;
|
||||
}
|
||||
|
||||
export interface PersonChange {
|
||||
id: string;
|
||||
action: string;
|
||||
time: string;
|
||||
iso_639_1: string;
|
||||
iso_3166_1: string;
|
||||
value: string | { profile: { file_path: string } };
|
||||
original_value: string | { profile: { file_path: string } };
|
||||
}
|
||||
|
||||
export interface PersonChanges {
|
||||
changes: {
|
||||
key: string;
|
||||
items: PersonChange[];
|
||||
}[];
|
||||
}
|
||||
export type PersonChangeValue =
|
||||
| string
|
||||
| {
|
||||
profile: {
|
||||
file_path: string;
|
||||
};
|
||||
};
|
||||
|
||||
export interface PopularPersons {
|
||||
page: number;
|
||||
|
||||
@@ -37,24 +37,6 @@ export interface GuestStar {
|
||||
profile_path: string | null;
|
||||
}
|
||||
|
||||
export interface TvEpisodeChangeItem {
|
||||
id: string;
|
||||
action: string;
|
||||
time: string;
|
||||
iso_639_1: string;
|
||||
iso_3166_1: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface TvEpisodeChange {
|
||||
key: string;
|
||||
items: TvEpisodeChangeItem[];
|
||||
}
|
||||
|
||||
export interface TvEpisodeChanges {
|
||||
changes: TvEpisodeChange[];
|
||||
}
|
||||
|
||||
export interface TvEpisodeCredit extends Credits {
|
||||
guest_stars: GuestStar[];
|
||||
}
|
||||
@@ -72,3 +54,5 @@ export interface TvEpisodeTranslations {
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export type TvEpisodeChangeValue = string | unknown;
|
||||
@@ -279,3 +279,8 @@ export interface TopRatedTvShows {
|
||||
total_results: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export interface TvShowChangeValue {
|
||||
season_id: number;
|
||||
season_number: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user