From 72031557473ea573497e174de434a251adcf22bf Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 2 May 2025 00:35:49 +0200 Subject: [PATCH] Use `.Composite` for models (better swagger) --- api/src/models/collections.ts | 6 +++--- api/src/models/entry/episode.ts | 6 +++--- api/src/models/entry/extra.ts | 6 +++--- api/src/models/entry/movie-entry.ts | 8 ++++---- api/src/models/entry/special.ts | 6 +++--- api/src/models/examples/bubble.ts | 1 - api/src/models/movie.ts | 6 +++--- api/src/models/season.ts | 6 +++--- api/src/models/serie.ts | 6 +++--- api/src/models/show.ts | 6 +++--- api/src/models/staff.ts | 8 ++++---- api/src/models/studio.ts | 6 +++--- api/src/models/video.ts | 4 ++-- api/src/models/watchlist.ts | 2 +- 14 files changed, 38 insertions(+), 39 deletions(-) diff --git a/api/src/models/collections.ts b/api/src/models/collections.ts index 91f6f8df..f3221ae3 100644 --- a/api/src/models/collections.ts +++ b/api/src/models/collections.ts @@ -45,7 +45,7 @@ export const CollectionTranslation = t.Object({ logo: t.Nullable(Image), }); -export const Collection = t.Intersect([ +export const Collection = t.Composite([ Resource(), CollectionTranslation, BaseCollection, @@ -64,7 +64,7 @@ export const FullCollection = t.Intersect([ ]); export type FullCollection = Prettify; -export const SeedCollection = t.Intersect([ +export const SeedCollection = t.Composite([ t.Omit(BaseCollection, ["kind", "startAir", "endAir", "nextRefresh"]), t.Object({ slug: t.String({ format: "slug" }), @@ -72,7 +72,7 @@ export const SeedCollection = t.Intersect([ description: "The language code this collection's items were made in.", }), translations: TranslationRecord( - t.Intersect([ + t.Composite([ t.Omit(CollectionTranslation, [ "poster", "thumbnail", diff --git a/api/src/models/entry/episode.ts b/api/src/models/entry/episode.ts index 1d1460b5..1c4bb99b 100644 --- a/api/src/models/entry/episode.ts +++ b/api/src/models/entry/episode.ts @@ -12,7 +12,7 @@ import { import { EmbeddedVideo } from "../video"; import { BaseEntry, EntryTranslation } from "./base-entry"; -export const BaseEpisode = t.Intersect([ +export const BaseEpisode = t.Composite([ t.Object({ kind: t.Literal("episode"), order: t.Number({ minimum: 1, description: "Absolute playback order." }), @@ -23,7 +23,7 @@ export const BaseEpisode = t.Intersect([ BaseEntry(), ]); -export const Episode = t.Intersect([ +export const Episode = t.Composite([ Resource(), EntryTranslation(), BaseEpisode, @@ -35,7 +35,7 @@ export const Episode = t.Intersect([ ]); export type Episode = Prettify; -export const SeedEpisode = t.Intersect([ +export const SeedEpisode = t.Composite([ t.Omit(BaseEpisode, ["thumbnail", "nextRefresh"]), t.Object({ thumbnail: t.Nullable(SeedImage), diff --git a/api/src/models/entry/extra.ts b/api/src/models/entry/extra.ts index fc248ff2..10a60873 100644 --- a/api/src/models/entry/extra.ts +++ b/api/src/models/entry/extra.ts @@ -16,7 +16,7 @@ export const ExtraType = t.UnionEnum([ ]); export type ExtraType = typeof ExtraType.static; -export const BaseExtra = t.Intersect( +export const BaseExtra = t.Composite( [ t.Object({ kind: ExtraType, @@ -32,7 +32,7 @@ export const BaseExtra = t.Intersect( }, ); -export const Extra = t.Intersect([ +export const Extra = t.Composite([ Resource(), BaseExtra, t.Object({ @@ -42,7 +42,7 @@ export const Extra = t.Intersect([ ]); export type Extra = Prettify; -export const SeedExtra = t.Intersect([ +export const SeedExtra = t.Composite([ t.Omit(BaseExtra, ["thumbnail"]), t.Object({ slug: t.String({ format: "slug" }), diff --git a/api/src/models/entry/movie-entry.ts b/api/src/models/entry/movie-entry.ts index 30bdbac2..1a8df313 100644 --- a/api/src/models/entry/movie-entry.ts +++ b/api/src/models/entry/movie-entry.ts @@ -13,7 +13,7 @@ import { import { EmbeddedVideo } from "../video"; import { BaseEntry, EntryTranslation } from "./base-entry"; -export const BaseMovieEntry = t.Intersect( +export const BaseMovieEntry = t.Composite( [ t.Object({ kind: t.Literal("movie"), @@ -33,7 +33,7 @@ export const BaseMovieEntry = t.Intersect( }, ); -export const MovieEntryTranslation = t.Intersect([ +export const MovieEntryTranslation = t.Composite([ EntryTranslation(), t.Object({ tagline: t.Nullable(t.String()), @@ -41,7 +41,7 @@ export const MovieEntryTranslation = t.Intersect([ }), ]); -export const MovieEntry = t.Intersect([ +export const MovieEntry = t.Composite([ Resource(), MovieEntryTranslation, BaseMovieEntry, @@ -53,7 +53,7 @@ export const MovieEntry = t.Intersect([ ]); export type MovieEntry = Prettify; -export const SeedMovieEntry = t.Intersect([ +export const SeedMovieEntry = t.Composite([ t.Omit(BaseMovieEntry, ["thumbnail", "nextRefresh"]), t.Object({ slug: t.Optional(t.String({ format: "slug" })), diff --git a/api/src/models/entry/special.ts b/api/src/models/entry/special.ts index b687e67d..90b8cdd0 100644 --- a/api/src/models/entry/special.ts +++ b/api/src/models/entry/special.ts @@ -12,7 +12,7 @@ import { import { EmbeddedVideo } from "../video"; import { BaseEntry, EntryTranslation } from "./base-entry"; -export const BaseSpecial = t.Intersect( +export const BaseSpecial = t.Composite( [ t.Object({ kind: t.Literal("special"), @@ -33,7 +33,7 @@ export const BaseSpecial = t.Intersect( }, ); -export const Special = t.Intersect([ +export const Special = t.Composite([ Resource(), EntryTranslation(), BaseSpecial, @@ -45,7 +45,7 @@ export const Special = t.Intersect([ ]); export type Special = Prettify; -export const SeedSpecial = t.Intersect([ +export const SeedSpecial = t.Composite([ t.Omit(BaseSpecial, ["thumbnail", "nextRefresh"]), t.Object({ thumbnail: t.Nullable(SeedImage), diff --git a/api/src/models/examples/bubble.ts b/api/src/models/examples/bubble.ts index 1326f7b4..573c0cf4 100644 --- a/api/src/models/examples/bubble.ts +++ b/api/src/models/examples/bubble.ts @@ -3,7 +3,6 @@ import type { Video } from "~/models/video"; export const bubbleVideo: Video = { id: "3cd436ee-01ff-4f45-ba98-62aabeb22f25", - slug: "bubble", path: "/video/Bubble/Bubble (2022).mkv", rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd", part: null, diff --git a/api/src/models/movie.ts b/api/src/models/movie.ts index 31f28487..d107474a 100644 --- a/api/src/models/movie.ts +++ b/api/src/models/movie.ts @@ -48,7 +48,7 @@ export const MovieTranslation = t.Object({ }); export type MovieTranslation = typeof MovieTranslation.static; -export const Movie = t.Intersect([ +export const Movie = t.Composite([ Resource(), MovieTranslation, BaseMovie, @@ -71,7 +71,7 @@ export const FullMovie = t.Intersect([ ]); export type FullMovie = Prettify; -export const SeedMovie = t.Intersect([ +export const SeedMovie = t.Composite([ t.Omit(BaseMovie, ["kind", "nextRefresh"]), t.Object({ slug: t.String({ format: "slug", examples: ["bubble"] }), @@ -79,7 +79,7 @@ export const SeedMovie = t.Intersect([ description: "The language code this movie was made in.", }), translations: TranslationRecord( - t.Intersect([ + t.Composite([ t.Omit(MovieTranslation, ["poster", "thumbnail", "banner", "logo"]), t.Object({ poster: t.Nullable(SeedImage), diff --git a/api/src/models/season.ts b/api/src/models/season.ts index 225bbce9..79c11976 100644 --- a/api/src/models/season.ts +++ b/api/src/models/season.ts @@ -27,7 +27,7 @@ export const SeasonTranslation = t.Object({ }); export type SeasonTranslation = typeof SeasonTranslation.static; -export const Season = t.Intersect([ +export const Season = t.Composite([ Resource(), SeasonTranslation, BaseSeason, @@ -35,11 +35,11 @@ export const Season = t.Intersect([ ]); export type Season = Prettify; -export const SeedSeason = t.Intersect([ +export const SeedSeason = t.Composite([ t.Omit(BaseSeason, ["nextRefresh"]), t.Object({ translations: TranslationRecord( - t.Intersect([ + t.Composite([ t.Omit(SeasonTranslation, ["poster", "thumbnail", "banner"]), t.Object({ poster: t.Nullable(SeedImage), diff --git a/api/src/models/serie.ts b/api/src/models/serie.ts index 8a9bd942..e16a0ea6 100644 --- a/api/src/models/serie.ts +++ b/api/src/models/serie.ts @@ -58,7 +58,7 @@ export const SerieTranslation = t.Object({ }); export type SerieTranslation = typeof SerieTranslation.static; -export const Serie = t.Intersect([ +export const Serie = t.Composite([ Resource(), SerieTranslation, BaseSerie, @@ -87,7 +87,7 @@ export const FullSerie = t.Intersect([ ]); export type FullSerie = Prettify; -export const SeedSerie = t.Intersect([ +export const SeedSerie = t.Composite([ t.Omit(BaseSerie, ["kind", "nextRefresh"]), t.Object({ slug: t.String({ format: "slug" }), @@ -95,7 +95,7 @@ export const SeedSerie = t.Intersect([ description: "The language code this serie was made in.", }), translations: TranslationRecord( - t.Intersect([ + t.Composite([ t.Omit(SerieTranslation, ["poster", "thumbnail", "banner", "logo"]), t.Object({ poster: t.Nullable(SeedImage), diff --git a/api/src/models/show.ts b/api/src/models/show.ts index 915ce7b4..ae5a0a43 100644 --- a/api/src/models/show.ts +++ b/api/src/models/show.ts @@ -4,7 +4,7 @@ import { Movie } from "./movie"; import { Serie } from "./serie"; export const Show = t.Union([ - t.Intersect([Movie, t.Object({ kind: t.Literal("movie") })]), - t.Intersect([Serie, t.Object({ kind: t.Literal("serie") })]), - t.Intersect([Collection, t.Object({ kind: t.Literal("collection") })]), + t.Composite([t.Object({ kind: t.Literal("movie") }), Movie]), + t.Composite([t.Object({ kind: t.Literal("serie") }), Serie]), + t.Composite([t.Object({ kind: t.Literal("collection") }), Collection]), ]); diff --git a/api/src/models/staff.ts b/api/src/models/staff.ts index 37aad31e..9d6fe403 100644 --- a/api/src/models/staff.ts +++ b/api/src/models/staff.ts @@ -28,19 +28,19 @@ const StaffData = t.Object({ image: t.Nullable(Image), externalId: ExternalId(), }); -export const Staff = t.Intersect([Resource(), StaffData, DbMetadata]); +export const Staff = t.Composite([Resource(), StaffData, DbMetadata]); export type Staff = typeof Staff.static; -export const SeedStaff = t.Intersect([ +export const SeedStaff = t.Composite([ t.Omit(Role, ["character"]), t.Object({ - character: t.Intersect([ + character: t.Composite([ t.Omit(Character, ["image"]), t.Object({ image: t.Nullable(SeedImage), }), ]), - staff: t.Intersect([ + staff: t.Composite([ t.Object({ slug: t.String({ format: "slug" }), image: t.Nullable(SeedImage), diff --git a/api/src/models/studio.ts b/api/src/models/studio.ts index c7b8beff..ce19ec0f 100644 --- a/api/src/models/studio.ts +++ b/api/src/models/studio.ts @@ -14,7 +14,7 @@ export const StudioTranslation = t.Object({ }); export type StudioTranslation = typeof StudioTranslation.static; -export const Studio = t.Intersect([ +export const Studio = t.Composite([ Resource(), StudioTranslation, BaseStudio, @@ -22,12 +22,12 @@ export const Studio = t.Intersect([ ]); export type Studio = Prettify; -export const SeedStudio = t.Intersect([ +export const SeedStudio = t.Composite([ BaseStudio, t.Object({ slug: t.String({ format: "slug" }), translations: TranslationRecord( - t.Intersect([ + t.Composite([ t.Omit(StudioTranslation, ["logo"]), t.Object({ logo: t.Nullable(SeedImage), diff --git a/api/src/models/video.ts b/api/src/models/video.ts index 04b98bd8..874a006c 100644 --- a/api/src/models/video.ts +++ b/api/src/models/video.ts @@ -113,7 +113,7 @@ export const SeedVideo = t.Object({ }); export type SeedVideo = Prettify; -export const Video = t.Intersect([ +export const Video = t.Composite([ t.Object({ id: t.String({ format: "uuid" }), }), @@ -123,7 +123,7 @@ export const Video = t.Intersect([ export type Video = Prettify; // type used in entry responses (the slug comes from the entryVideoJoin) -export const EmbeddedVideo = t.Intersect([ +export const EmbeddedVideo = t.Composite([ t.Object({ slug: t.String({ format: "slug" }) }), t.Omit(Video, ["guess", "createdAt", "updatedAt"]), ]); diff --git a/api/src/models/watchlist.ts b/api/src/models/watchlist.ts index 182b2b17..5e072f6a 100644 --- a/api/src/models/watchlist.ts +++ b/api/src/models/watchlist.ts @@ -20,7 +20,7 @@ export const SerieWatchStatus = t.Object({ }); export type SerieWatchStatus = typeof SerieWatchStatus.static; -export const MovieWatchStatus = t.Intersect([ +export const MovieWatchStatus = t.Composite([ t.Omit(SerieWatchStatus, ["startedAt", "seenCount"]), t.Object({ percent: t.Integer({