Prettify entry types

This commit is contained in:
Zoe Roux 2025-02-18 17:38:42 +01:00
parent c730d47cd9
commit c70e11d36a
8 changed files with 23 additions and 17 deletions

View File

@ -1,4 +1,5 @@
import { t } from "elysia"; import { t } from "elysia";
import type { Prettify } from "~/utils";
import { EpisodeId, Resource, SeedImage, TranslationRecord } from "../utils"; import { EpisodeId, Resource, SeedImage, TranslationRecord } from "../utils";
import { BaseEntry, EntryTranslation } from "./base-entry"; import { BaseEntry, EntryTranslation } from "./base-entry";
@ -14,7 +15,7 @@ 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 type Episode = Prettify<typeof Episode.static>;
export const SeedEpisode = t.Intersect([ export const SeedEpisode = t.Intersect([
t.Omit(BaseEpisode, ["thumbnail", "createdAt", "nextRefresh"]), t.Omit(BaseEpisode, ["thumbnail", "createdAt", "nextRefresh"]),
@ -24,4 +25,4 @@ export const SeedEpisode = t.Intersect([
videos: t.Optional(t.Array(t.String({ format: "uuid" }))), videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}), }),
]); ]);
export type SeedEpisode = typeof SeedEpisode.static; export type SeedEpisode = Prettify<typeof SeedEpisode.static>;

View File

@ -1,5 +1,5 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "~/utils"; import { type Prettify, comment } from "~/utils";
import { SeedImage } from "../utils"; import { SeedImage } from "../utils";
import { Resource } from "../utils/resource"; import { Resource } from "../utils/resource";
import { BaseEntry } from "./base-entry"; import { BaseEntry } from "./base-entry";
@ -31,7 +31,7 @@ export const BaseExtra = t.Intersect(
); );
export const Extra = t.Intersect([Resource(), BaseExtra]); export const Extra = t.Intersect([Resource(), BaseExtra]);
export type Extra = typeof Extra.static; export type Extra = Prettify<typeof Extra.static>;
export const SeedExtra = t.Intersect([ export const SeedExtra = t.Intersect([
t.Omit(BaseExtra, ["thumbnail", "createdAt"]), t.Omit(BaseExtra, ["thumbnail", "createdAt"]),
@ -41,4 +41,4 @@ export const SeedExtra = t.Intersect([
video: t.String({ format: "uuid" }), video: t.String({ format: "uuid" }),
}), }),
]); ]);
export type SeedExtra = typeof SeedExtra.static; export type SeedExtra = Prettify<typeof SeedExtra.static>;

View File

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

View File

@ -1,5 +1,5 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../../utils"; import { comment, Prettify } from "../../utils";
import { import {
ExternalId, ExternalId,
Image, Image,
@ -42,7 +42,7 @@ export const MovieEntry = t.Intersect([
BaseMovieEntry, BaseMovieEntry,
MovieEntryTranslation, MovieEntryTranslation,
]); ]);
export type MovieEntry = typeof MovieEntry.static; export type MovieEntry = Prettify<typeof MovieEntry.static>;
export const SeedMovieEntry = t.Intersect([ export const SeedMovieEntry = t.Intersect([
t.Omit(BaseMovieEntry, ["thumbnail", "createdAt", "nextRefresh"]), t.Omit(BaseMovieEntry, ["thumbnail", "createdAt", "nextRefresh"]),
@ -58,4 +58,4 @@ export const SeedMovieEntry = t.Intersect([
videos: t.Optional(t.Array(t.String({ format: "uuid" }))), videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}), }),
]); ]);
export type SeedMovieEntry = typeof SeedMovieEntry.static; export type SeedMovieEntry = Prettify<typeof SeedMovieEntry.static>;

View File

@ -1,5 +1,5 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../../utils"; import { type Prettify, comment } from "~/utils";
import { EpisodeId, Resource, SeedImage, TranslationRecord } from "../utils"; import { EpisodeId, Resource, SeedImage, TranslationRecord } from "../utils";
import { BaseEntry, EntryTranslation } from "./base-entry"; import { BaseEntry, EntryTranslation } from "./base-entry";
@ -25,7 +25,7 @@ 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 type Special = Prettify<typeof Special.static>;
export const SeedSpecial = t.Intersect([ export const SeedSpecial = t.Intersect([
t.Omit(BaseSpecial, ["thumbnail", "createdAt", "nextRefresh"]), t.Omit(BaseSpecial, ["thumbnail", "createdAt", "nextRefresh"]),
@ -35,4 +35,4 @@ export const SeedSpecial = t.Intersect([
videos: t.Optional(t.Array(t.String({ format: "uuid" }))), videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}), }),
]); ]);
export type SeedSpecial = typeof SeedSpecial.static; export type SeedSpecial = Prettify<typeof SeedSpecial.static>;

View File

@ -1,5 +1,5 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../../utils"; import { type Prettify, comment } from "~/utils";
import { Resource } from "../utils/resource"; import { Resource } from "../utils/resource";
import { BaseEntry, EntryTranslation } from "./base-entry"; import { BaseEntry, EntryTranslation } from "./base-entry";
@ -27,4 +27,4 @@ export const UnknownEntry = t.Intersect([
BaseUnknownEntry, BaseUnknownEntry,
UnknownEntryTranslation, UnknownEntryTranslation,
]); ]);
export type UnknownEntry = typeof UnknownEntry.static; export type UnknownEntry = Prettify<typeof UnknownEntry.static>;

View File

@ -1,4 +1,5 @@
import { t } from "elysia"; import { t } from "elysia";
import type { Prettify } from "~/utils";
import { bubble, registerExamples } from "./examples"; import { bubble, registerExamples } from "./examples";
import { bubbleImages } from "./examples/bubble"; import { bubbleImages } from "./examples/bubble";
import { import {
@ -57,7 +58,7 @@ export const Movie = t.Intersect([
BaseMovie, BaseMovie,
t.Object({ isAvailable: t.Boolean() }), t.Object({ isAvailable: t.Boolean() }),
]); ]);
export type Movie = typeof Movie.static; export type Movie = Prettify<typeof Movie.static>;
export const FullMovie = t.Intersect([ export const FullMovie = t.Intersect([
Movie, Movie,
@ -86,7 +87,7 @@ export const SeedMovie = t.Intersect([
videos: t.Optional(t.Array(t.String({ format: "uuid" }))), videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
}), }),
]); ]);
export type SeedMovie = typeof SeedMovie.static; export type SeedMovie = Prettify<typeof SeedMovie.static>;
registerExamples(Movie, { registerExamples(Movie, {
...bubble, ...bubble,

View File

@ -10,3 +10,7 @@ export const comment = (str: TemplateStringsArray, ...values: any[]) =>
export function getYear(date: string) { export function getYear(date: string) {
return new Date(date).getUTCFullYear(); return new Date(date).getUTCFullYear();
} }
export type Prettify<T> = {
[K in keyof T]: Prettify<T[K]>;
} & {};