Merge pull request #33 from xanderbarkhatov/feature/multi-search
Add multi-search, adjust types to allow type narrowing
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": "0.2.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "tmdb-ts",
|
"name": "tmdb-ts",
|
||||||
"version": "0.2.0",
|
"version": "1.0.0",
|
||||||
"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.1.0",
|
"version": "1.2.0",
|
||||||
"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,5 @@
|
|||||||
import { BaseEndpoint } from './base';
|
import { BaseEndpoint } from './base';
|
||||||
import { Search } from '../types/search';
|
import { MultiSearchResult, Search } from '../types/search';
|
||||||
import { Collection, Company, Movie, Person, TV } from '../types';
|
import { Collection, Company, Movie, Person, TV } from '../types';
|
||||||
|
|
||||||
const BASE_SEARCH = '/search';
|
const BASE_SEARCH = '/search';
|
||||||
@@ -24,6 +24,10 @@ export interface PeopleSearchOptions extends SearchOptions {
|
|||||||
include_adult?: boolean;
|
include_adult?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MultiSearchOptions extends SearchOptions {
|
||||||
|
include_adult?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class SearchEndpoint extends BaseEndpoint {
|
export class SearchEndpoint extends BaseEndpoint {
|
||||||
constructor(protected readonly accessToken: string) {
|
constructor(protected readonly accessToken: string) {
|
||||||
super(accessToken);
|
super(accessToken);
|
||||||
@@ -60,9 +64,14 @@ export class SearchEndpoint extends BaseEndpoint {
|
|||||||
return await this.api.get<Search<Person>>(`${BASE_SEARCH}/person`, options);
|
return await this.api.get<Search<Person>>(`${BASE_SEARCH}/person`, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Multi search
|
|
||||||
|
|
||||||
async tvShows(options: TvSearchOptions): Promise<Search<TV>> {
|
async tvShows(options: TvSearchOptions): Promise<Search<TV>> {
|
||||||
return await this.api.get<Search<TV>>(`${BASE_SEARCH}/tv`, options);
|
return await this.api.get<Search<TV>>(`${BASE_SEARCH}/tv`, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async multi(options: MultiSearchOptions): Promise<Search<MultiSearchResult>> {
|
||||||
|
return await this.api.get<Search<MultiSearchResult>>(
|
||||||
|
`${BASE_SEARCH}/multi`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MediaType, TimeWindow, TrendingResults } from '../types';
|
import { TrendingMediaType, TimeWindow, TrendingResults } from '../types';
|
||||||
import { BaseEndpoint } from './base';
|
import { BaseEndpoint } from './base';
|
||||||
|
|
||||||
export class TrendingEndpoint extends BaseEndpoint {
|
export class TrendingEndpoint extends BaseEndpoint {
|
||||||
@@ -6,7 +6,7 @@ export class TrendingEndpoint extends BaseEndpoint {
|
|||||||
super(accessToken);
|
super(accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
async trending<T extends MediaType>(
|
async trending<T extends TrendingMediaType>(
|
||||||
mediaType: T,
|
mediaType: T,
|
||||||
timeWindow: TimeWindow
|
timeWindow: TimeWindow
|
||||||
): Promise<TrendingResults<T>> {
|
): Promise<TrendingResults<T>> {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ export * from './find';
|
|||||||
export * from './keywords';
|
export * from './keywords';
|
||||||
export * from './collections';
|
export * from './collections';
|
||||||
|
|
||||||
|
export type MediaType = 'movie' | 'tv' | 'person';
|
||||||
|
|
||||||
export interface AuthorDetails {
|
export interface AuthorDetails {
|
||||||
name: string;
|
name: string;
|
||||||
username: string;
|
username: string;
|
||||||
@@ -22,23 +24,7 @@ export interface AuthorDetails {
|
|||||||
rating?: number;
|
rating?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KnownFor {
|
export type KnownFor = MovieWithMediaType | TVWithMediaType;
|
||||||
id: number;
|
|
||||||
overview: string;
|
|
||||||
release_date: string;
|
|
||||||
video: boolean;
|
|
||||||
adult: boolean;
|
|
||||||
backdrop_path: string;
|
|
||||||
media_type: string;
|
|
||||||
genre_ids: number[];
|
|
||||||
title: string;
|
|
||||||
original_language: string;
|
|
||||||
original_title: string;
|
|
||||||
poster_path: string;
|
|
||||||
vote_count: number;
|
|
||||||
vote_average: number;
|
|
||||||
popularity: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Person {
|
export interface Person {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -51,6 +37,10 @@ export interface Person {
|
|||||||
popularity: number;
|
popularity: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PersonWithMediaType extends Person {
|
||||||
|
media_type: 'person';
|
||||||
|
}
|
||||||
|
|
||||||
export interface Movie {
|
export interface Movie {
|
||||||
id: number;
|
id: number;
|
||||||
poster_path: string;
|
poster_path: string;
|
||||||
@@ -68,6 +58,10 @@ export interface Movie {
|
|||||||
vote_average: number;
|
vote_average: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MovieWithMediaType extends Movie {
|
||||||
|
media_type: 'movie';
|
||||||
|
}
|
||||||
|
|
||||||
export interface Company {
|
export interface Company {
|
||||||
id: number;
|
id: number;
|
||||||
logo_path: string;
|
logo_path: string;
|
||||||
@@ -91,6 +85,10 @@ export interface TV {
|
|||||||
vote_average: number;
|
vote_average: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TVWithMediaType extends TV {
|
||||||
|
media_type: 'tv';
|
||||||
|
}
|
||||||
|
|
||||||
export interface Genre {
|
export interface Genre {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
import { MovieWithMediaType, PersonWithMediaType, TVWithMediaType } from '.';
|
||||||
|
|
||||||
export interface Search<T> {
|
export interface Search<T> {
|
||||||
page: number;
|
page: number;
|
||||||
results: T[];
|
results: T[];
|
||||||
total_pages: number;
|
total_pages: number;
|
||||||
total_results: number;
|
total_results: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type MultiSearchResult =
|
||||||
|
| MovieWithMediaType
|
||||||
|
| TVWithMediaType
|
||||||
|
| PersonWithMediaType;
|
||||||
|
|||||||
@@ -1,19 +1,28 @@
|
|||||||
import { Movie, Person, TV } from '.';
|
import {
|
||||||
export type MediaType = 'all' | 'movie' | 'tv' | 'person';
|
Movie,
|
||||||
|
Person,
|
||||||
|
TV,
|
||||||
|
MediaType,
|
||||||
|
MovieWithMediaType,
|
||||||
|
TVWithMediaType,
|
||||||
|
PersonWithMediaType,
|
||||||
|
} from '.';
|
||||||
|
|
||||||
export type TimeWindow = 'day' | 'week';
|
export type TimeWindow = 'day' | 'week';
|
||||||
|
|
||||||
type TrendingResult<T extends MediaType> = T extends 'tv'
|
export type TrendingMediaType = MediaType | 'all';
|
||||||
|
|
||||||
|
type TrendingResult<T extends TrendingMediaType> = T extends 'tv'
|
||||||
? TV
|
? TV
|
||||||
: T extends 'movie'
|
: T extends 'movie'
|
||||||
? Movie
|
? Movie
|
||||||
: T extends 'person'
|
: T extends 'person'
|
||||||
? Person
|
? Person
|
||||||
: TV | Movie | Person;
|
: TVWithMediaType | MovieWithMediaType | PersonWithMediaType;
|
||||||
|
|
||||||
export interface TrendingResults<T extends MediaType> {
|
export interface TrendingResults<T extends TrendingMediaType> {
|
||||||
page: number;
|
page: number;
|
||||||
results: (TrendingResult<T> & { media_type: MediaType })[];
|
results: TrendingResult<T>[];
|
||||||
total_pages: number;
|
total_pages: number;
|
||||||
total_results: number;
|
total_results: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user