Add db-metadata type helper

This commit is contained in:
Zoe Roux 2025-03-02 21:44:55 +01:00
parent e32c83180e
commit 12faca5fb5
No known key found for this signature in database
8 changed files with 56 additions and 39 deletions

View File

@ -2,6 +2,7 @@ import { t } from "elysia";
import type { Prettify } from "elysia/dist/types"; import type { Prettify } from "elysia/dist/types";
import { bubbleImages, duneCollection, registerExamples } from "./examples"; import { bubbleImages, duneCollection, registerExamples } from "./examples";
import { import {
DbMetadata,
ExternalId, ExternalId,
Genre, Genre,
Image, Image,
@ -33,7 +34,6 @@ const BaseCollection = t.Object({
}), }),
), ),
createdAt: t.String({ format: "date-time" }),
nextRefresh: t.String({ format: "date-time" }), nextRefresh: t.String({ format: "date-time" }),
externalId: ExternalId, externalId: ExternalId,
@ -56,6 +56,7 @@ export const Collection = t.Intersect([
Resource(), Resource(),
CollectionTranslation, CollectionTranslation,
BaseCollection, BaseCollection,
DbMetadata,
]); ]);
export type Collection = Prettify<typeof Collection.static>; export type Collection = Prettify<typeof Collection.static>;
@ -68,13 +69,7 @@ export const FullCollection = t.Intersect([
export type FullCollection = Prettify<typeof FullCollection.static>; export type FullCollection = Prettify<typeof FullCollection.static>;
export const SeedCollection = t.Intersect([ export const SeedCollection = t.Intersect([
t.Omit(BaseCollection, [ t.Omit(BaseCollection, ["kind", "startAir", "endAir", "nextRefresh"]),
"kind",
"startAir",
"endAir",
"createdAt",
"nextRefresh",
]),
t.Object({ t.Object({
slug: t.String({ format: "slug" }), slug: t.String({ format: "slug" }),
translations: TranslationRecord( translations: TranslationRecord(

View File

@ -1,10 +1,10 @@
import { t } from "elysia"; import { t } from "elysia";
import type { Prettify } from "~/utils"; import type { Prettify } from "~/utils";
import { SeedCollection } from "./collections"; import { SeedCollection } from "./collections";
import { bubble, registerExamples } from "./examples"; import { bubble, bubbleImages, registerExamples } from "./examples";
import { bubbleImages } from "./examples/bubble";
import { SeedStudio } from "./studio"; import { SeedStudio } from "./studio";
import { import {
DbMetadata,
ExternalId, ExternalId,
Genre, Genre,
Image, Image,
@ -34,7 +34,6 @@ const BaseMovie = t.Object({
}), }),
), ),
createdAt: t.String({ format: "date-time" }),
nextRefresh: t.String({ format: "date-time" }), nextRefresh: t.String({ format: "date-time" }),
externalId: ExternalId, externalId: ExternalId,
@ -59,6 +58,7 @@ export const Movie = t.Intersect([
Resource(), Resource(),
MovieTranslation, MovieTranslation,
BaseMovie, BaseMovie,
DbMetadata,
// t.Object({ isAvailable: t.Boolean() }), // t.Object({ isAvailable: t.Boolean() }),
]); ]);
export type Movie = Prettify<typeof Movie.static>; export type Movie = Prettify<typeof Movie.static>;
@ -73,7 +73,7 @@ export const FullMovie = t.Intersect([
export type FullMovie = Prettify<typeof FullMovie.static>; export type FullMovie = Prettify<typeof FullMovie.static>;
export const SeedMovie = t.Intersect([ export const SeedMovie = t.Intersect([
t.Omit(BaseMovie, ["kind", "createdAt", "nextRefresh"]), t.Omit(BaseMovie, ["kind", "nextRefresh"]),
t.Object({ t.Object({
slug: t.String({ format: "slug", examples: ["bubble"] }), slug: t.String({ format: "slug", examples: ["bubble"] }),
translations: TranslationRecord( translations: TranslationRecord(

View File

@ -1,6 +1,7 @@
import { t } from "elysia"; import { t } from "elysia";
import type { Prettify } from "~/utils"; import type { Prettify } from "~/utils";
import { bubbleImages, madeInAbyss, registerExamples } from "./examples"; import { bubbleImages, madeInAbyss, registerExamples } from "./examples";
import { DbMetadata } from "./utils";
import { SeasonId } from "./utils/external-id"; import { SeasonId } from "./utils/external-id";
import { Image, SeedImage } from "./utils/image"; import { Image, SeedImage } from "./utils/image";
import { TranslationRecord } from "./utils/language"; import { TranslationRecord } from "./utils/language";
@ -11,7 +12,6 @@ export const BaseSeason = t.Object({
startAir: t.Nullable(t.String({ format: "date" })), startAir: t.Nullable(t.String({ format: "date" })),
endAir: t.Nullable(t.String({ format: "date" })), endAir: t.Nullable(t.String({ format: "date" })),
createdAt: t.String({ format: "date-time" }),
nextRefresh: t.String({ format: "date-time" }), nextRefresh: t.String({ format: "date-time" }),
externalId: SeasonId, externalId: SeasonId,
@ -27,11 +27,16 @@ export const SeasonTranslation = t.Object({
}); });
export type SeasonTranslation = typeof SeasonTranslation.static; export type SeasonTranslation = typeof SeasonTranslation.static;
export const Season = t.Intersect([Resource(), SeasonTranslation, BaseSeason]); export const Season = t.Intersect([
export type Season = typeof Season.static; Resource(),
SeasonTranslation,
BaseSeason,
DbMetadata,
]);
export type Season = Prettify<typeof Season.static>;
export const SeedSeason = t.Intersect([ export const SeedSeason = t.Intersect([
t.Omit(BaseSeason, ["createdAt", "nextRefresh"]), t.Omit(BaseSeason, ["nextRefresh"]),
t.Object({ t.Object({
translations: TranslationRecord( translations: TranslationRecord(
t.Intersect([ t.Intersect([

View File

@ -5,11 +5,16 @@ import { SeedEntry, SeedExtra } from "./entry";
import { bubbleImages, madeInAbyss, registerExamples } from "./examples"; import { bubbleImages, madeInAbyss, registerExamples } from "./examples";
import { SeedSeason } from "./season"; import { SeedSeason } from "./season";
import { SeedStudio } from "./studio"; import { SeedStudio } from "./studio";
import { ExternalId } from "./utils/external-id"; import {
import { Genre } from "./utils/genres"; DbMetadata,
import { Image, SeedImage } from "./utils/image"; ExternalId,
import { Language, TranslationRecord } from "./utils/language"; Genre,
import { Resource } from "./utils/resource"; Image,
Language,
Resource,
SeedImage,
TranslationRecord,
} from "./utils";
export const SerieStatus = t.UnionEnum([ export const SerieStatus = t.UnionEnum([
"unknown", "unknown",
@ -39,7 +44,6 @@ const BaseSerie = t.Object({
}), }),
), ),
createdAt: t.String({ format: "date-time" }),
nextRefresh: t.String({ format: "date-time" }), nextRefresh: t.String({ format: "date-time" }),
externalId: ExternalId, externalId: ExternalId,
@ -60,7 +64,12 @@ export const SerieTranslation = t.Object({
}); });
export type SerieTranslation = typeof SerieTranslation.static; export type SerieTranslation = typeof SerieTranslation.static;
export const Serie = t.Intersect([Resource(), SerieTranslation, BaseSerie]); export const Serie = t.Intersect([
Resource(),
SerieTranslation,
BaseSerie,
DbMetadata,
]);
export type Serie = Prettify<typeof Serie.static>; export type Serie = Prettify<typeof Serie.static>;
export const FullSerie = t.Intersect([ export const FullSerie = t.Intersect([
@ -72,7 +81,7 @@ export const FullSerie = t.Intersect([
export type FullMovie = Prettify<typeof FullSerie.static>; export type FullMovie = Prettify<typeof FullSerie.static>;
export const SeedSerie = t.Intersect([ export const SeedSerie = t.Intersect([
t.Omit(BaseSerie, ["kind", "createdAt", "nextRefresh"]), t.Omit(BaseSerie, ["kind", "nextRefresh"]),
t.Object({ t.Object({
slug: t.String({ format: "slug" }), slug: t.String({ format: "slug" }),
translations: TranslationRecord( translations: TranslationRecord(

View File

@ -1,12 +1,10 @@
import { t } from "elysia"; import { t } from "elysia";
import type { Prettify } from "elysia/dist/types"; import type { Prettify } from "elysia/dist/types";
import { madeInAbyss, registerExamples } from "./examples"; import { madeInAbyss, registerExamples } from "./examples";
import { ExternalId, Resource, TranslationRecord } from "./utils"; import { DbMetadata, ExternalId, Resource, TranslationRecord } from "./utils";
import { Image, SeedImage } from "./utils/image"; import { Image, SeedImage } from "./utils/image";
const BaseStudio = t.Object({ const BaseStudio = t.Object({
createdAt: t.String({ format: "date-time" }),
externalId: ExternalId, externalId: ExternalId,
}); });
@ -15,11 +13,16 @@ export const StudioTranslation = t.Object({
logo: t.Nullable(Image), logo: t.Nullable(Image),
}); });
export const Studio = t.Intersect([Resource(), StudioTranslation, BaseStudio]); export const Studio = t.Intersect([
Resource(),
StudioTranslation,
BaseStudio,
DbMetadata,
]);
export type Studio = Prettify<typeof Studio.static>; export type Studio = Prettify<typeof Studio.static>;
export const SeedStudio = t.Intersect([ export const SeedStudio = t.Intersect([
t.Omit(BaseStudio, ["createdAt"]), BaseStudio,
t.Object({ t.Object({
slug: t.String({ format: "slug" }), slug: t.String({ format: "slug" }),
translations: TranslationRecord( translations: TranslationRecord(

View File

@ -0,0 +1,6 @@
import { t } from "elysia";
export const DbMetadata = t.Object({
createdAt: t.String({ format: "date-time" }),
updatedAt: t.String({ format: "date-time" }),
});

View File

@ -7,3 +7,4 @@ export * from "./filters";
export * from "./page"; export * from "./page";
export * from "./sort"; export * from "./sort";
export * from "./keyset-paginate"; export * from "./keyset-paginate";
export * from "./db-metadata";

View File

@ -1,10 +1,9 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../utils"; import { type Prettify, comment } from "~/utils";
import { bubbleVideo, registerExamples } from "./examples"; import { bubbleVideo, registerExamples } from "./examples";
import { DbMetadata, Resource } from "./utils";
export const Video = t.Object({ export const SeedVideo = t.Object({
id: t.String({ format: "uuid" }),
slug: t.String({ format: "slug" }),
path: t.String(), path: t.String(),
rendering: t.String({ rendering: t.String({
description: comment` description: comment`
@ -30,8 +29,6 @@ export const Video = t.Object({
"Kyoo will prefer playing back the highest `version` number if there are multiples rendering.", "Kyoo will prefer playing back the highest `version` number if there are multiples rendering.",
}), }),
createdAt: t.String({ format: "date-time" }),
guess: t.Optional( guess: t.Optional(
t.Recursive((Self) => t.Recursive((Self) =>
t.Object( t.Object(
@ -69,8 +66,9 @@ export const Video = t.Object({
), ),
), ),
}); });
export type Video = typeof Video.static;
registerExamples(Video, bubbleVideo);
export const SeedVideo = t.Omit(Video, ["id", "slug", "createdAt"]);
export type SeedVideo = typeof SeedVideo.static; export type SeedVideo = typeof SeedVideo.static;
export const Video = t.Intersect([Resource(), SeedVideo, DbMetadata]);
export type Video = Prettify<typeof Video.static>;
registerExamples(Video, bubbleVideo);