diff --git a/types/tryghost__content-api/index.d.ts b/types/tryghost__content-api/index.d.ts index 6903802fc0..afbfb1c282 100644 --- a/types/tryghost__content-api/index.d.ts +++ b/types/tryghost__content-api/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Kevin Nguyen // Anton Van Eechaute // Yashar Moradi +// Oliver Emery // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export type ArrayOrValue = T | T[]; @@ -50,9 +51,10 @@ export interface Twitter { twitter_description?: Nullable; } -export interface SocialMedia extends Facebook, Twitter {} +export interface SocialMedia extends Facebook, Twitter { +} -export interface Setting extends Metadata, CodeInjection, SocialMedia { +export interface Settings extends Metadata, CodeInjection, SocialMedia { title?: string; description?: string; logo?: string; @@ -106,11 +108,11 @@ export interface PostOrPage extends Identification, Excerpt, CodeInjection, Meta // Post or Page title?: string; - html?: string | null; + html?: Nullable; plaintext?: Nullable; // Image - feature_image?: string | null; + feature_image?: Nullable; featured?: boolean; // Dates @@ -119,11 +121,14 @@ export interface PostOrPage extends Identification, Excerpt, CodeInjection, Meta published_at?: Nullable; // Custom Template for posts and pages - custom_template?: string | null; + custom_template?: Nullable; // Post or Page page?: boolean; + // Reading time + reading_time?: number; + // Tags - Only shown when using Include param tags?: Tag[]; primary_tag?: Nullable; @@ -136,7 +141,7 @@ export interface PostOrPage extends Identification, Excerpt, CodeInjection, Meta canonical_url?: Nullable; } -export type GhostData = PostOrPage | Author | Tag | Setting; +export type GhostData = PostOrPage | Author | Tag | Settings; export type IncludeParam = 'authors' | 'tags' | 'count.posts'; @@ -170,29 +175,21 @@ export interface ReadFunction { (data: { id: Nullable } | { slug: Nullable }, options?: Params, memberToken?: Nullable): Promise; } -export interface PostObject { - posts: PostOrPage[]; +interface BrowseResults extends Array { meta: { pagination: Pagination }; } -export interface AuthorsObject { - authors: Author[]; - meta: { pagination: Pagination }; +export interface PostsOrPages extends BrowseResults { } -export interface TagsObject { - tags: Tag[]; - meta: { pagination: Pagination }; +export interface Authors extends BrowseResults { } -export interface PagesObject { - pages: PostOrPage[]; - meta: { pagination: Pagination }; +export interface Tags extends BrowseResults { } -export interface SettingsObject { - settings: Setting; - meta: {}; +export interface SettingsResponse extends Settings { + meta: any; } export interface GhostError { @@ -219,24 +216,29 @@ export interface GhostContentAPIOptions { export interface GhostAPI { posts: { - browse: BrowseFunction; + browse: BrowseFunction; read: ReadFunction; }; authors: { - browse: BrowseFunction; + browse: BrowseFunction; read: ReadFunction; }; tags: { - browse: BrowseFunction; + browse: BrowseFunction; read: ReadFunction; }; pages: { - browse: BrowseFunction; + browse: BrowseFunction; read: ReadFunction; }; settings: { - browse: BrowseFunction; + browse: BrowseFunction; }; } -export default function GhostContentAPI(options: GhostContentAPIOptions): GhostAPI; +declare var GhostContentAPI: { + (options: GhostContentAPIOptions): GhostAPI; + new(options: GhostContentAPIOptions): GhostAPI; +}; + +export default GhostContentAPI; diff --git a/types/tryghost__content-api/tryghost__content-api-tests.ts b/types/tryghost__content-api/tryghost__content-api-tests.ts index db74840b98..3d60752e67 100644 --- a/types/tryghost__content-api/tryghost__content-api-tests.ts +++ b/types/tryghost__content-api/tryghost__content-api-tests.ts @@ -1,12 +1,9 @@ -import GhostContentAPI, { PostOrPage } from '@tryghost/content-api'; +import GhostContentAPI from '@tryghost/content-api'; -const api = GhostContentAPI({ url: 'test', version: 'v3', key: '' }); // $ExpectType GhostAPI +const api = new GhostContentAPI({ url: 'test', version: 'v3', key: '' }); // $ExpectType GhostAPI -let pages: PostOrPage[]; -const pagesBrowsePromise = api.pages.browse(); // $ExpectType Promise - -pagesBrowsePromise.then(pageObject => { - pages = pageObject.pages; +const pagesBrowsePromise = api.pages.browse(); // $ExpectType Promise +pagesBrowsePromise.then(pages => { api.pages.read(pages[0], { include: 'authors' }); // $ExpectType Promise });