Skip to content

Commit 1b6ae95

Browse files
committed
Add New Fields
1 parent 3100e85 commit 1b6ae95

13 files changed

Lines changed: 225 additions & 10 deletions

File tree

docs/openapi.yaml

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ $defs:
115115
minimum: 0
116116
maximum: 50000000
117117
example: 1337
118+
animenewsnetwork:
119+
oneOf:
120+
- type: "null"
121+
- type: integer
122+
minimum: 0
123+
maximum: 50000000
124+
example: 1337
118125
notify-moe:
119126
oneOf:
120127
- type: "null"
@@ -129,20 +136,55 @@ $defs:
129136
minimum: 0
130137
maximum: 50000000
131138
example: 1337
139+
themoviedb-season:
140+
oneOf:
141+
- type: "null"
142+
- type: integer
143+
minimum: 0
144+
maximum: 50000000
145+
example: 1
132146
thetvdb:
133147
oneOf:
134148
- type: "null"
135149
- type: integer
136150
minimum: 0
137151
maximum: 50000000
138152
example: 1337
153+
thetvdb-season:
154+
oneOf:
155+
- type: "null"
156+
- type: integer
157+
minimum: 0
158+
maximum: 50000000
159+
example: 1
139160
myanimelist:
140161
oneOf:
141162
- type: "null"
142163
- type: integer
143164
minimum: 0
144165
maximum: 50000000
145166
example: 1337
167+
simkl:
168+
oneOf:
169+
- type: "null"
170+
- type: integer
171+
minimum: 0
172+
maximum: 50000000
173+
example: 1337
174+
animecountdown:
175+
oneOf:
176+
- type: "null"
177+
- type: integer
178+
minimum: 0
179+
maximum: 50000000
180+
example: 1337
181+
media:
182+
oneOf:
183+
- type: "null"
184+
- type: string
185+
minLength: 0
186+
maxLength: 10
187+
example: TV
146188

147189
nullable_relation:
148190
oneOf:
@@ -153,15 +195,20 @@ $defs:
153195
example:
154196
anidb: 1337
155197
anilist: 1337
156-
anime-planet: spriggan
198+
anime-planet: dororon-enma-kun
157199
anisearch: null
158200
imdb: tt0164917
159201
kitsu: null
160202
livechart: null
161203
notify-moe: "-cQb5Fmmg"
162204
themoviedb: null
205+
themoviedb-season: 1
163206
thetvdb: null
207+
thetvdb-season: 1
164208
myanimelist: null
209+
animecountdown: null
210+
animenewsnetwork: null
211+
media: TV
165212
oneOf:
166213
- $ref: "#/$defs/nullable_relation"
167214
- type: array
@@ -305,6 +352,8 @@ paths:
305352
- anilist
306353
- anidb
307354
- anime-planet
355+
- animecountdown
356+
- animenewsnetwork
308357
- anisearch
309358
- kitsu
310359
- livechart
@@ -410,6 +459,18 @@ paths:
410459
- type: integer
411460
minimum: 0
412461
maximum: 50000000
462+
animenewsnetwork:
463+
oneOf:
464+
- type: "null"
465+
- type: integer
466+
minimum: 0
467+
maximum: 50000000
468+
animecountdown:
469+
oneOf:
470+
- type: "null"
471+
- type: integer
472+
minimum: 0
473+
maximum: 50000000
413474
- type: array
414475
minItems: 1
415476
maxItems: 100
@@ -466,6 +527,18 @@ paths:
466527
- type: integer
467528
minimum: 0
468529
maximum: 50000000
530+
animenewsnetwork:
531+
oneOf:
532+
- type: "null"
533+
- type: integer
534+
minimum: 0
535+
maximum: 50000000
536+
animecountdown:
537+
oneOf:
538+
- type: "null"
539+
- type: integer
540+
minimum: 0
541+
maximum: 50000000
469542

470543
responses:
471544
"200":

src/db/db.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,27 @@ export const Source = {
1515
IMDB: "imdb",
1616
Kitsu: "kitsu",
1717
LiveChart: "livechart",
18+
AnimeNewsNetwork: "animenewsnetwork",
1819
NotifyMoe: "notify-moe",
1920
TheMovieDB: "themoviedb",
21+
TheMovieDBSeason: "themoviedb-season",
2022
TheTVDB: "thetvdb",
23+
TheTVDBSeason: "thetvdb-season",
2124
MAL: "myanimelist",
25+
Simkl: "simkl",
26+
AnimeCountdown: "animecountdown",
27+
MediaType: "media",
2228
} as const
2329
export type SourceValue = (typeof Source)[keyof typeof Source]
30+
export const NonUniqueFields = [
31+
Source.IMDB,
32+
Source.TheMovieDB,
33+
Source.TheMovieDBSeason,
34+
Source.TheTVDB,
35+
Source.TheTVDBSeason,
36+
Source.Simkl,
37+
Source.MediaType,
38+
]
2439

2540
export type Relation = {
2641
[Source.AniDB]?: number
@@ -30,10 +45,16 @@ export type Relation = {
3045
[Source.IMDB]?: `tt${string}`
3146
[Source.Kitsu]?: number
3247
[Source.LiveChart]?: number
48+
[Source.AnimeNewsNetwork]?: number
3349
[Source.NotifyMoe]?: string
3450
[Source.TheMovieDB]?: number
3551
[Source.TheTVDB]?: number
3652
[Source.MAL]?: number
53+
[Source.TheTVDBSeason]?: number
54+
[Source.TheMovieDBSeason]?: number
55+
[Source.Simkl]?: number
56+
[Source.AnimeCountdown]?: number
57+
[Source.MediaType]?: string
3758
}
3859

3960
export type OldRelation = Pick<Relation, "anidb" | "anilist" | "myanimelist" | "kitsu">

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { serve } from "h3"
22

33
import { createApp } from "./app.ts"
4-
import { config } from "./config.ts"
4+
import { config, Environment } from "./config.ts"
55
import { migrator } from "./db/db.ts"
66
import { updateRelations } from "./update.ts"
77

@@ -11,7 +11,7 @@ const { NODE_ENV, PORT } = config
1111

1212
const runUpdateScript = async () => updateRelations()
1313

14-
if (NODE_ENV === "production") {
14+
if (NODE_ENV === Environment.Prod) {
1515
void runUpdateScript()
1616

1717
// eslint-disable-next-line ts/no-misused-promises
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { type Kysely, sql } from "kysely"
2+
3+
export async function up(db: Kysely<any>): Promise<void> {
4+
await sql`PRAGMA journal_mode=WAL`.execute(db)
5+
6+
await db.schema.dropTable("relations").ifExists().execute()
7+
8+
await db.schema
9+
.createTable("relations")
10+
.ifNotExists()
11+
12+
// Original columns
13+
.addColumn("anidb", "integer", (col) => col.unique())
14+
.addColumn("anilist", "integer", (col) => col.unique())
15+
.addColumn("myanimelist", "integer", (col) => col.unique())
16+
.addColumn("kitsu", "integer", (col) => col.unique())
17+
18+
// v2 columns
19+
.addColumn("anime-planet", "text", (col) => col.unique())
20+
.addColumn("anisearch", "integer", (col) => col.unique())
21+
.addColumn("imdb", "text")
22+
.addColumn("livechart", "integer", (col) => col.unique())
23+
.addColumn("notify-moe", "text", (col) => col.unique())
24+
.addColumn("themoviedb", "integer")
25+
.addColumn("thetvdb", "integer")
26+
27+
// New Columns
28+
.addColumn("themoviedb-season", "integer")
29+
.addColumn("thetvdb-season", "integer")
30+
.addColumn("animenewsnetwork", "integer", (col) => col.unique())
31+
.addColumn("animecountdown", "integer", (col) => col.unique())
32+
.addColumn("simkl", "integer")
33+
.addColumn("media", "text")
34+
.execute()
35+
}

src/routes/v2/ids/handler.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ const createRelations = async <N extends number>(
1616
imdb: `tt${id++}`,
1717
kitsu: id++,
1818
livechart: id++,
19+
animenewsnetwork: id++,
1920
"notify-moe": `${id++}`,
2021
themoviedb: id++,
22+
"themoviedb-season": id++,
2123
thetvdb: id++,
24+
"thetvdb-season": id++,
2225
myanimelist: id++,
26+
simkl: id++,
27+
animecountdown: id++,
28+
media: `${id++}`,
2329
}))
2430

2531
// Insert each relation
@@ -80,10 +86,16 @@ describe("query params", () => {
8086
imdb: null!,
8187
kitsu: null!,
8288
livechart: null!,
89+
animenewsnetwork: null!,
8390
"notify-moe": null!,
8491
themoviedb: null!,
92+
"themoviedb-season": null!,
8593
thetvdb: null!,
94+
"thetvdb-season": null!,
8695
myanimelist: null!,
96+
simkl: null!,
97+
animecountdown: null!,
98+
media: null!,
8799
}
88100
await db.insertInto("relations").values(relation).execute()
89101

@@ -165,10 +177,16 @@ describe("json body", () => {
165177
imdb: null!,
166178
kitsu: null!,
167179
livechart: null!,
180+
animenewsnetwork: null!,
168181
"notify-moe": null!,
169182
themoviedb: null!,
183+
"themoviedb-season": null!,
170184
thetvdb: null!,
185+
"thetvdb-season": null!,
171186
myanimelist: null!,
187+
simkl: null!,
188+
animecountdown: null!,
189+
media: null!,
172190
}
173191
await db.insertInto("relations").values(relation).execute()
174192

src/routes/v2/ids/schemas/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as v from "valibot"
44
export const numberIdSourceSchema = v.picklist([
55
"anilist",
66
"anidb",
7+
"animecountdown",
8+
"animenewsnetwork",
79
"anisearch",
810
"kitsu",
911
"livechart",

src/routes/v2/ids/schemas/json-body.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ const okCases = [
2222
anisearch: 1337,
2323
kitsu: 1337,
2424
livechart: 1337,
25+
animenewsnetwork: 1337,
2526
"notify-moe": "1337",
2627
myanimelist: 1337,
28+
animecountdown: 1337,
2729
},
2830
true,
2931
],
@@ -47,6 +49,7 @@ const badCases = [
4749
[{ imdb: 1337 }, false],
4850
[{ themoviedb: 1337 }, false],
4951
[{ thetvdb: 1337 }, false],
52+
[{ simkl: 1337 }, false],
5053
] satisfies Cases
5154

5255
const mapToSingularArrayInput = (cases: Cases): Cases =>

src/routes/v2/ids/schemas/json-body.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const singularItemInputSchema = v.pipe(
1111
anidb: numberIdSchema,
1212
anilist: numberIdSchema,
1313
"anime-planet": stringIdSchema,
14+
animecountdown: numberIdSchema,
15+
animenewsnetwork: numberIdSchema,
1416
anisearch: numberIdSchema,
1517
kitsu: numberIdSchema,
1618
livechart: numberIdSchema,

src/routes/v2/include.test-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ export const testIncludeQueryParam = (
7474
imdb: null,
7575
kitsu: null,
7676
livechart: null,
77+
animenewsnetwork: null,
7778
"notify-moe": null,
7879
themoviedb: null,
80+
"themoviedb-season": null,
7981
thetvdb: null,
82+
"thetvdb-season": null,
8083
myanimelist: null,
84+
simkl: null,
85+
animecountdown: null,
86+
media: null,
8187
}
8288
expectedResult[source] = prefixify(source, 1337) as never
8389

src/routes/v2/include.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const includeSchema = v.object({
88
v.string(),
99
v.regex(/^[\-a-z,]+$/, "Invalid `include` query"),
1010
v.minLength(1),
11-
v.maxLength(100),
11+
v.maxLength(200),
1212
),
1313
),
1414
})

0 commit comments

Comments
 (0)