From 6450bb3fc548dc9b474baaa9c90aec1501b11957 Mon Sep 17 00:00:00 2001 From: zkldi Date: Sat, 21 Aug 2021 01:52:01 +0100 Subject: [PATCH] Change versions from freeform string to explicit support. --- .../common/eamusement-iidx-csv/types.ts | 4 +++- .../file/solid-state-squad/converter.ts | 6 +++--- .../import-types/ir/fervidex-static/types.ts | 4 ++-- .../import-types/ir/fervidex/types.ts | 4 ++-- server/src/utils/queries/songs.ts | 15 ++++++--------- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/types.ts b/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/types.ts index 3215913ed..02b819c7a 100644 --- a/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/types.ts +++ b/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/types.ts @@ -1,3 +1,5 @@ +import { GPTSupportedVersions } from "tachi-common"; + export interface EamusementScoreData { difficulty: "BEGINNER" | "NORMAL" | "HYPER" | "ANOTHER" | "LEGGENDARIA"; lamp: string; @@ -28,7 +30,7 @@ export type RawIIDXEamusementCSVData = { export interface IIDXEamusementCSVContext { playtype: "SP" | "DP"; - importVersion: string; + importVersion: GPTSupportedVersions["iidx:SP" | "iidx:DP"]; hasBeginnerAndLegg: boolean; service: string; } diff --git a/server/src/lib/score-import/import-types/file/solid-state-squad/converter.ts b/server/src/lib/score-import/import-types/file/solid-state-squad/converter.ts index 484a362a3..cc475f1c4 100644 --- a/server/src/lib/score-import/import-types/file/solid-state-squad/converter.ts +++ b/server/src/lib/score-import/import-types/file/solid-state-squad/converter.ts @@ -72,7 +72,7 @@ export function ResolveS3Lamp(data: S3Score, logger: KtLogger): Lamps["iidx:SP" throw new InvalidScoreFailure(`Invalid cleartype of ${data.cleartype}.`); } -const S3_VERSION_CONV: Record = { +const S3_VERSION_CONV = { "3rd": "3-cs", "4th": "4-cs", "5th": "5-cs", @@ -89,14 +89,14 @@ const S3_VERSION_CONV: Record = { emp: "16-cs", pb: "16-cs", us: "bmus", -}; +} as const; function ConvertVersion(joinedStyles: string) { const styles = joinedStyles.split(","); const style = styles[styles.length - 1]; - const convertedStyle = S3_VERSION_CONV[style]; + const convertedStyle = S3_VERSION_CONV[style as keyof typeof S3_VERSION_CONV]; if (!convertedStyle) { throw new InvalidScoreFailure(`Song has invalid style ${style}.`); diff --git a/server/src/lib/score-import/import-types/ir/fervidex-static/types.ts b/server/src/lib/score-import/import-types/ir/fervidex-static/types.ts index 5bebae409..39988d369 100644 --- a/server/src/lib/score-import/import-types/ir/fervidex-static/types.ts +++ b/server/src/lib/score-import/import-types/ir/fervidex-static/types.ts @@ -1,4 +1,4 @@ -import { integer } from "tachi-common"; +import { GPTSupportedVersions, integer } from "tachi-common"; export interface FervidexStaticScore { clear_type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; @@ -9,5 +9,5 @@ export interface FervidexStaticScore { } export interface FervidexStaticContext { - version: string; + version: GPTSupportedVersions["iidx:SP" | "iidx:DP"]; } diff --git a/server/src/lib/score-import/import-types/ir/fervidex/types.ts b/server/src/lib/score-import/import-types/ir/fervidex/types.ts index 6149b309f..867186c96 100644 --- a/server/src/lib/score-import/import-types/ir/fervidex/types.ts +++ b/server/src/lib/score-import/import-types/ir/fervidex/types.ts @@ -1,4 +1,4 @@ -import { integer } from "tachi-common"; +import { GPTSupportedVersions, integer } from "tachi-common"; export interface FervidexScore { chart: `${"sp" | "dp"}${"b" | "n" | "h" | "a" | "l"}`; @@ -58,5 +58,5 @@ export interface FervidexScore { } export interface FervidexContext { - version: string; + version: GPTSupportedVersions["iidx:SP" | "iidx:DP"]; } diff --git a/server/src/utils/queries/songs.ts b/server/src/utils/queries/songs.ts index b44b2ac8d..3fe41f070 100644 --- a/server/src/utils/queries/songs.ts +++ b/server/src/utils/queries/songs.ts @@ -1,4 +1,4 @@ -import { Game, AnySongDocument, integer } from "tachi-common"; +import { Game, SongDocument, integer } from "tachi-common"; import { FindOneResult } from "monk"; import db from "external/mongo/db"; import { KtLogger } from "lib/logger/logger"; @@ -11,12 +11,9 @@ import { EscapeStringRegexp } from "../misc"; * rather difficult. Prefer other functions! * @param game - The game to search upon. * @param title - The song title to match. - * @returns AnySongDocument + * @returns SongDocument */ -export function FindSongOnTitle( - game: Game, - title: string -): Promise> { +export function FindSongOnTitle(game: Game, title: string): Promise> { // @optimisable: Performance should be tested here by having a utility field for all-titles. return db.songs[game].findOne({ $or: [ @@ -37,7 +34,7 @@ export function FindSongOnTitle( export function FindSongOnTitleInsensitive( game: Game, title: string -): Promise> { +): Promise> { // @optimisable: Performance should be tested here by having a utility field for all-titles. const regex = new RegExp(`^${EscapeStringRegexp(title)}$`, "iu"); @@ -58,9 +55,9 @@ export function FindSongOnTitleInsensitive( * also be the in-game-ID. * @param game - The game to search upon. * @param songID - The song ID to match. - * @returns AnySongDocument + * @returns SongDocument */ -export function FindSongOnID(game: Game, songID: integer): Promise> { +export function FindSongOnID(game: Game, songID: integer): Promise> { return db.songs[game].findOne({ id: songID, });