Add seed entry types

This commit is contained in:
Zoe Roux 2025-01-25 16:38:32 +01:00
parent d4257c1d02
commit b9c022f614
No known key found for this signature in database
6 changed files with 65 additions and 15 deletions

View File

@ -1,7 +1,6 @@
import { t } from "elysia";
import { EpisodeId } from "../utils/external-id";
import { Resource } from "../utils/resource";
import { BaseEntry, EntryTranslation } from "./base-entry";
import { EpisodeId, SeedImage, TranslationRecord, Resource } from "../utils";
export const BaseEpisode = t.Intersect([
BaseEntry,
@ -14,5 +13,16 @@ export const BaseEpisode = t.Intersect([
}),
]);
export const Episode = t.Intersect([Resource, BaseEpisode, EntryTranslation]);
export const Episode = t.Intersect([Resource(), BaseEpisode, EntryTranslation]);
export type Episode = typeof Episode.static;
export const SeedEpisode = t.Intersect([
BaseEpisode,
t.Omit(BaseEntry, ["thumbnail", "createdAt", "nextRefresh"]),
t.Object({
thumbnail: t.Nullable(SeedImage),
translations: TranslationRecord(EntryTranslation),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}),
]);
export type SeedEpisode = typeof SeedEpisode.static;

View File

@ -31,5 +31,5 @@ export const BaseExtra = t.Intersect(
},
);
export const Extra = t.Intersect([Resource, BaseExtra, EntryTranslation]);
export const Extra = t.Intersect([Resource(), BaseExtra, EntryTranslation]);
export type Extra = typeof Extra.static;

View File

@ -1,9 +1,19 @@
import { t } from "elysia";
import { Episode, MovieEntry, Special } from "../entry";
import {
Episode,
SeedEpisode,
MovieEntry,
SeedMovieEntry,
Special,
SeedSpecial,
} from "../entry";
export const Entry = t.Union([Episode, MovieEntry, Special]);
export type Entry = typeof Entry.static;
export const SeedEntry = t.Union([SeedEpisode, SeedMovieEntry, SeedSpecial]);
export type SeedEntry = typeof Entry.static;
export * from "./episode";
export * from "./movie-entry";
export * from "./special";

View File

@ -1,13 +1,17 @@
import { t } from "elysia";
import { comment } from "../../utils";
import { ExternalId } from "../utils/external-id";
import { Image } from "../utils/image";
import { Resource } from "../utils/resource";
import { BaseEntry, EntryTranslation } from "./base-entry";
import {
Resource,
Image,
SeedImage,
ExternalId,
TranslationRecord,
} from "../utils";
export const BaseMovieEntry = t.Intersect(
[
t.Omit(BaseEntry, ["thumbnail"]),
BaseEntry,
t.Object({
kind: t.Literal("movie"),
order: t.Number({
@ -29,13 +33,29 @@ export const MovieEntryTranslation = t.Intersect([
EntryTranslation,
t.Object({
tagline: t.Nullable(t.String()),
thumbnail: t.Nullable(Image),
poster: t.Nullable(Image),
}),
]);
export const MovieEntry = t.Intersect([
Resource,
Resource(),
BaseMovieEntry,
MovieEntryTranslation,
]);
export type MovieEntry = typeof MovieEntry.static;
export const SeedMovieEntry = t.Intersect([
BaseMovieEntry,
t.Omit(BaseEntry, ["thumbnail", "createdAt", "nextRefresh"]),
t.Object({
thumbnail: t.Nullable(SeedImage),
translations: TranslationRecord(
t.Intersect([
t.Omit(MovieEntryTranslation, ["poster"]),
t.Object({ poster: t.Nullable(SeedImage) }),
]),
),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}),
]);
export type SeedMovieEntry = typeof SeedMovieEntry.static;

View File

@ -1,8 +1,7 @@
import { t } from "elysia";
import { comment } from "../../utils";
import { EpisodeId } from "../utils/external-id";
import { Resource } from "../utils/resource";
import { BaseEntry, EntryTranslation } from "./base-entry";
import { EpisodeId, Resource, SeedImage, TranslationRecord } from "../utils";
export const BaseSpecial = t.Intersect(
[
@ -25,5 +24,16 @@ export const BaseSpecial = t.Intersect(
},
);
export const Special = t.Intersect([Resource, BaseSpecial, EntryTranslation]);
export const Special = t.Intersect([Resource(), BaseSpecial, EntryTranslation]);
export type Special = typeof Special.static;
export const SeedSpecial = t.Intersect([
BaseSpecial,
t.Omit(BaseEntry, ["thumbnail", "createdAt", "nextRefresh"]),
t.Object({
thumbnail: t.Nullable(SeedImage),
translations: TranslationRecord(EntryTranslation),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}),
]);
export type SeedSpecial = typeof SeedSpecial.static;

View File

@ -23,7 +23,7 @@ export const UnknownEntryTranslation = t.Omit(EntryTranslation, [
]);
export const UnknownEntry = t.Intersect([
Resource,
Resource(),
BaseUnknownEntry,
UnknownEntryTranslation,
]);