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