fix: update LPE data types

This commit is contained in:
Hossein Mehrabi 2023-08-14 17:29:10 +03:30
parent 9abec91f69
commit ce1f3fed73
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
2 changed files with 41 additions and 29 deletions

View File

@ -1,4 +1,13 @@
import { DictValues } from '../utils/type.utils'
export namespace LPE { export namespace LPE {
export const PostTypes = {
Podcast: 'podcast',
Article: 'article',
} as const
export type PostType = DictValues<typeof PostTypes>
export namespace Image { export namespace Image {
export type Document = { export type Document = {
url: string url: string
@ -11,9 +20,7 @@ export namespace LPE {
export namespace Author { export namespace Author {
export type Document = { export type Document = {
name: string name: string
url?: string
emailAddress?: string emailAddress?: string
image?: Image.Document
} }
} }
@ -44,8 +51,7 @@ export namespace LPE {
Text: 'text', Text: 'text',
} as const } as const
export type ContentBlockType = export type ContentBlockType = DictValues<typeof ContentBlockTypes>
(typeof ContentBlockTypes)[keyof typeof ContentBlockTypes]
export const ContentBlockLabels = { export const ContentBlockLabels = {
Title: 'title', Title: 'title',
@ -58,8 +64,7 @@ export namespace LPE {
CoverImage: 'cover_image', CoverImage: 'cover_image',
} as const } as const
export type ContentBlockLabel = export type ContentBlockLabel = DictValues<typeof ContentBlockLabels>
(typeof ContentBlockLabels)[keyof typeof ContentBlockLabels]
export type ContentBlockCommon<D = any> = { export type ContentBlockCommon<D = any> = {
id: string id: string
@ -84,20 +89,13 @@ export namespace LPE {
export type ContentBlock<D = any> = TextBlock<D> | ImageBlock<D> export type ContentBlock<D = any> = TextBlock<D> | ImageBlock<D>
export type SearchResultItemData = { export type SearchResultItemData =
id: string | ({
url: string type: typeof PostTypes.Article
slug: string } & Article.Metadata)
date: string | ({
title: string type: typeof PostTypes.Podcast
tags: string } & Required<Podcast.Document>)
description: string
priority: 1 | 2 | 3
authors: Author.Document[]
coverImage?: Post.ImageBlock
type: 'article' | 'podcast'
}
} }
export namespace Article { export namespace Article {
@ -142,41 +140,54 @@ export namespace LPE {
export type Show = { export type Show = {
id: string id: string
slug: string slug: string
url: string
title: string title: string
description: string description: string
logo: Image.Document logo: Image.Document
hosts: Author.Document[] hosts: Author.Document[]
numberOfEpisodes: number
episodes?: Omit<Podcast.Document, 'show'>[] episodes?: Omit<Podcast.Document, 'show'>[]
} }
export const ChannelNames = {
ApplePodcasts: 'apple_podcasts',
GooglePodcasts: 'google_podcasts',
Spotify: 'spotify',
} as const
export type ChannelName = DictValues<typeof ChannelNames>
export type Channel = {
name: ChannelName
url: string
}
export type Metadata = { export type Metadata = {
id: string id: string
slug: string slug: string
title: string title: string
tags: string[] tags: string[]
summary: string description: string
authors: Author.Document[] authors: Author.Document[]
publishedAt: string publishedAt: string
episodeNumber: number episodeNumber: number
coverImage?: Post.ImageBlock
show?: Show
} }
export type TranscriptionItem = { export type TranscriptionItem = {
text: string html: string
start?: number start?: number
end?: number end?: number
speaker?: string speaker?: string
} }
export type Content = { export type Content = {
coverImage?: Post.ImageBlock channels: Channel[]
transcription: TranscriptionItem[]
references?: Post.TextBlock[]
credits?: Post.TextBlock[] credits?: Post.TextBlock[]
transcription: TranscriptionItem[]
} }
export type Document = Metadata & export type Document = Metadata & Content
Content & {
show: Show
}
} }
} }

1
src/utils/type.utils.ts Normal file
View File

@ -0,0 +1 @@
export type DictValues<T> = T[keyof T]