lufinkey / node-justwatch-api

Unofficial JustWatch API for nodejs
71 stars 14 forks source link

Add typings to the package #13

Closed nick-lehmann closed 3 years ago

nick-lehmann commented 3 years ago

It would be very beneficial for all who want to use this package in a typescript package to include types for all functions. Since your package works like a charm for me (thank you 🙏🏻), I have created a declaration file for your package and included it in my tsconfig.json.

Would you be willing to accept a pull request to add the types to this package?

The current state (not completely done) can be seen below. If you would agree to a PR for adding these, I would spend a little bit of time on completing the types.

justwatch.d.ts ```typescript declare module "justwatch-api" { export default class JustWatch { constructor(options: any); _options: any; // request(method: any, endpoint: any, params: any): Promise; search(options?: {}): Promise; getProviders(): Promise; getGenres(): Promise; getSeason(season_id: any): Promise; getEpisodes(show_id: any): Promise; getTitle(content_type: ContentType, title_id: TitleID): Promise; getPerson(person_id: any): Promise<any>; } export enum ContentType { Movie = "movie", Show = "show", } export type TitleID = number; export interface Title { id: TitleID; jw_entity_id: string; title: string; full_path: string; full_paths: Fullpaths; poster: string; poster_blur_hash: string; backdrops: Backdrop[]; short_description: string; original_release_year: number; object_type: string; original_title: string; localized_release_date: string; offers: Offer[]; clips: Clip[]; scoring: Scoring[]; credits: Credit[]; external_ids: Externalid[]; genre_ids: number[]; age_certification: string; runtime: number; production_countries: string[]; cinema_release_date: string; permanent_audiences: string[]; } interface Externalid { provider: string; external_id: string; } interface Credit { role: string; character_name?: string; person_id: number; name: string; } interface Scoring { provider_type: string; value: number; } interface Clip { type: string; provider: string; external_id: string; name: string; } interface Offer { jw_entity_id: string; monetization_type: MonetizationType; provider_id: number; retail_price?: number; last_change_retail_price?: number; last_change_difference?: number; last_change_percent?: number; last_change_date?: string; last_change_date_provider_id?: string; currency: string; urls: Urls; presentation_type: string; country: string; } export enum MonetizationType { Buy = "buy", Rent = "rent", Flatrate = "flatrate", } export enum PresentationType { SD = "sd", HD = "hd", UHD = "4k", } interface Urls { standard_web: string; deeplink_web?: string; } interface Backdrop { backdrop_url: string; backdrop_blur_hash: string; } interface Fullpaths { MOVIE_DETAIL_OVERVIEW: string; } export interface SearchResults { page: number; page_size: number; total_pages: number; total_results: number; items: Title[]; } export type ProviderID = number; export interface Provider { id: ProviderID; technical_name: string; short_name: string; clear_name: string; display_priority: number; priority: number; monetization_types: MonetizationType[]; icon_url: string; icon_blur_hash: string; slug: string; data: ProviderData; addon_packages?: any; parent_packages?: any; } interface ProviderData { deeplink_data: any[]; packages: Packages; } interface Packages { android_tv: string; fire_tv: string; tvos: string; tizenos: string; webos: string; xbox: string; } } ``` </details> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/lufinkey"><img src="https://avatars.githubusercontent.com/u/7820113?v=4" />lufinkey</a> commented <strong> 3 years ago</strong> </div> <div class="markdown-body"> <p>Yeah go for it</p> <p>Also I think the <code>search</code> argument should probably be <code>any</code> if you're gonna make it an empty object</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/nick-lehmann"><img src="https://avatars.githubusercontent.com/u/2708875?v=4" />nick-lehmann</a> commented <strong> 3 years ago</strong> </div> <div class="markdown-body"> <p>Ok, I will give it a shot this week. Just another quick question: Would you like to stick with Javascript and I only add the types, or would it be acceptable to also rewrite the few lines of code to Typescript altogether?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/lufinkey"><img src="https://avatars.githubusercontent.com/u/7820113?v=4" />lufinkey</a> commented <strong> 3 years ago</strong> </div> <div class="markdown-body"> <p>Sorry forgot to respond to this. I think just adding the typing files would be fine</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/nick-lehmann"><img src="https://avatars.githubusercontent.com/u/2708875?v=4" />nick-lehmann</a> commented <strong> 3 years ago</strong> </div> <div class="markdown-body"> <p>Sorry for the late response, but the pull request is now there. Did a very quick test in a sample project and it works as expected 👍🏻</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>