Format code

This commit is contained in:
Zoe Roux 2025-01-18 16:26:34 +01:00
parent 02d1197f6b
commit a8fb84daf0
29 changed files with 62 additions and 69 deletions

View File

@ -6,8 +6,8 @@ export const base = new Elysia({ name: "base" })
if (code === "VALIDATION") { if (code === "VALIDATION") {
const details = JSON.parse(error.message); const details = JSON.parse(error.message);
if (details.code === "KError") { if (details.code === "KError") {
delete details.code; const { code, ...ret } = details;
return details; return ret;
} }
return { return {
status: error.status, status: error.status,

View File

@ -1,15 +1,13 @@
import { and, eq, exists, SQL, sql } from "drizzle-orm"; import { type SQL, and, eq, exists, sql } from "drizzle-orm";
import { Elysia, t } from "elysia"; import { Elysia, t } from "elysia";
import { KError } from "~/models/error";
import { comment } from "~/utils";
import { db } from "../db";
import { import {
entries, entries,
entryVideoJointure as entryVideoJoint, entryVideoJointure as entryVideoJoint,
shows,
showTranslations, showTranslations,
shows,
} from "~/db/schema"; } from "~/db/schema";
import { getColumns, sqlarr } from "~/db/schema/utils"; import { getColumns, sqlarr } from "~/db/schema/utils";
import { KError } from "~/models/error";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { import {
FullMovie, FullMovie,
@ -19,16 +17,18 @@ import {
} from "~/models/movie"; } from "~/models/movie";
import { import {
Filter, Filter,
type Image,
Sort,
type FilterDef, type FilterDef,
Genre, Genre,
type Image,
Page,
Sort,
createPage,
isUuid, isUuid,
keysetPaginate, keysetPaginate,
Page,
processLanguages, processLanguages,
createPage,
} from "~/models/utils"; } from "~/models/utils";
import { comment } from "~/utils";
import { db } from "../db";
const movieFilters: FilterDef = { const movieFilters: FilterDef = {
genres: { genres: {

View File

@ -1,10 +1,10 @@
import Elysia from "elysia";
import { Value } from "@sinclair/typebox/value"; import { Value } from "@sinclair/typebox/value";
import Elysia from "elysia";
import { KError } from "~/models/error";
import { Movie, SeedMovie } from "~/models/movie"; import { Movie, SeedMovie } from "~/models/movie";
import { seedMovie, SeedMovieResponse } from "./movies";
import { Resource } from "~/models/utils"; import { Resource } from "~/models/utils";
import { comment } from "~/utils"; import { comment } from "~/utils";
import { KError } from "~/models/error"; import { SeedMovieResponse, seedMovie } from "./movies";
export const seed = new Elysia() export const seed = new Elysia()
.model({ .model({

View File

@ -1,19 +1,19 @@
import { inArray, sql, eq } from "drizzle-orm"; import { eq, inArray, sql } from "drizzle-orm";
import { t } from "elysia"; import { t } from "elysia";
import { db } from "~/db"; import { db } from "~/db";
import { import {
entries, entries,
entryTranslations, entryTranslations,
entryVideoJointure as evj, entryVideoJointure as evj,
shows,
showTranslations, showTranslations,
shows,
videos, videos,
} from "~/db/schema"; } from "~/db/schema";
import { conflictUpdateAllExcept } from "~/db/schema/utils"; import { conflictUpdateAllExcept } from "~/db/schema/utils";
import { KErrorT } from "~/models/error";
import type { SeedMovie } from "~/models/movie"; import type { SeedMovie } from "~/models/movie";
import { processOptImage } from "./images"; import { processOptImage } from "./images";
import { guessNextRefresh } from "./refresh"; import { guessNextRefresh } from "./refresh";
import { KErrorT } from "~/models/error";
type Show = typeof shows.$inferInsert; type Show = typeof shows.$inferInsert;
type ShowTrans = typeof showTranslations.$inferInsert; type ShowTrans = typeof showTranslations.$inferInsert;

View File

@ -1,9 +1,9 @@
import { Elysia, t } from "elysia"; import { Elysia, t } from "elysia";
import { SeedVideo, Video } from "~/models/video";
import { db } from "~/db"; import { db } from "~/db";
import { videos as videosT } from "~/db/schema"; import { videos as videosT } from "~/db/schema";
import { comment } from "~/utils";
import { bubbleVideo } from "~/models/examples"; import { bubbleVideo } from "~/models/examples";
import { SeedVideo, Video } from "~/models/video";
import { comment } from "~/utils";
const CreatedVideo = t.Object({ const CreatedVideo = t.Object({
id: t.String({ format: "uuid" }), id: t.String({ format: "uuid" }),

View File

@ -12,8 +12,8 @@ import {
uuid, uuid,
varchar, varchar,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { image, language, schema } from "./utils";
import { shows } from "./shows"; import { shows } from "./shows";
import { image, language, schema } from "./utils";
export const entryType = schema.enum("entry_type", [ export const entryType = schema.enum("entry_type", [
"unknown", "unknown",

View File

@ -9,8 +9,8 @@ import {
uuid, uuid,
varchar, varchar,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { image, language, schema } from "./utils";
import { shows } from "./shows"; import { shows } from "./shows";
import { image, language, schema } from "./utils";
export const season_extid = () => export const season_extid = () =>
jsonb() jsonb()

View File

@ -1,14 +1,15 @@
import { import {
is,
type ColumnsSelection, type ColumnsSelection,
type SQL,
type Subquery, type Subquery,
Table, Table,
View, View,
ViewBaseConfig, ViewBaseConfig,
getTableColumns, getTableColumns,
is,
sql, sql,
SQL,
} from "drizzle-orm"; } from "drizzle-orm";
import type { CasingCache } from "drizzle-orm/casing";
import type { AnyMySqlSelect } from "drizzle-orm/mysql-core"; import type { AnyMySqlSelect } from "drizzle-orm/mysql-core";
import { import {
type AnyPgSelect, type AnyPgSelect,
@ -19,7 +20,6 @@ import {
import type { AnySQLiteSelect } from "drizzle-orm/sqlite-core"; import type { AnySQLiteSelect } from "drizzle-orm/sqlite-core";
import type { WithSubquery } from "drizzle-orm/subquery"; import type { WithSubquery } from "drizzle-orm/subquery";
import { db } from ".."; import { db } from "..";
import type { CasingCache } from "drizzle-orm/casing";
export const schema = pgSchema("kyoo"); export const schema = pgSchema("kyoo");

View File

@ -3,14 +3,14 @@ import {
check, check,
integer, integer,
jsonb, jsonb,
primaryKey,
text, text,
timestamp, timestamp,
uuid, uuid,
varchar, varchar,
primaryKey,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { schema } from "./utils";
import { entries } from "./entries"; import { entries } from "./entries";
import { schema } from "./utils";
export const videos = schema.table( export const videos = schema.table(
"videos", "videos",

View File

@ -2,6 +2,7 @@ import jwt from "@elysiajs/jwt";
import { swagger } from "@elysiajs/swagger"; import { swagger } from "@elysiajs/swagger";
import { migrate } from "drizzle-orm/node-postgres/migrator"; import { migrate } from "drizzle-orm/node-postgres/migrator";
import { Elysia } from "elysia"; import { Elysia } from "elysia";
import { base } from "./base";
import { entries } from "./controllers/entries"; import { entries } from "./controllers/entries";
import { movies } from "./controllers/movies"; import { movies } from "./controllers/movies";
import { seasons } from "./controllers/seasons"; import { seasons } from "./controllers/seasons";
@ -11,7 +12,6 @@ import { videos } from "./controllers/videos";
import { db } from "./db"; import { db } from "./db";
import { Image } from "./models/utils"; import { Image } from "./models/utils";
import { comment } from "./utils"; import { comment } from "./utils";
import { base } from "./base";
await migrate(db, { migrationsSchema: "kyoo", migrationsFolder: "./drizzle" }); await migrate(db, { migrationsSchema: "kyoo", migrationsFolder: "./drizzle" });

View File

@ -17,7 +17,6 @@ export const EntryTranslation = t.Object({
description: t.Nullable(t.String()), description: t.Nullable(t.String()),
}); });
// export const SeedEntry = t.Intersect([ // export const SeedEntry = t.Intersect([
// Entry, // Entry,
// t.Object({ videos: t.Optional(t.Array(Video)) }), // t.Object({ videos: t.Optional(t.Array(Video)) }),

View File

@ -1,7 +1,7 @@
import { t } from "elysia"; import { t } from "elysia";
import { BaseEntry, EntryTranslation } from "./base-entry";
import { EpisodeId } from "../utils/external-id"; import { EpisodeId } from "../utils/external-id";
import { Resource } from "../utils/resource"; import { Resource } from "../utils/resource";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseEpisode = t.Intersect([ export const BaseEpisode = t.Intersect([
BaseEntry, BaseEntry,

View File

@ -1,8 +1,8 @@
import { t } from "elysia"; import { t } from "elysia";
import { BaseEntry, EntryTranslation } from "./base-entry";
import { EpisodeId } from "../utils/external-id";
import { comment } from "../../utils"; import { comment } from "../../utils";
import { EpisodeId } from "../utils/external-id";
import { Resource } from "../utils/resource"; import { Resource } from "../utils/resource";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const ExtraType = t.UnionEnum([ export const ExtraType = t.UnionEnum([
"other", "other",
@ -33,5 +33,3 @@ 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; export type Extra = typeof Extra.static;

View File

@ -1,9 +1,9 @@
import type { TSchema } from "elysia";
import { KindGuard } from "@sinclair/typebox"; import { KindGuard } from "@sinclair/typebox";
import type { TSchema } from "elysia";
export const registerExamples = <T extends TSchema>( export const registerExamples = <T extends TSchema>(
schema: T, schema: T,
...examples: (Partial<T["static"] >| undefined)[] ...examples: (Partial<T["static"]> | undefined)[]
) => { ) => {
if (KindGuard.IsUnion(schema)) { if (KindGuard.IsUnion(schema)) {
for (const union of schema.anyOf) { for (const union of schema.anyOf) {

View File

@ -1,4 +1,6 @@
import { t } from "elysia"; import { t } from "elysia";
import { bubble, registerExamples } from "./examples";
import { bubbleImages } from "./examples/bubble";
import { import {
ExternalId, ExternalId,
Genre, Genre,
@ -7,8 +9,6 @@ import {
SeedImage, SeedImage,
TranslationRecord, TranslationRecord,
} from "./utils"; } from "./utils";
import { bubble, registerExamples } from "./examples";
import { bubbleImages } from "./examples/bubble";
import { Video } from "./video"; import { Video } from "./video";
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]); export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);

View File

@ -1,8 +1,8 @@
import { t } from "elysia"; import { t } from "elysia";
import { Image } from "./utils/image";
import { SeasonId } from "./utils/external-id"; import { SeasonId } from "./utils/external-id";
import { Resource } from "./utils/resource"; import { Image } from "./utils/image";
import { Language } from "./utils/language"; import { Language } from "./utils/language";
import { Resource } from "./utils/resource";
export const BaseSeason = t.Object({ export const BaseSeason = t.Object({
seasonNumber: t.Number({ minimum: 1 }), seasonNumber: t.Number({ minimum: 1 }),

View File

@ -1,11 +1,11 @@
import { t } from "elysia"; import { t } from "elysia";
import { madeInAbyss, registerExamples } from "./examples";
import { SeedSeason } from "./season";
import { ExternalId } from "./utils/external-id";
import { Genre } from "./utils/genres"; import { Genre } from "./utils/genres";
import { Image } from "./utils/image"; import { Image } from "./utils/image";
import { ExternalId } from "./utils/external-id";
import { madeInAbyss, registerExamples } from "./examples";
import { Resource } from "./utils/resource";
import { Language } from "./utils/language"; import { Language } from "./utils/language";
import { SeedSeason } from "./season"; import { Resource } from "./utils/resource";
export const SerieStatus = t.UnionEnum([ export const SerieStatus = t.UnionEnum([
"unknown", "unknown",

View File

@ -1,9 +1,9 @@
import type { Column } from "drizzle-orm"; import type { Column } from "drizzle-orm";
import { t } from "elysia"; import { t } from "elysia";
import { KErrorT } from "~/models/error";
import { comment } from "~/utils"; import { comment } from "~/utils";
import { expression } from "./parser"; import { expression } from "./parser";
import { toDrizzle } from "./to-sql"; import { toDrizzle } from "./to-sql";
import { KErrorT } from "~/models/error";
export type FilterDef = { export type FilterDef = {
[key: string]: [key: string]:

View File

@ -1,26 +1,26 @@
import { import {
type Parjser,
anyStringOf, anyStringOf,
digit, digit,
float, float,
int, int,
letter, letter,
noCharOf, noCharOf,
type Parjser,
string, string,
} from "parjs"; } from "parjs";
import { import {
between,
exactly, exactly,
later,
many, many,
many1, many1,
map, map,
or, or,
qthen,
recover,
stringify, stringify,
then, then,
thenq, thenq,
qthen,
later,
between,
recover,
} from "parjs/combinators"; } from "parjs/combinators";
export type Property = string; export type Property = string;

View File

@ -1,4 +1,5 @@
import { import {
type SQL,
and, and,
eq, eq,
gt, gt,
@ -8,13 +9,12 @@ import {
ne, ne,
not, not,
or, or,
type SQL,
sql, sql,
} from "drizzle-orm"; } from "drizzle-orm";
import { KErrorT } from "~/models/error";
import { comment } from "~/utils"; import { comment } from "~/utils";
import type { FilterDef } from "./index"; import type { FilterDef } from "./index";
import type { Expression, Operator } from "./parser"; import type { Expression, Operator } from "./parser";
import { KErrorT } from "~/models/error";
const opMap: Record<Operator, typeof eq> = { const opMap: Record<Operator, typeof eq> = {
eq: eq, eq: eq,

View File

@ -1,5 +1,5 @@
import { type Column, and, eq, gt, isNull, lt, or, sql } from "drizzle-orm";
import type { NonEmptyArray, Sort } from "./sort"; import type { NonEmptyArray, Sort } from "./sort";
import { eq, or, type Column, and, gt, lt, isNull, sql } from "drizzle-orm";
type Table<Name extends string> = Record<Name, Column>; type Table<Name extends string> = Record<Name, Column>;

View File

@ -1,8 +1,8 @@
import { import {
FormatRegistry, FormatRegistry,
StaticDecode, type StaticDecode,
TSchema, type TSchema,
TString, type TString,
} from "@sinclair/typebox"; } from "@sinclair/typebox";
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../../utils"; import { comment } from "../../utils";

View File

@ -1,7 +1,7 @@
import type { ObjectOptions } from "@sinclair/typebox"; import type { ObjectOptions } from "@sinclair/typebox";
import { t, type TSchema } from "elysia"; import { type TSchema, t } from "elysia";
import type { Sort } from "./sort";
import { generateAfter } from "./keyset-paginate"; import { generateAfter } from "./keyset-paginate";
import type { Sort } from "./sort";
export const Page = <T extends TSchema>(schema: T, options?: ObjectOptions) => export const Page = <T extends TSchema>(schema: T, options?: ObjectOptions) =>
t.Object( t.Object(

View File

@ -1,6 +1,6 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../utils"; import { comment } from "../utils";
import { registerExamples, bubbleVideo } from "./examples"; import { bubbleVideo, registerExamples } from "./examples";
export const Video = t.Object({ export const Video = t.Object({
id: t.String({ format: "uuid" }), id: t.String({ format: "uuid" }),

View File

@ -1,12 +1,12 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import { eq } from "drizzle-orm";
import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies"; import { seedMovie } from "~/controllers/seed/movies";
import { db } from "~/db"; import { db } from "~/db";
import { shows } from "~/db/schema"; import { shows } from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { dune1984 } from "~/models/examples/dune-1984"; import { dune1984 } from "~/models/examples/dune-1984";
import { dune } from "~/models/examples/dune-2021"; import { dune } from "~/models/examples/dune-2021";
import { eq } from "drizzle-orm";
import { expectStatus } from "tests/utils";
import { createMovie, getMovies, movieApp } from "./movies-helper"; import { createMovie, getMovies, movieApp } from "./movies-helper";
beforeAll(async () => { beforeAll(async () => {

View File

@ -6,9 +6,9 @@ import { shows } from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { dune1984 } from "~/models/examples/dune-1984"; import { dune1984 } from "~/models/examples/dune-1984";
import { dune } from "~/models/examples/dune-2021"; import { dune } from "~/models/examples/dune-2021";
import { getMovie, getMovies, movieApp } from "./movies-helper";
import type { Movie } from "~/models/movie"; import type { Movie } from "~/models/movie";
import { isUuid } from "~/models/utils"; import { isUuid } from "~/models/utils";
import { getMovie, getMovies, movieApp } from "./movies-helper";
beforeAll(async () => { beforeAll(async () => {
await db.delete(shows); await db.delete(shows);

View File

@ -1,8 +1,8 @@
import { beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies"; import { seedMovie } from "~/controllers/seed/movies";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { getMovie } from "./movies-helper"; import { getMovie } from "./movies-helper";
import { expectStatus } from "tests/utils";
let bubbleId = ""; let bubbleId = "";

View File

@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, it, test } from "bun:test";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { db } from "~/db"; import { db } from "~/db";
import { shows, showTranslations, videos } from "~/db/schema"; import { showTranslations, shows, videos } from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { dune, duneVideo } from "~/models/examples/dune-2021"; import { dune, duneVideo } from "~/models/examples/dune-2021";
import { createMovie } from "./movies-helper"; import { createMovie } from "./movies-helper";

View File

@ -3,9 +3,7 @@
"target": "ES2021", "target": "ES2021",
"module": "ES2022", "module": "ES2022",
"moduleResolution": "node", "moduleResolution": "node",
"types": [ "types": ["bun-types"],
"bun-types"
],
"esModuleInterop": true, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strict": true, "strict": true,
@ -13,9 +11,7 @@
"noErrorTruncation": true, "noErrorTruncation": true,
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"~/*": [ "~/*": ["./src/*"]
"./src/*"
]
} }
} }
} }