mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add db-metadata type helper
This commit is contained in:
parent
e32c83180e
commit
12faca5fb5
@ -2,6 +2,7 @@ import { t } from "elysia";
|
||||
import type { Prettify } from "elysia/dist/types";
|
||||
import { bubbleImages, duneCollection, registerExamples } from "./examples";
|
||||
import {
|
||||
DbMetadata,
|
||||
ExternalId,
|
||||
Genre,
|
||||
Image,
|
||||
@ -33,7 +34,6 @@ const BaseCollection = t.Object({
|
||||
}),
|
||||
),
|
||||
|
||||
createdAt: t.String({ format: "date-time" }),
|
||||
nextRefresh: t.String({ format: "date-time" }),
|
||||
|
||||
externalId: ExternalId,
|
||||
@ -56,6 +56,7 @@ export const Collection = t.Intersect([
|
||||
Resource(),
|
||||
CollectionTranslation,
|
||||
BaseCollection,
|
||||
DbMetadata,
|
||||
]);
|
||||
export type Collection = Prettify<typeof Collection.static>;
|
||||
|
||||
@ -68,13 +69,7 @@ export const FullCollection = t.Intersect([
|
||||
export type FullCollection = Prettify<typeof FullCollection.static>;
|
||||
|
||||
export const SeedCollection = t.Intersect([
|
||||
t.Omit(BaseCollection, [
|
||||
"kind",
|
||||
"startAir",
|
||||
"endAir",
|
||||
"createdAt",
|
||||
"nextRefresh",
|
||||
]),
|
||||
t.Omit(BaseCollection, ["kind", "startAir", "endAir", "nextRefresh"]),
|
||||
t.Object({
|
||||
slug: t.String({ format: "slug" }),
|
||||
translations: TranslationRecord(
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { t } from "elysia";
|
||||
import type { Prettify } from "~/utils";
|
||||
import { SeedCollection } from "./collections";
|
||||
import { bubble, registerExamples } from "./examples";
|
||||
import { bubbleImages } from "./examples/bubble";
|
||||
import { bubble, bubbleImages, registerExamples } from "./examples";
|
||||
import { SeedStudio } from "./studio";
|
||||
import {
|
||||
DbMetadata,
|
||||
ExternalId,
|
||||
Genre,
|
||||
Image,
|
||||
@ -34,7 +34,6 @@ const BaseMovie = t.Object({
|
||||
}),
|
||||
),
|
||||
|
||||
createdAt: t.String({ format: "date-time" }),
|
||||
nextRefresh: t.String({ format: "date-time" }),
|
||||
|
||||
externalId: ExternalId,
|
||||
@ -59,6 +58,7 @@ export const Movie = t.Intersect([
|
||||
Resource(),
|
||||
MovieTranslation,
|
||||
BaseMovie,
|
||||
DbMetadata,
|
||||
// t.Object({ isAvailable: t.Boolean() }),
|
||||
]);
|
||||
export type Movie = Prettify<typeof Movie.static>;
|
||||
@ -73,7 +73,7 @@ export const FullMovie = t.Intersect([
|
||||
export type FullMovie = Prettify<typeof FullMovie.static>;
|
||||
|
||||
export const SeedMovie = t.Intersect([
|
||||
t.Omit(BaseMovie, ["kind", "createdAt", "nextRefresh"]),
|
||||
t.Omit(BaseMovie, ["kind", "nextRefresh"]),
|
||||
t.Object({
|
||||
slug: t.String({ format: "slug", examples: ["bubble"] }),
|
||||
translations: TranslationRecord(
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { t } from "elysia";
|
||||
import type { Prettify } from "~/utils";
|
||||
import { bubbleImages, madeInAbyss, registerExamples } from "./examples";
|
||||
import { DbMetadata } from "./utils";
|
||||
import { SeasonId } from "./utils/external-id";
|
||||
import { Image, SeedImage } from "./utils/image";
|
||||
import { TranslationRecord } from "./utils/language";
|
||||
@ -11,7 +12,6 @@ export const BaseSeason = t.Object({
|
||||
startAir: 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" }),
|
||||
|
||||
externalId: SeasonId,
|
||||
@ -27,11 +27,16 @@ export const SeasonTranslation = t.Object({
|
||||
});
|
||||
export type SeasonTranslation = typeof SeasonTranslation.static;
|
||||
|
||||
export const Season = t.Intersect([Resource(), SeasonTranslation, BaseSeason]);
|
||||
export type Season = typeof Season.static;
|
||||
export const Season = t.Intersect([
|
||||
Resource(),
|
||||
SeasonTranslation,
|
||||
BaseSeason,
|
||||
DbMetadata,
|
||||
]);
|
||||
export type Season = Prettify<typeof Season.static>;
|
||||
|
||||
export const SeedSeason = t.Intersect([
|
||||
t.Omit(BaseSeason, ["createdAt", "nextRefresh"]),
|
||||
t.Omit(BaseSeason, ["nextRefresh"]),
|
||||
t.Object({
|
||||
translations: TranslationRecord(
|
||||
t.Intersect([
|
||||
|
@ -5,11 +5,16 @@ import { SeedEntry, SeedExtra } from "./entry";
|
||||
import { bubbleImages, madeInAbyss, registerExamples } from "./examples";
|
||||
import { SeedSeason } from "./season";
|
||||
import { SeedStudio } from "./studio";
|
||||
import { ExternalId } from "./utils/external-id";
|
||||
import { Genre } from "./utils/genres";
|
||||
import { Image, SeedImage } from "./utils/image";
|
||||
import { Language, TranslationRecord } from "./utils/language";
|
||||
import { Resource } from "./utils/resource";
|
||||
import {
|
||||
DbMetadata,
|
||||
ExternalId,
|
||||
Genre,
|
||||
Image,
|
||||
Language,
|
||||
Resource,
|
||||
SeedImage,
|
||||
TranslationRecord,
|
||||
} from "./utils";
|
||||
|
||||
export const SerieStatus = t.UnionEnum([
|
||||
"unknown",
|
||||
@ -39,7 +44,6 @@ const BaseSerie = t.Object({
|
||||
}),
|
||||
),
|
||||
|
||||
createdAt: t.String({ format: "date-time" }),
|
||||
nextRefresh: t.String({ format: "date-time" }),
|
||||
|
||||
externalId: ExternalId,
|
||||
@ -60,7 +64,12 @@ export const SerieTranslation = t.Object({
|
||||
});
|
||||
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 const FullSerie = t.Intersect([
|
||||
@ -72,7 +81,7 @@ export const FullSerie = t.Intersect([
|
||||
export type FullMovie = Prettify<typeof FullSerie.static>;
|
||||
|
||||
export const SeedSerie = t.Intersect([
|
||||
t.Omit(BaseSerie, ["kind", "createdAt", "nextRefresh"]),
|
||||
t.Omit(BaseSerie, ["kind", "nextRefresh"]),
|
||||
t.Object({
|
||||
slug: t.String({ format: "slug" }),
|
||||
translations: TranslationRecord(
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { t } from "elysia";
|
||||
import type { Prettify } from "elysia/dist/types";
|
||||
import { madeInAbyss, registerExamples } from "./examples";
|
||||
import { ExternalId, Resource, TranslationRecord } from "./utils";
|
||||
import { DbMetadata, ExternalId, Resource, TranslationRecord } from "./utils";
|
||||
import { Image, SeedImage } from "./utils/image";
|
||||
|
||||
const BaseStudio = t.Object({
|
||||
createdAt: t.String({ format: "date-time" }),
|
||||
|
||||
externalId: ExternalId,
|
||||
});
|
||||
|
||||
@ -15,11 +13,16 @@ export const StudioTranslation = t.Object({
|
||||
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 const SeedStudio = t.Intersect([
|
||||
t.Omit(BaseStudio, ["createdAt"]),
|
||||
BaseStudio,
|
||||
t.Object({
|
||||
slug: t.String({ format: "slug" }),
|
||||
translations: TranslationRecord(
|
||||
|
6
api/src/models/utils/db-metadata.ts
Normal file
6
api/src/models/utils/db-metadata.ts
Normal 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" }),
|
||||
});
|
@ -7,3 +7,4 @@ export * from "./filters";
|
||||
export * from "./page";
|
||||
export * from "./sort";
|
||||
export * from "./keyset-paginate";
|
||||
export * from "./db-metadata";
|
||||
|
@ -1,10 +1,9 @@
|
||||
import { t } from "elysia";
|
||||
import { comment } from "../utils";
|
||||
import { type Prettify, comment } from "~/utils";
|
||||
import { bubbleVideo, registerExamples } from "./examples";
|
||||
import { DbMetadata, Resource } from "./utils";
|
||||
|
||||
export const Video = t.Object({
|
||||
id: t.String({ format: "uuid" }),
|
||||
slug: t.String({ format: "slug" }),
|
||||
export const SeedVideo = t.Object({
|
||||
path: t.String(),
|
||||
rendering: t.String({
|
||||
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.",
|
||||
}),
|
||||
|
||||
createdAt: t.String({ format: "date-time" }),
|
||||
|
||||
guess: t.Optional(
|
||||
t.Recursive((Self) =>
|
||||
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 const Video = t.Intersect([Resource(), SeedVideo, DbMetadata]);
|
||||
export type Video = Prettify<typeof Video.static>;
|
||||
|
||||
registerExamples(Video, bubbleVideo);
|
||||
|
Loading…
x
Reference in New Issue
Block a user