From 12d0850ab70039b95cb1391fcc69e2fba598c153 Mon Sep 17 00:00:00 2001 From: tobinio Date: Tue, 15 Apr 2025 19:24:38 +0000 Subject: [PATCH] lints --- nuxt.config.ts | 6 +----- package.json | 1 + tsconfig.json | 3 ++- server/utils/storage.ts | 8 ++------ shared/utils/array.ts | 8 ++++---- server/api/stats/projects.ts | 2 +- server/utils/export/globalStats.ts | 2 +- server/utils/export/projectStats.ts | 19 +++++++++++++++---- server/utils/export/revenue.ts | 4 ++-- server/api/stats/time/global.ts | 2 +- server/api/stats/time/projects.ts | 2 +- server/api/stats/time/revenue.ts | 9 ++------- server/utils/processing/gameVersions/processing.ts | 4 ++-- server/utils/processing/projects/processing.ts | 12 ++++++------ 14 file(s) changed, 41 insertion(s)(+), 41 deletion(s)(-) diff --git a/nuxt.config.ts b/nuxt.config.ts --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -61,10 +61,6 @@ }, }, - modules: [ - "@nuxt/icon", - "@nuxtjs/tailwindcss", - "@vueuse/nuxt", - ], + modules: ["@nuxt/icon", "@nuxtjs/tailwindcss", "@vueuse/nuxt"], compatibilityDate: "2024-07-05", }); diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "postinstall": "nuxt prepare", "lint:fix": "biome check --write", "lint": "biome check", + "lint:typecheck": "nuxi typecheck", "lint:check": "biome check", "lint:summary": "biome check --reporter summary" }, diff --git a/tsconfig.json b/tsconfig.json --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,4 @@ { - "extends": "./.nuxt/tsconfig.json" + "extends": "./.nuxt/tsconfig.json", + "exclude": ["db-fix.js"] } diff --git a/server/utils/storage.ts b/server/utils/storage.ts --- a/server/utils/storage.ts +++ b/server/utils/storage.ts @@ -100,13 +100,9 @@ return getFromStorage("projectStatistics", key); } -type StorageValue = null | string | number | boolean | object; -async function getFromStorage( - storageName: string, - key: string, -) { +async function getFromStorage(storageName: string, key: string) { const storage = useStorage(storageName); - const data = await storage.getItem(key); + const data = (await storage.getItem(key)) as t; if (!data) { return new Error( diff --git a/shared/utils/array.ts b/shared/utils/array.ts --- a/shared/utils/array.ts +++ b/shared/utils/array.ts @@ -1,5 +1,5 @@ export function chunkArray(array: T[], size: number): T[][] { - return Array.from({length: Math.ceil(array.length / size)}, (_, i) => - array.slice(i * size, i * size + size) - ); -} \ No newline at end of file + return Array.from({ length: Math.ceil(array.length / size) }, (_, i) => + array.slice(i * size, i * size + size), + ); +} diff --git a/server/api/stats/projects.ts b/server/api/stats/projects.ts --- a/server/api/stats/projects.ts +++ b/server/api/stats/projects.ts @@ -1,7 +1,7 @@ import { statStringToExtraction } from "~~/server/utils/api/project"; +import { exportStats } from "~~/server/utils/export/projectStats"; import type { VersionCategories } from "~~/server/utils/processing/gameVersions/types"; import type { ProjectStatCategory } from "~~/server/utils/processing/projects/types"; -import {exportStats} from "~~/server/utils/export/projectStats"; type QueryData = { stat: ProjectStatCategory; diff --git a/server/utils/export/globalStats.ts b/server/utils/export/globalStats.ts --- a/server/utils/export/globalStats.ts +++ b/server/utils/export/globalStats.ts @@ -26,7 +26,7 @@ } statsOverTime.labels.splice(0, 0, dateToFormatted(date)); - statsOverTime.data[0].data.splice(0, 0, fn(stats)); + statsOverTime.data[0]?.data.splice(0, 0, fn(stats)); date.setUTCDate(date.getUTCDate() - 1); } diff --git a/server/utils/export/projectStats.ts b/server/utils/export/projectStats.ts --- a/server/utils/export/projectStats.ts +++ b/server/utils/export/projectStats.ts @@ -49,7 +49,11 @@ mappedStats.labels = mappedStats.labels.slice(from, to); for (let i = 0; i < mappedStats.data.length; i++) { - mappedStats.data[i].data = mappedStats.data[i].data.slice(from, to); + const data = mappedStats.data[i]; + + if (!data) continue; + + data.data = data.data.slice(from, to); } } @@ -101,21 +105,28 @@ break; } - const index = stats.versions.indexOf(version); + const versionIndex = stats.versions.indexOf(version); statsOverTime.versions.splice(0, 0, dateToFormatted(date)); outer: for (const data of stats.data) { + const versionData = data.values[versionIndex]; + + if (!versionData) { + consola.warn(`no version data - ${stats}`); + continue; + } + for (const dataOverTime of statsOverTime.data) { if (dataOverTime.name === data.name) { - dataOverTime.values.splice(0, 0, data.values[index]); + dataOverTime.values.splice(0, 0, versionData); continue outer; } } statsOverTime.data.push({ name: data.name, - values: [data.values[index]], + values: [versionData], }); } diff --git a/server/utils/export/revenue.ts b/server/utils/export/revenue.ts --- a/server/utils/export/revenue.ts +++ b/server/utils/export/revenue.ts @@ -20,8 +20,8 @@ for (const revenue of await getRevenue()) { statsOverTime.labels.splice(0, 0, dateToFormatted(revenue.time)); - statsOverTime.data[0].data.splice(0, 0, revenue.creator_revenue); - statsOverTime.data[1].data.splice(0, 0, revenue.modrinth_revenue); + statsOverTime.data[0]?.data.splice(0, 0, revenue.creator_revenue); + statsOverTime.data[1]?.data.splice(0, 0, revenue.modrinth_revenue); } return statsOverTime; diff --git a/server/api/stats/time/global.ts b/server/api/stats/time/global.ts --- a/server/api/stats/time/global.ts +++ b/server/api/stats/time/global.ts @@ -1,7 +1,7 @@ import consola from "consola"; +import { exportGlobalStatsOverTime } from "~~/server/utils/export/globalStats"; import type { GlobalStatCategory } from "~~/server/utils/processing/global/types"; import { getLatestDate } from "~~/server/utils/storage"; -import {exportGlobalStatsOverTime} from "~~/server/utils/export/globalStats"; type QueryData = { type: GlobalStatCategory; diff --git a/server/api/stats/time/projects.ts b/server/api/stats/time/projects.ts --- a/server/api/stats/time/projects.ts +++ b/server/api/stats/time/projects.ts @@ -1,7 +1,7 @@ import { statStringToExtraction } from "~~/server/utils/api/project"; +import { exportStatsOverTime } from "~~/server/utils/export/projectStats"; import type { VersionCategories } from "~~/server/utils/processing/gameVersions/types"; import type { ProjectStatCategory } from "~~/server/utils/processing/projects/types"; -import {exportStatsOverTime} from "~~/server/utils/export/projectStats"; type QueryData = { stat: ProjectStatCategory; diff --git a/server/api/stats/time/revenue.ts b/server/api/stats/time/revenue.ts --- a/server/api/stats/time/revenue.ts +++ b/server/api/stats/time/revenue.ts @@ -1,12 +1,7 @@ -import type { GlobalStatCategory } from "~~/server/utils/processing/global/types"; -import {exportRevenueStatsOverTime} from "~~/server/utils/export/revenue"; - -type QueryData = { - type: GlobalStatCategory; -}; +import { exportRevenueStatsOverTime } from "~~/server/utils/export/revenue"; export default defineCachedEventHandler( - async (event): Promise => { + async (_event): Promise => { return exportRevenueStatsOverTime(); }, { maxAge: 60 * 60 /* 1 hour */, swr: false }, diff --git a/server/utils/processing/gameVersions/processing.ts b/server/utils/processing/gameVersions/processing.ts --- a/server/utils/processing/gameVersions/processing.ts +++ b/server/utils/processing/gameVersions/processing.ts @@ -75,7 +75,7 @@ if ( major.length === 0 || - major[major.length - 1].name !== gameVersionName + major[major.length - 1]?.name !== gameVersionName ) { major.push({ name: gameVersionName, @@ -84,7 +84,7 @@ continue; } - major[major.length - 1].contains.push(...version.contains); + major[major.length - 1]?.contains.push(...version.contains); } return { diff --git a/server/utils/processing/projects/processing.ts b/server/utils/processing/projects/processing.ts --- a/server/utils/processing/projects/processing.ts +++ b/server/utils/processing/projects/processing.ts @@ -14,7 +14,7 @@ Version, } from "~~/server/utils/processing/projects/types"; import { getGameVersions, setProjectStats } from "~~/server/utils/storage"; -import {chunkArray} from "#shared/utils/array"; +import { chunkArray } from "#shared/utils/array"; type StatsDataType = Map< string, @@ -113,11 +113,11 @@ } } - const versionIds: string[] = [] - for (const chunk of chunkArray(batchProjectIds, 200)) { - const versions = await getVersionIds(chunk); - versionIds.push(...versions); - } + const versionIds: string[] = []; + for (const chunk of chunkArray(batchProjectIds, 200)) { + const versions = await getVersionIds(chunk); + versionIds.push(...versions); + } await analyzeVersionsFromIds(gameVersions, versionIds, data, type); -- tangled.sh