From 3e3e97ee76d2c7c6de7e8fcda4995cfdff4cfbe1 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 6 Mar 2023 14:25:37 +0100 Subject: [PATCH] refactor: add typings --- src/common/index.js | 2 +- src/common/useProfile.d.ts | 2 + src/common/useStreamingServer.d.ts | 2 + src/modules.d.ts | 2 + src/routes/Addons/useInstalledAddons.d.ts | 2 + src/routes/Addons/useRemoteAddons.d.ts | 2 + src/routes/Board/useBoard.d.ts | 2 + src/routes/Discover/useDiscover.d.ts | 2 + src/routes/Library/useLibrary.d.ts | 2 + src/routes/MetaDetails/useMetaDetails.d.ts | 2 + src/routes/Player/usePlayer.d.ts | 2 + src/routes/Player/useSettings.d.ts | 2 + src/routes/Search/useSearch.d.ts | 2 + src/services/Core/Core.d.ts | 2 + src/services/Core/CoreTransport.d.ts | 2 + src/services/Core/globals.d.ts | 12 ++ src/services/Core/types.d.ts | 28 +++ src/services/ServicesContext/types.d.ts | 7 + src/services/ServicesContext/useServices.d.ts | 2 + src/types/Board.d.ts | 1 + src/types/CatalogsWithExtra.d.ts | 7 + src/types/Ctx.d.ts | 47 ++++ src/types/Discover.d.ts | 16 ++ src/types/InstalledAddons.d.ts | 12 ++ src/types/Library.d.ts | 24 +++ src/types/MetaDetails.d.ts | 20 ++ src/types/Player.d.ts | 18 ++ src/types/RemoteAddons.d.ts | 10 + src/types/Search.d.ts | 1 + src/types/StremingServer.d.ts | 21 ++ src/types/common.d.ts | 200 ++++++++++++++++++ tsconfig.json | 20 ++ 32 files changed, 475 insertions(+), 1 deletion(-) create mode 100644 src/common/useProfile.d.ts create mode 100644 src/common/useStreamingServer.d.ts create mode 100644 src/modules.d.ts create mode 100644 src/routes/Addons/useInstalledAddons.d.ts create mode 100644 src/routes/Addons/useRemoteAddons.d.ts create mode 100644 src/routes/Board/useBoard.d.ts create mode 100644 src/routes/Discover/useDiscover.d.ts create mode 100644 src/routes/Library/useLibrary.d.ts create mode 100644 src/routes/MetaDetails/useMetaDetails.d.ts create mode 100644 src/routes/Player/usePlayer.d.ts create mode 100644 src/routes/Player/useSettings.d.ts create mode 100644 src/routes/Search/useSearch.d.ts create mode 100644 src/services/Core/Core.d.ts create mode 100644 src/services/Core/CoreTransport.d.ts create mode 100644 src/services/Core/globals.d.ts create mode 100644 src/services/Core/types.d.ts create mode 100644 src/services/ServicesContext/types.d.ts create mode 100644 src/services/ServicesContext/useServices.d.ts create mode 100644 src/types/Board.d.ts create mode 100644 src/types/CatalogsWithExtra.d.ts create mode 100644 src/types/Ctx.d.ts create mode 100644 src/types/Discover.d.ts create mode 100644 src/types/InstalledAddons.d.ts create mode 100644 src/types/Library.d.ts create mode 100644 src/types/MetaDetails.d.ts create mode 100644 src/types/Player.d.ts create mode 100644 src/types/RemoteAddons.d.ts create mode 100644 src/types/Search.d.ts create mode 100644 src/types/StremingServer.d.ts create mode 100644 src/types/common.d.ts create mode 100644 tsconfig.json diff --git a/src/common/index.js b/src/common/index.js index 22dcad52a..bfc169279 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -27,7 +27,7 @@ const comparatorWithPriorities = require('./comparatorWithPriorities'); const CONSTANTS = require('./CONSTANTS'); const { withCoreSuspender, useCoreSuspender } = require('./CoreSuspender'); const getVisibleChildrenRange = require('./getVisibleChildrenRange'); -const languageNames = require('./languageNames'); +const languageNames = require('./languageNames.json'); const routesRegexp = require('./routesRegexp'); const useAnimationFrame = require('./useAnimationFrame'); const useBinaryState = require('./useBinaryState'); diff --git a/src/common/useProfile.d.ts b/src/common/useProfile.d.ts new file mode 100644 index 000000000..be5aed774 --- /dev/null +++ b/src/common/useProfile.d.ts @@ -0,0 +1,2 @@ +declare const useProfile: () => Profile; +export = useProfile; \ No newline at end of file diff --git a/src/common/useStreamingServer.d.ts b/src/common/useStreamingServer.d.ts new file mode 100644 index 000000000..76d3167de --- /dev/null +++ b/src/common/useStreamingServer.d.ts @@ -0,0 +1,2 @@ +declare const useStreamingServer: () => StreamingServer; +export = useStreamingServer; \ No newline at end of file diff --git a/src/modules.d.ts b/src/modules.d.ts new file mode 100644 index 000000000..fc79871c7 --- /dev/null +++ b/src/modules.d.ts @@ -0,0 +1,2 @@ +declare module '*'; +declare module 'classnames'; \ No newline at end of file diff --git a/src/routes/Addons/useInstalledAddons.d.ts b/src/routes/Addons/useInstalledAddons.d.ts new file mode 100644 index 000000000..72120dad4 --- /dev/null +++ b/src/routes/Addons/useInstalledAddons.d.ts @@ -0,0 +1,2 @@ +declare const useInstalledAddons: (urlParams: UrlParams) => InstalledAddons; +export = useInstalledAddons; \ No newline at end of file diff --git a/src/routes/Addons/useRemoteAddons.d.ts b/src/routes/Addons/useRemoteAddons.d.ts new file mode 100644 index 000000000..520f53d60 --- /dev/null +++ b/src/routes/Addons/useRemoteAddons.d.ts @@ -0,0 +1,2 @@ +declare const useRemoteAddons: (urlParams: UrlParams) => RemoteAddons; +export = useRemoteAddons; \ No newline at end of file diff --git a/src/routes/Board/useBoard.d.ts b/src/routes/Board/useBoard.d.ts new file mode 100644 index 000000000..c0fe06d3c --- /dev/null +++ b/src/routes/Board/useBoard.d.ts @@ -0,0 +1,2 @@ +declare const useBoard: () => [Board, ({ start, end }: { start: number, end: number }) => void]; +export = useBoard; \ No newline at end of file diff --git a/src/routes/Discover/useDiscover.d.ts b/src/routes/Discover/useDiscover.d.ts new file mode 100644 index 000000000..3fbd7a512 --- /dev/null +++ b/src/routes/Discover/useDiscover.d.ts @@ -0,0 +1,2 @@ +declare const useDiscover: (urlParams: UrlParams, searchParams: URLSearchParams) => [Discover, () => void]; +export = useDiscover; \ No newline at end of file diff --git a/src/routes/Library/useLibrary.d.ts b/src/routes/Library/useLibrary.d.ts new file mode 100644 index 000000000..f197b0820 --- /dev/null +++ b/src/routes/Library/useLibrary.d.ts @@ -0,0 +1,2 @@ +declare const useLibrary: (model: string, urlParams: UrlParams, searchParams: URLSearchParams) => Library; +export = useLibrary; \ No newline at end of file diff --git a/src/routes/MetaDetails/useMetaDetails.d.ts b/src/routes/MetaDetails/useMetaDetails.d.ts new file mode 100644 index 000000000..5146bed99 --- /dev/null +++ b/src/routes/MetaDetails/useMetaDetails.d.ts @@ -0,0 +1,2 @@ +declare const useMetaDetails: (urlParams: UrlParams) => MetaDetails; +export = useMetaDetails; \ No newline at end of file diff --git a/src/routes/Player/usePlayer.d.ts b/src/routes/Player/usePlayer.d.ts new file mode 100644 index 000000000..8580583f3 --- /dev/null +++ b/src/routes/Player/usePlayer.d.ts @@ -0,0 +1,2 @@ +declare const usePlayer: (urlParams: UrlParams, videoParams: any) => [Player, (time: number, duration: number, device: string) => void, (paused: boolean) => void, () => void, () => void]; +export = usePlayer; \ No newline at end of file diff --git a/src/routes/Player/useSettings.d.ts b/src/routes/Player/useSettings.d.ts new file mode 100644 index 000000000..688445b1f --- /dev/null +++ b/src/routes/Player/useSettings.d.ts @@ -0,0 +1,2 @@ +declare const useSettings: () => [Settings, (settings: any) => void]; +export = useSettings; \ No newline at end of file diff --git a/src/routes/Search/useSearch.d.ts b/src/routes/Search/useSearch.d.ts new file mode 100644 index 000000000..156cacbbf --- /dev/null +++ b/src/routes/Search/useSearch.d.ts @@ -0,0 +1,2 @@ +declare const useSearch: (searchParams: URLSearchParams) => [Search, (range: number) => void]; +export = useSearch; \ No newline at end of file diff --git a/src/services/Core/Core.d.ts b/src/services/Core/Core.d.ts new file mode 100644 index 000000000..e9cfdef5b --- /dev/null +++ b/src/services/Core/Core.d.ts @@ -0,0 +1,2 @@ +declare function Core(): Core; +export = Core; \ No newline at end of file diff --git a/src/services/Core/CoreTransport.d.ts b/src/services/Core/CoreTransport.d.ts new file mode 100644 index 000000000..ef9b606ca --- /dev/null +++ b/src/services/Core/CoreTransport.d.ts @@ -0,0 +1,2 @@ +declare function CoreTransport(): CoreTransport; +export = CoreTransport; \ No newline at end of file diff --git a/src/services/Core/globals.d.ts b/src/services/Core/globals.d.ts new file mode 100644 index 000000000..ca2680a0e --- /dev/null +++ b/src/services/Core/globals.d.ts @@ -0,0 +1,12 @@ +type CoreEvent = { + name: string, + args: any[], +}; + +declare global { + interface Window { + onCoreEvent: (event: CoreEvent) => void; + } +} + +export {}; \ No newline at end of file diff --git a/src/services/Core/types.d.ts b/src/services/Core/types.d.ts new file mode 100644 index 000000000..73875adf9 --- /dev/null +++ b/src/services/Core/types.d.ts @@ -0,0 +1,28 @@ +type Action = { + action: string, + args?: { + model?: string, + action?: string, + args?: any, + } +}; + +type AnalyticsEvent = { + event: string, + args: object, +}; + +interface CoreTransport { + start: (args: object) => Promise, + getState: (model: string) => Promise, + dispatch: (action: Action, model?: string) => Promise, + decodeStream: (stream: string) => Promise, + analytics: (event: AnalyticsEvent) => Promise, + on: (name: string, listener: () => void) => void, + off: (name: string, listener: () => void) => void, +} + +interface Core { + active: boolean, + transport: CoreTransport, +} \ No newline at end of file diff --git a/src/services/ServicesContext/types.d.ts b/src/services/ServicesContext/types.d.ts new file mode 100644 index 000000000..48a599ea2 --- /dev/null +++ b/src/services/ServicesContext/types.d.ts @@ -0,0 +1,7 @@ +type ServicesContext = { + core: Core, + shell: any, + chromecast: any, + keyboardShortcuts: any, + dragAndDrop: any, +}; \ No newline at end of file diff --git a/src/services/ServicesContext/useServices.d.ts b/src/services/ServicesContext/useServices.d.ts new file mode 100644 index 000000000..bd4199743 --- /dev/null +++ b/src/services/ServicesContext/useServices.d.ts @@ -0,0 +1,2 @@ +declare const useService: () => ServicesContext; +export = useService; \ No newline at end of file diff --git a/src/types/Board.d.ts b/src/types/Board.d.ts new file mode 100644 index 000000000..f03046102 --- /dev/null +++ b/src/types/Board.d.ts @@ -0,0 +1 @@ +type Board = CatalogsWithExtra; \ No newline at end of file diff --git a/src/types/CatalogsWithExtra.d.ts b/src/types/CatalogsWithExtra.d.ts new file mode 100644 index 000000000..caa207721 --- /dev/null +++ b/src/types/CatalogsWithExtra.d.ts @@ -0,0 +1,7 @@ +type CatalogsWithExtra = { + catalogs: Catalog, DiscoverDeepLinks>[] | null, + selected: { + type: string | null, + extra: [string, string][] + } | null, +}; \ No newline at end of file diff --git a/src/types/Ctx.d.ts b/src/types/Ctx.d.ts new file mode 100644 index 000000000..83fe66c84 --- /dev/null +++ b/src/types/Ctx.d.ts @@ -0,0 +1,47 @@ +type Auth = { + key: string, + user: { + _id: string, + avatar: string, + email: string, + trakt: { + access_token: string, + created_at: number, + expires_in: number, + }, + }, +}; + +type Settings = { + audioLanguage: string, + audioPassthrough: boolean, + autoFrameRateMatching: boolean, + bingeWatching: boolean, + hardwareDecoding: boolean, + interfaceLanguage: string, + nextVideoNotificationDuration: number, + playInBackground: boolean, + playerType: string | null, + secondaryAudioLanguage: string | null, + secondarySubtitlesLanguage: string | null, + seekTimeDuration: number, + streamingServerUrl: string, + streamingServerWarningDismissed: Date | null, + subtitlesBackgroundColor: string, + subtitlesBold: boolean, + subtitlesFont: string, + subtitlesLanguage: string, + subtitlesOffset: number, + subtitlesOutlineColor: string, + subtitlesSize: number, + subtitlesTextColor: string, +}; + +type Profile = { + auth: Auth | null, + settings: Settings, +}; + +type Ctx = { + profile: Profile, +}; \ No newline at end of file diff --git a/src/types/Discover.d.ts b/src/types/Discover.d.ts new file mode 100644 index 000000000..e9b9a5dc0 --- /dev/null +++ b/src/types/Discover.d.ts @@ -0,0 +1,16 @@ +type DiscoverDeepLinks = { + discover: string, +}; + +type Discover = { + catalog: Catalog> | null, + selectable: { + catalogs: DiscoverCatalogOption, + extra: ExtraOption[], + types: TypeOption[], + nextPage: boolean, + }, + selected: { + request: ResourceRequest, + } | null, +}; \ No newline at end of file diff --git a/src/types/InstalledAddons.d.ts b/src/types/InstalledAddons.d.ts new file mode 100644 index 000000000..01cf9075c --- /dev/null +++ b/src/types/InstalledAddons.d.ts @@ -0,0 +1,12 @@ +type InstalledAddons = { + catalog: Addon[], + selectable: { + catalogs: CatalogOption[], + types: TypeOption[], + }, + selected: { + request: { + type: string, + } + } | null, +}; \ No newline at end of file diff --git a/src/types/Library.d.ts b/src/types/Library.d.ts new file mode 100644 index 000000000..902a230e8 --- /dev/null +++ b/src/types/Library.d.ts @@ -0,0 +1,24 @@ +type LibraryDeepLinks = { + library: string, +} + +type LibraryPage = { + deepLinks: LibraryDeepLinks, +} | null; + +type Library = { + catalog: LibraryItem[], + selectable: { + nextPage: LibraryPage, + prevPage: LibraryPage, + sorts: SortOption[], + types: TypeOption[], + }, + selected: { + request: { + page: number, + sort: string, + type: string | null, + } + } | null, +}; \ No newline at end of file diff --git a/src/types/MetaDetails.d.ts b/src/types/MetaDetails.d.ts new file mode 100644 index 000000000..2e37d6fd2 --- /dev/null +++ b/src/types/MetaDetails.d.ts @@ -0,0 +1,20 @@ +type MetaDetails = { + metaExtensions: { + url: string, + name: string, + addon: Addon, + }[], + metaItem: { + addon: Addon, + content: Loadable, + } | null, + selected: { + metaPath: ResourceRequestPath, + streamPath: ResourceRequestPath, + } | null, + streams: { + addon: Addon, + content: Loadable + }[], + title: string | null, +}; \ No newline at end of file diff --git a/src/types/Player.d.ts b/src/types/Player.d.ts new file mode 100644 index 000000000..d4508aa05 --- /dev/null +++ b/src/types/Player.d.ts @@ -0,0 +1,18 @@ +type Player = { + addon: Addon | null, + libraryItem: LibraryItem | null, + metaItem: Loadable | null, + nextVideo: Video | null, + selected: { + stream: Stream, + metaRequest: ResourceRequest, + streamRequest: ResourceRequest, + subtitlesPath: ResourceRequestPath, + } | null, + seriesInfo: { + season: number, + episode: number, + } | null, + subtitles: Subtitle[], + title: string | null, +}; \ No newline at end of file diff --git a/src/types/RemoteAddons.d.ts b/src/types/RemoteAddons.d.ts new file mode 100644 index 000000000..cd5a768f7 --- /dev/null +++ b/src/types/RemoteAddons.d.ts @@ -0,0 +1,10 @@ +type RemoteAddons = { + catalog: Catalog>, + selectable: { + catalogs: CatalogOption[], + types: TypeOption[], + }, + selected: { + request: ResourceRequest, + } | null, +}; \ No newline at end of file diff --git a/src/types/Search.d.ts b/src/types/Search.d.ts new file mode 100644 index 000000000..b9c91ba67 --- /dev/null +++ b/src/types/Search.d.ts @@ -0,0 +1 @@ +type Search = CatalogsWithExtra; \ No newline at end of file diff --git a/src/types/StremingServer.d.ts b/src/types/StremingServer.d.ts new file mode 100644 index 000000000..45f013067 --- /dev/null +++ b/src/types/StremingServer.d.ts @@ -0,0 +1,21 @@ +type StreamingServerSettings = { + appPath: string, + btDownloadSpeedHardLimit: number, + btDownloadSpeedSoftLimit: number, + btHandshakeTimeout: number, + btMaxConnections: number, + btMinPeersForStable: number, + btRequestTimeout: number, + cacheRoot: string, + cacheSize: number, + serverVersion: string, +}; + +type StreamingServer = { + baseUrl: Loadable | null, + selected: { + transportUrl: string, + } | null, + settings: Loadable | null, + torrent: [string, Loadable] | null, +}; \ No newline at end of file diff --git a/src/types/common.d.ts b/src/types/common.d.ts new file mode 100644 index 000000000..4d2cdda98 --- /dev/null +++ b/src/types/common.d.ts @@ -0,0 +1,200 @@ +interface UrlParams extends Record { + path: string, +} + +type LoadableError = string | { + type: string, + content: { + code: number, + message: string, + } +}; + +type Loadable = { + type: 'Ready' | 'Loading' | 'Err', + content: T | LoadableError, +}; + +type ResourceRequestPath = { + id: string, + type: string, + resource: string, + extra: [string, string][] +}; + +type ResourceRequest = { + base: string, + path: ResourceRequestPath, +}; + +type ExternalPlayerDeepLinks = { + androidTv: string | null, + download: string | null, + fileName: string | null, + href: string | null, + tizen: string | null, + webos: string | null, +}; + +type AddonsDeepLinks = { + addons: string, +}; + +type Torrent = [ + { + extra: any[], + id: string, + resource: string, + type: string, + }, + { + metaDetailsStreams: string | null, + metaDetailsVideos: string | null, + player: string | null, + } +]; + +type Subtitle = { + id: string, + lang: string, + origin: string, + url: string, +}; + +type Addon = { + installed: boolean, + manifest: { + id: string, + types: string[], + name: string, + description: string, + version: string, + logo: string | null, + background: string | null, + }, + transportUrl: string, +}; + +type Stream = { + ytId?: string, + name: string, + description: string, + infoHash?: string, + fileIdx?: string, + externalUrl?: string, + deepLinks: { + player: string, + externalPlayer: ExternalPlayerDeepLinks, + }, +}; + +type TrailerStream = { + ytId: string, + description: string, + deepLinks: { + player: string, + externalPlayer: ExternalPlayerDeepLinks, + }, +}; + +type Video = { + id: string, + title: string, + overview: string, + released: string, + thumbnail: string, + season?: number, + episode?: number, + watched: boolean, + deepLinks: { + externalPlayer: ExternalPlayerDeepLinks | null, + metaDetailsStreams: string | null, + player: string | null, + } +}; + +type Link = { + name: string, + category: string, + url: string, +}; + +type Item = { + type: string, + name: string, + poster: string, + posterShape: string, +}; + +interface LibraryItem extends Item { + _id: string, + progress: number, + state: { + timeOffset: number, + video_id: string, + }, +} + +interface MetaItem extends Item { + id: string, + description: string, + logo: string, + background: string, + releaseInfo: string, + released: string, + runtime: string, + videos: Video[], + trailerStreams: TrailerStream[], + links: Link[], + inLibrary: boolean, + watched: boolean, + deepLinks: { + metaDetailsStreams: string | null, + metaDetailsVideos: string | null, + player: string | null, + } +} + +type Catalog = { + title?: string, + content: T, + installed?: boolean, + deepLinks?: D, +}; + +type TypeOption = { + type: string, + selected: boolean, + deepLinks: T +}; + +type SortOption = { + sort: string, + selected: boolean, + deepLinks: T +}; + +type ExtraOption = { + isRequired: boolean, + name: string, + options: { + deepLinks: T, + selected: boolean, + value: string | null, + } +}; + +type CatalogOption = { + name: string, + selected: boolean, + deepLinks: T, +}; + +interface DiscoverCatalogOption extends CatalogOption { + id: string, + addon: Addon, +} + +interface AddonCatalogOption extends CatalogOption { + id?: string, +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..99988b3ad --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "lib": ["DOM", "DOM.Iterable"], + "jsx": "preserve", + "rootDir": "./src", + "moduleResolution": "node", + "baseUrl": ".", + "paths": { + "stremio/*": ["src/*"], + }, + "resolveJsonModule": true, + "allowJs": true, + "checkJs": false, + "noEmit": true, + "strict": false + }, + "include": [ + "./src", + ], +}