Fix typechecking

This commit is contained in:
Zoe Roux
2025-05-02 02:12:08 +02:00
parent 71b3ee61af
commit 379765b28f
11 changed files with 39 additions and 37 deletions
+8 -6
View File
@@ -143,13 +143,15 @@ export const entryVideosQ = db
export const mapProgress = ({ aliased }: { aliased: boolean }) => {
const { time, percent, playedDate, videoId } = getColumns(entryProgressQ);
const ret = {
time: coalesce(time, sql`0`),
percent: coalesce(percent, sql`0`),
playedDate: sql`${playedDate}`,
videoId: sql`${videoId}`,
time: coalesce(time, sql<number>`0`),
percent: coalesce(percent, sql<number>`0`),
playedDate: sql<string>`${playedDate}`,
videoId: sql<string>`${videoId}`,
};
if (!aliased) return ret;
return Object.fromEntries(Object.entries(ret).map(([k, v]) => [k, v.as(k)]));
return Object.fromEntries(
Object.entries(ret).map(([k, v]) => [k, v.as(k)]),
) as unknown as typeof ret;
};
export async function getEntries({
@@ -197,7 +199,7 @@ export async function getEntries({
videos: entryVideosQ.videos,
progress: mapProgress({ aliased: true }),
// specials don't have an `episodeNumber` but a `number` field.
number: episodeNumber,
number: sql<number>`${episodeNumber}`,
// merge `extraKind` into `kind`
kind: sql<EntryKind>`case when ${kind} = 'extra' then ${extraKind} else ${kind}::text end`.as(
+16 -15
View File
@@ -18,6 +18,7 @@ import {
processLanguages,
} from "~/models/utils";
import { desc } from "~/models/utils/descriptions";
import type { WatchlistStatus } from "~/models/watchlist";
import {
entryFilters,
entryProgressQ,
@@ -186,12 +187,12 @@ export const historyH = new Elysia({ tags: ["profiles"] })
.select(
db
.select({
profilePk: sql`${profilePk}`,
profilePk: sql`${profilePk}`.as("profilePk"),
entryPk: entries.pk,
videoPk: videos.pk,
percent: sql`hist.percent`,
time: sql`hist.time`,
playedDate: sql`hist.playedDate`,
percent: sql`hist.percent`.as("percent"),
time: sql`hist.time`.as("time"),
playedDate: sql`hist.playedDate`.as("playedDate"),
})
.from(hist)
.innerJoin(entries, valEqEntries)
@@ -248,9 +249,9 @@ export const historyH = new Elysia({ tags: ["profiles"] })
.select(
db
.select({
profilePk: sql`${profilePk}`,
profilePk: sql`${profilePk}`.as("profilePk"),
showPk: entries.showPk,
status: sql`
status: sql<WatchlistStatus>`
case
when
hist.percent >= 95
@@ -258,35 +259,35 @@ export const historyH = new Elysia({ tags: ["profiles"] })
then 'completed'::watchlist_status
else 'watching'::watchlist_status
end
`,
`.as("status"),
seenCount: sql`
case
when ${entries.kind} = 'movie' then hist.percent
when hist.percent >= 95 then 1
else 0
end
`,
`.as("seen_count"),
nextEntry: sql`
case
when hist.percent >= 95 then ${nextEntryQ.pk}
else ${entries.pk}
end
`,
score: sql`null`,
startedAt: sql`hist.playedDate`,
lastPlayedAt: sql`hist.playedDate`,
`.as("next_entry"),
score: sql`null`.as("score"),
startedAt: sql`hist.playedDate`.as("startedAt"),
lastPlayedAt: sql`hist.playedDate`.as("lastPlayedAt"),
completedAt: sql`
case
when ${nextEntryQ.pk} is null then hist.playedDate
else null
end
`,
`.as("completedAt"),
// see https://github.com/drizzle-team/drizzle-orm/issues/3608
updatedAt: sql`now()`,
updatedAt: sql`now()`.as("updatedAt"),
})
.from(hist)
.leftJoin(entries, valEqEntries)
.crossJoinLateral(nextEntryQ),
.leftJoinLateral(nextEntryQ, sql`true`),
)
.onConflictDoUpdate({
target: [watchlist.profilePk, watchlist.showPk],
+3 -1
View File
@@ -90,6 +90,7 @@ export const nextup = new Elysia({ tags: ["profiles"] })
seasonNumber,
episodeNumber,
extraKind,
kind,
...entryCol
} = getColumns(entries);
@@ -100,9 +101,10 @@ export const nextup = new Elysia({ tags: ["profiles"] })
videos: entryVideosQ.videos,
progress: mapProgress({ aliased: true }),
// specials don't have an `episodeNumber` but a `number` field.
number: episodeNumber,
number: sql<number>`${episodeNumber}`,
// assign more restrained types to make typescript happy.
kind: sql<Entry["kind"]>`${kind}`,
externalId: sql<any>`${externalId}`,
order: sql<number>`${order}`,
seasonNumber: sql<number>`${seasonNumber}`,
+1 -2
View File
@@ -3,7 +3,6 @@ import { Episode, SeedEpisode } from "./episode";
import type { Extra } from "./extra";
import { MovieEntry, SeedMovieEntry } from "./movie-entry";
import { SeedSpecial, Special } from "./special";
import type { UnknownEntry } from "./unknown-entry";
export const Entry = t.Union([Episode, MovieEntry, Special]);
export type Entry = Episode | MovieEntry | Special;
@@ -11,7 +10,7 @@ export type Entry = Episode | MovieEntry | Special;
export const SeedEntry = t.Union([SeedEpisode, SeedMovieEntry, SeedSpecial]);
export type SeedEntry = SeedEpisode | SeedMovieEntry | SeedSpecial;
export type EntryKind = Entry["kind"] | Extra["kind"] | UnknownEntry["kind"];
export type EntryKind = Entry["kind"] | Extra["kind"];
export * from "./episode";
export * from "./movie-entry";
-1
View File
@@ -3,7 +3,6 @@ import type { Video } from "../video";
export const dune1984Video: Video = {
id: "d1a62b87-9cfd-4f9c-9ad7-21f9b7fa6290",
slug: "dune-1984",
path: "/video/Dune_1984/Dune (1984).mkv",
rendering: "ea3a0f8f2f2c5b61a07f61e4e8d9f8e01b2b92bcbb6f5ed1151e1f61619c2c0f",
part: null,
-1
View File
@@ -3,7 +3,6 @@ import type { Video } from "~/models/video";
export const duneVideo: Video = {
id: "c9a0d02e-6b8e-4ac1-b431-45b022ec0708",
slug: "dune",
path: "/video/Dune/Dune (2021).mkv",
rendering: "f1953a4fb58247efb6c15b76468b6a9d13b4155b02094863b1a4f0c3fbb6db58",
part: null,
+4 -3
View File
@@ -4,7 +4,8 @@ import { Movie } from "./movie";
import { Serie } from "./serie";
export const Show = t.Union([
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]),
t.Intersect([t.Object({ kind: t.Literal("movie") }), Movie]),
t.Intersect([t.Object({ kind: t.Literal("serie") }), Serie]),
t.Intersect([t.Object({ kind: t.Literal("collection") }), Collection]),
]);
export type Show = typeof Show.static;
+1
View File
@@ -7,6 +7,7 @@ export const WatchlistStatus = t.UnionEnum([
"dropped",
"planned",
]);
export type WatchlistStatus = typeof WatchlistStatus.static;
export const SerieWatchStatus = t.Object({
status: WatchlistStatus,