update songdocument typedefs

This commit is contained in:
zkldi
2021-04-22 15:00:06 +01:00
parent aa362bcc93
commit 7a6daed3aa
9 changed files with 67 additions and 62 deletions
-1
View File
@@ -71,7 +71,6 @@ t.test("#ReinstateInvite", (t) => {
let response = await ReinstateInvite(inviteDoc);
// @ts-expect-error Monks' types are WRONG. this is nModified, not modifiedCount
t.equal(response.nModified, 1, "Should modify one document");
let invite2 = await db.invites.findOne({
+38 -37
View File
@@ -8,6 +8,7 @@ import {
IIDXBPIData,
IIDXEamusementScoreDocument,
ImportDocument,
SongDocument,
InviteCodeDocument,
MilestoneDocument,
NotificationDocument,
@@ -16,7 +17,8 @@ import {
PublicAPIKeyDocument,
ScoreDocument,
SessionDocument,
SongDocument,
AnySongDocument,
AnyChartDocument,
UserGoalDocument,
UserMilestoneDocument,
} from "kamaitachi-common";
@@ -53,7 +55,39 @@ export async function CloseMongoConnection() {
await monkDB.close();
}
const StaticCollections = {
const songs = {
bms: monkDB.get<AnySongDocument>(`songs-bms`),
chunithm: monkDB.get<AnySongDocument>(`songs-chunithm`),
ddr: monkDB.get<AnySongDocument>(`songs-ddr`),
gitadora: monkDB.get<AnySongDocument>(`songs-gitadora`),
iidx: monkDB.get<AnySongDocument>(`songs-iidx`),
jubeat: monkDB.get<AnySongDocument>(`songs-jubeat`),
maimai: monkDB.get<AnySongDocument>(`songs-maimai`),
museca: monkDB.get<AnySongDocument>(`songs-museca`),
popn: monkDB.get<AnySongDocument>(`songs-popn`),
sdvx: monkDB.get<AnySongDocument>(`songs-sdvx`),
usc: monkDB.get<AnySongDocument>(`songs-usc`),
};
const charts = {
bms: monkDB.get<AnyChartDocument>(`charts-bms`),
chunithm: monkDB.get<AnyChartDocument>(`charts-chunithm`),
ddr: monkDB.get<AnyChartDocument>(`charts-ddr`),
gitadora: monkDB.get<AnyChartDocument>(`charts-gitadora`),
iidx: monkDB.get<AnyChartDocument>(`charts-iidx`),
jubeat: monkDB.get<AnyChartDocument>(`charts-jubeat`),
maimai: monkDB.get<AnyChartDocument>(`charts-maimai`),
museca: monkDB.get<AnyChartDocument>(`charts-museca`),
popn: monkDB.get<AnyChartDocument>(`charts-popn`),
sdvx: monkDB.get<AnyChartDocument>(`charts-sdvx`),
usc: monkDB.get<AnyChartDocument>(`charts-usc`),
};
const db = {
// i have to handwrite this out for TS... :(
// dont worry, it was all macro'd
songs,
charts,
scores: monkDB.get<ScoreDocument>("scores"),
folders: monkDB.get<FolderDocument>("folders"),
goals: monkDB.get<GoalDocument>("goals"),
@@ -71,41 +105,8 @@ const StaticCollections = {
"iidx-eam-scores": monkDB.get<IIDXEamusementScoreDocument>("iidx-eam-scores"),
};
type GameCollections = Record<Game, ICollection>;
interface GCPartial {
songs: Partial<GameCollections>;
charts: Partial<GameCollections>;
export function GetGameChartCollection(game: Game) {
return db.charts[game];
}
interface GameCollectionFull {
songs: GameCollections;
charts: GameCollections;
}
let GameCollectionPartial: GCPartial = {
songs: {},
// i have to handwrite this out for TS... :(
charts: {
bms: monkDB.get<`bms:${Playtypes["bms"]}`>(`charts-bms`),
chunithm: monkDB.get<`chunithm:${Playtypes["chunithm"]}`>(`charts-chunithm`),
ddr: monkDB.get<`ddr:${Playtypes["ddr"]}`>(`charts-ddr`),
gitadora: monkDB.get<`gitadora:${Playtypes["gitadora"]}`>(`charts-gitadora`),
iidx: monkDB.get<`iidx:${Playtypes["iidx"]}`>(`charts-iidx`),
jubeat: monkDB.get<`jubeat:${Playtypes["jubeat"]}`>(`charts-jubeat`),
maimai: monkDB.get<`maimai:${Playtypes["maimai"]}`>(`charts-maimai`),
museca: monkDB.get<`museca:${Playtypes["museca"]}`>(`charts-museca`),
popn: monkDB.get<`popn:${Playtypes["popn"]}`>(`charts-popn`),
sdvx: monkDB.get<`sdvx:${Playtypes["sdvx"]}`>(`charts-sdvx`),
usc: monkDB.get<`usc:${Playtypes["usc"]}`>(`charts-usc`),
},
};
for (const game of config.supportedGames) {
GameCollectionPartial.songs[game] = monkDB.get<SongDocument>(`songs-${game}`);
}
// a typescript-friendly interface for the database.
const db = Object.assign(StaticCollections, GameCollectionPartial as GameCollectionFull);
export default db;
+6 -6
View File
@@ -25,12 +25,12 @@ export const PRUDENCE_PUBLIC_USER: PrudenceSchema = {
},
friends: [p.isPositiveInteger],
socialMedia: {
discord: "?string",
twitter: "?string",
github: "?string",
steam: "?string",
youtube: "?string",
twitch: "?string",
discord: "*?string",
twitter: "*?string",
github: "*?string",
steam: "*?string",
youtube: "*?string",
twitch: "*?string",
},
about: p.isBoundedString(0, 4000),
customPfp: "boolean",
@@ -1,4 +1,5 @@
import { Game } from "kamaitachi-common";
import { Game, AnySongDocument } from "kamaitachi-common";
import { FindOneResult } from "monk";
import db from "../../db/db";
/**
@@ -8,9 +9,13 @@ import db from "../../db/db";
* @param game - The game to search upon.
* @param title - The song title to match.
* @param version - The version a song should be in to be counted.
* @returns SongDocument
* @returns AnySongDocument
*/
export function FindSongOnTitleVersion(game: Game, title: string, version: string | number) {
export function FindSongOnTitleVersion<G extends Game>(
game: G,
title: string,
version: string
): Promise<FindOneResult<AnySongDocument>> {
return db.songs[game].findOne({
"data.version": version,
$or: [
@@ -30,9 +35,13 @@ export function FindSongOnTitleVersion(game: Game, title: string, version: strin
* rather difficult. Prefer other functions!
* @param game - The game to search upon.
* @param title - The song title to match.
* @returns SongDocument
* @returns AnySongDocument
*/
export function FindSongOnTitle(game: Game, title: string) {
export function FindSongOnTitle(
game: Game,
title: string
): Promise<FindOneResult<AnySongDocument>> {
db.songs[game];
return db.songs[game].findOne({
$or: [
{
@@ -5,7 +5,6 @@ import {
IDStrings,
Playtypes,
ScoreDocument,
SongDocument,
TierlistDataDocument,
} from "kamaitachi-common";
import { Logger } from "winston";
@@ -1,10 +1,9 @@
import {
AnyChartDocument,
ChartDocument,
config,
integer,
ScoreDocument,
SongDocument,
AnySongDocument,
} from "kamaitachi-common";
import { Logger } from "winston";
import { DryScore } from "../../../types";
@@ -19,7 +18,7 @@ export default async function HydrateScore(
userID: integer,
dryScore: DryScore,
chart: AnyChartDocument,
song: SongDocument,
song: AnySongDocument,
scoreID: string,
logger: Logger
): Promise<ScoreDocument> {
@@ -50,7 +49,6 @@ export default async function HydrateScore(
songID: song.id,
chartID: chart.chartID,
scoreID,
difficulty: chart.difficulty,
playtype: chart.playtype,
// these will be sorted out in post-processing
isLampPB: false,
@@ -1,10 +1,9 @@
import {
AnyChartDocument,
ChartDocument,
ImportProcessingInfo,
integer,
ScoreDocument,
SongDocument,
AnySongDocument,
} from "kamaitachi-common";
import { DryScore, ConverterFunction, ConverterFnReturn } from "../../../types";
import HydrateScore from "../core/hydrate-score";
@@ -120,7 +119,7 @@ async function HydrateAndInsertScore(
userID: integer,
dryScore: DryScore,
chart: AnyChartDocument,
song: SongDocument,
song: AnySongDocument,
importLogger: Logger
): Promise<ScoreDocument | null> {
const scoreID = CreateScoreID(userID, dryScore, chart.chartID);
@@ -1,4 +1,4 @@
import { config, ESDCore, Lamps, SongDocument } from "kamaitachi-common";
import { config, ESDCore, Lamps, AnySongDocument } from "kamaitachi-common";
import { Logger } from "winston";
import { DryScore, ConverterFunction, ConverterFnReturn } from "../../../types";
import { FindChartWithPTDF } from "../../database-lookup/chart-ptdf";
@@ -29,7 +29,7 @@ const EAMUSEMENT_LAMP_RESOLVER: Map<string, Lamps["iidx:SP" | "iidx:DP"]> = new
async function EamScoreConverter(
eamScore: EamusementScoreData,
ktchiSong: SongDocument,
ktchiSong: AnySongDocument,
context: IIDXEamusementCSVContext,
data: IIDXEamusementCSVData,
logger: Logger
@@ -166,7 +166,7 @@ async function EamScoreConverter(
*/
async function EamScoreConverterWrapper(
eamScore: EamusementScoreData,
song: SongDocument,
song: AnySongDocument,
context: IIDXEamusementCSVContext,
data: IIDXEamusementCSVData,
logger: Logger
+2 -2
View File
@@ -4,7 +4,7 @@ import {
ImportTypes,
integer,
ScoreDocument,
SongDocument,
AnySongDocument,
} from "kamaitachi-common";
import { Logger } from "winston";
import { ConverterFailure } from "./score-import/framework/core/converter-errors";
@@ -38,7 +38,7 @@ export type KTReponse = KTFailResponse | KTSuccessResponse;
export interface ConverterFnSuccessReturn {
dryScore: DryScore;
chart: AnyChartDocument;
song: SongDocument;
song: AnySongDocument;
}
export type ConverterFnReturn = ConverterFailure | ConverterFnSuccessReturn | null;