mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: some more type prefixes
This commit is contained in:
1 parent
0d8cb5c1ae
commit
26304fc281
71 files changed
+411
-409
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { TankClass, TankType } from '../protos';
|
||||
import { BlitzStats } from '../statistics';
|
||||
import { TankClass, TankType } from "../protos";
|
||||
import type { BlitzStats } from "../statistics";
|
||||
|
||||
export const TANK_TYPES = [
|
||||
TankType.RESEARCHABLE,
|
||||
@@ -8,9 +8,9 @@ export const TANK_TYPES = [
|
||||
];
|
||||
|
||||
export const TANK_TYPE_COMMAND_NAMES = {
|
||||
[TankType.RESEARCHABLE]: 'researchable',
|
||||
[TankType.PREMIUM]: 'premium',
|
||||
[TankType.COLLECTOR]: 'collector',
|
||||
[TankType.RESEARCHABLE]: "researchable",
|
||||
[TankType.PREMIUM]: "premium",
|
||||
[TankType.COLLECTOR]: "collector",
|
||||
};
|
||||
|
||||
export const TANK_CLASSES = [
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { assertSecret, EventManager } from '../blitzkit';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { Region } from './regions';
|
||||
import { assertSecret, EventManager } from "../blitzkit";
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import type { Region } from "./regions";
|
||||
|
||||
const RETRY_ERRORS = ['REQUEST_LIMIT_EXCEEDED', 'SOURCE_NOT_AVAILABLE'];
|
||||
const RETRY_ERRORS = ["REQUEST_LIMIT_EXCEEDED", "SOURCE_NOT_AVAILABLE"];
|
||||
|
||||
export const retryAbleBlitzFetchEvent = new EventManager();
|
||||
export const blitzFetchQueueAvailableEvent = new EventManager();
|
||||
|
||||
type BlitzResponse<Data extends object> =
|
||||
| {
|
||||
status: 'error';
|
||||
status: "error";
|
||||
error: { field: string; message: string; code: 402; value: null };
|
||||
}
|
||||
| {
|
||||
status: 'ok';
|
||||
status: "ok";
|
||||
data: Data;
|
||||
};
|
||||
|
||||
@@ -36,11 +36,11 @@ async function manageQueue() {
|
||||
const request = queue.shift()!;
|
||||
const data = (await patientFetch(request.url)
|
||||
.then((response) => response.json())
|
||||
.catch((error) => ({ status: 'error', error }))) as BlitzResponse<
|
||||
.catch((error) => ({ status: "error", error }))) as BlitzResponse<
|
||||
typeof request.resolve
|
||||
>;
|
||||
|
||||
if (data.status === 'ok') {
|
||||
if (data.status === "ok") {
|
||||
request.resolve(data.data);
|
||||
} else {
|
||||
if (RETRY_ERRORS.includes(data.error.message)) {
|
||||
@@ -67,19 +67,19 @@ export type FetchBlitzParams = Record<string, string | number | undefined>;
|
||||
export function fetchBlitz<Data extends object>(
|
||||
region: Region,
|
||||
path: string,
|
||||
params: FetchBlitzParams = {},
|
||||
params: FetchBlitzParams = {}
|
||||
) {
|
||||
return new Promise<Data>((resolve) => {
|
||||
queue.push({
|
||||
url: `https://api.wotblitz.${region}/wotb/${path}/?${Object.entries({
|
||||
application_id: assertSecret(
|
||||
import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID,
|
||||
import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID
|
||||
),
|
||||
...params,
|
||||
})
|
||||
.filter(([_, value]) => value !== undefined)
|
||||
.map(([key, value]) => `${key}=${encodeURIComponent(value!)}`)
|
||||
.join('&')}`,
|
||||
.join("&")}`,
|
||||
resolve(data) {
|
||||
resolve(data as Data);
|
||||
},
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { assertSecret } from '../blitzkit';
|
||||
import { BlitzGlossary } from '../types';
|
||||
import { assertSecret } from "../blitzkit";
|
||||
import type { BlitzGlossary } from "../types";
|
||||
|
||||
export async function fetchGlossary(locale: string) {
|
||||
const response = await fetch(
|
||||
`${assertSecret(
|
||||
import.meta.env.WOTB_GLOSSARY_DOMAIN,
|
||||
)}/${locale}${assertSecret(import.meta.env.WOTB_GLOSSARY_PATH)}`,
|
||||
import.meta.env.WOTB_GLOSSARY_DOMAIN
|
||||
)}/${locale}${assertSecret(import.meta.env.WOTB_GLOSSARY_PATH)}`
|
||||
);
|
||||
return (await response.json()) as BlitzGlossary;
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import { BlitzStats, calculateWN8 } from "../statistics";
|
||||
import { type BlitzStats, calculateWN8 } from "../statistics";
|
||||
|
||||
export type Stat = keyof ReturnType<typeof generateStats>;
|
||||
|
||||
export const STAT_NAMES: Record<Stat, string> = {
|
||||
battles: 'Battles',
|
||||
winrate: 'Winrate',
|
||||
wn8: 'WN8',
|
||||
averageDamage: 'Damage',
|
||||
damage: 'Accumulated damage',
|
||||
wins: 'Wins',
|
||||
battles: "Battles",
|
||||
winrate: "Winrate",
|
||||
wn8: "WN8",
|
||||
averageDamage: "Damage",
|
||||
damage: "Accumulated damage",
|
||||
wins: "Wins",
|
||||
};
|
||||
|
||||
export const STAT_KEYS = Object.keys(STAT_NAMES) as Stat[];
|
||||
@@ -29,7 +29,7 @@ export function prettifyStats(s: ReturnType<typeof generateStats>) {
|
||||
battles: `${s.battles}`,
|
||||
wins: `${s.wins}`,
|
||||
winrate: `${(s.winrate * 100).toFixed(0)}%`,
|
||||
wn8: s.wn8 ? s.wn8.toFixed(0) : '--',
|
||||
wn8: s.wn8 ? s.wn8.toFixed(0) : "--",
|
||||
damage: `${s.damage}`,
|
||||
averageDamage: s.averageDamage.toFixed(0),
|
||||
} satisfies Record<Stat, string>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fetchBlitz } from "./fetchBlitz";
|
||||
import { normalizeIds } from "./normalizeIds";
|
||||
import { Region } from "./regions";
|
||||
import type { Region } from "./regions";
|
||||
|
||||
interface IndividualAccountAchievements {
|
||||
achievements: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fetchBlitz } from "./fetchBlitz";
|
||||
import { normalizeIds } from "./normalizeIds";
|
||||
import { Region } from "./regions";
|
||||
import type { Region } from "./regions";
|
||||
|
||||
type IndividualClanAccountInfo = {
|
||||
account_id: number;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fetchBlitz } from "./fetchBlitz";
|
||||
import { normalizeIds } from "./normalizeIds";
|
||||
import { Region } from "./regions";
|
||||
import type { Region } from "./regions";
|
||||
|
||||
interface IndividualClanInfo {
|
||||
recruiting_options: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { context } from "../blitzkit/context";
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import { RatingLeague, RatingReward } from "./rating";
|
||||
import { Region } from "./regions";
|
||||
import type { RatingLeague, RatingReward } from "./rating";
|
||||
import type { Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
export type RatingInfo =
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { context } from "../blitzkit/context";
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import { RatingPlayer } from "../statistics";
|
||||
import { LeagueTop } from "./rating";
|
||||
import { Region } from "./regions";
|
||||
import type { RatingPlayer } from "../statistics";
|
||||
import type { LeagueTop } from "./rating";
|
||||
import type { Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
export async function getRatingLeague(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import { withCORSProxy } from "../blitzkit/withCORSProxy";
|
||||
import { RatingNeighbors } from "./rating";
|
||||
import { Region } from "./regions";
|
||||
import type { RatingNeighbors } from "./rating";
|
||||
import type { Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
export async function getRatingNeighbors(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TanksStats } from "../types";
|
||||
import { FetchBlitzParams, fetchBlitz } from "./fetchBlitz";
|
||||
import { Region } from "./regions";
|
||||
import type { TanksStats } from "../types";
|
||||
import { type FetchBlitzParams, fetchBlitz } from "./fetchBlitz";
|
||||
import type { Region } from "./regions";
|
||||
|
||||
export async function getTankStats(
|
||||
region: Region,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Region } from './regions';
|
||||
import { type Region } from './regions';
|
||||
|
||||
export const MIN_REGION_IDS: Record<Region, number> = {
|
||||
asia: 20e8,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { RatingPlayer } from '../statistics';
|
||||
import { type RatingPlayer } from '../statistics';
|
||||
|
||||
export const LEAGUES = [
|
||||
{ name: 'diamond', minScore: 5000, index: 0, icon: 'YOw6mZ4' },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Region, RegionSubdomain } from "./regions";
|
||||
import type { Region, RegionSubdomain } from "./regions";
|
||||
|
||||
export function regionSubdomainToRegion(regionDomain: RegionSubdomain): Region {
|
||||
return regionDomain === "na" ? "com" : regionDomain;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Region, RegionSubdomain } from "./regions";
|
||||
import { type Region, type RegionSubdomain } from "./regions";
|
||||
|
||||
export function regionToRegionSubdomain(regionDomain: Region): RegionSubdomain {
|
||||
return regionDomain === "com" ? "na" : regionDomain;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ClanList } from "./clans";
|
||||
import type { ClanList } from "./clans";
|
||||
import { fetchBlitz } from "./fetchBlitz";
|
||||
import { Region } from "./regions";
|
||||
import type { Region } from "./regions";
|
||||
|
||||
export async function searchClansAcrossRegions(search: string, limit = 25) {
|
||||
const trimmed = search.trim();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { context } from "../blitzkit/context";
|
||||
import { Region } from "./regions";
|
||||
import { type Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
type CurrentRatingPlayerSearch = Record<
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fetchBlitz } from '../fetchBlitz';
|
||||
import { Region } from '../regions';
|
||||
import { usernamePattern } from './constants';
|
||||
import { fetchBlitz } from "../fetchBlitz";
|
||||
import type { Region } from "../regions";
|
||||
import { usernamePattern } from "./constants";
|
||||
|
||||
export interface AccountListItem {
|
||||
nickname: string;
|
||||
@@ -19,7 +19,7 @@ export async function searchPlayersAcrossRegions(search: string, limit = 25) {
|
||||
if (usernamePattern.test(trimmed)) {
|
||||
return (
|
||||
await Promise.all([
|
||||
fetchBlitz<AccountList>('com', 'account/list', {
|
||||
fetchBlitz<AccountList>("com", "account/list", {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
@@ -27,10 +27,10 @@ export async function searchPlayersAcrossRegions(search: string, limit = 25) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'com' as Region,
|
||||
})),
|
||||
region: "com" as Region,
|
||||
}))
|
||||
),
|
||||
fetchBlitz<AccountList>('eu', 'account/list', {
|
||||
fetchBlitz<AccountList>("eu", "account/list", {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
@@ -38,10 +38,10 @@ export async function searchPlayersAcrossRegions(search: string, limit = 25) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'eu' as Region,
|
||||
})),
|
||||
region: "eu" as Region,
|
||||
}))
|
||||
),
|
||||
fetchBlitz<AccountList>('asia', 'account/list', {
|
||||
fetchBlitz<AccountList>("asia", "account/list", {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
@@ -49,8 +49,8 @@ export async function searchPlayersAcrossRegions(search: string, limit = 25) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'asia' as Region,
|
||||
})),
|
||||
region: "asia" as Region,
|
||||
}))
|
||||
),
|
||||
])
|
||||
)
|
||||
@@ -61,4 +61,4 @@ export async function searchPlayersAcrossRegions(search: string, limit = 25) {
|
||||
}
|
||||
}
|
||||
|
||||
export * from './constants';
|
||||
export * from "./constants";
|
||||
@@ -1,6 +1,6 @@
|
||||
import { emptyAllStats } from '../../blitz/constants';
|
||||
import { Samples } from '../../protos';
|
||||
import { BlitzkitStats } from '../../statistics';
|
||||
import type { BlitzkitStats } from '../../statistics';
|
||||
|
||||
export const emptyAverageDefinitionsAllStats: BlitzkitStats = {
|
||||
...emptyAllStats,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Region } from "../blitz/regions";
|
||||
import type { Region } from "../blitz/regions";
|
||||
import { RatingLeaderboard } from "../protos";
|
||||
import { asset } from "./asset";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MessageFns } from '../protos';
|
||||
import type { MessageFns } from '../protos';
|
||||
|
||||
export async function fetchPB<Type>(url: string, message: MessageFns<Type>) {
|
||||
const response = await fetch(url);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { calculateWN8 } from '../calculateWN8';
|
||||
import { calculateWN8 } from "../calculateWN8";
|
||||
import {
|
||||
BlitzkitStats,
|
||||
CompositeStats,
|
||||
type BlitzkitStats,
|
||||
type CompositeStats,
|
||||
compositeStatsFormatting,
|
||||
CompositeStatsKey,
|
||||
} from './constants';
|
||||
type CompositeStatsKey,
|
||||
} from "./constants";
|
||||
|
||||
export function compositeStats(stats: BlitzkitStats, average: BlitzkitStats) {
|
||||
return {
|
||||
@@ -52,9 +52,9 @@ export function compositeStats(stats: BlitzkitStats, average: BlitzkitStats) {
|
||||
export function formatCompositeStat(
|
||||
value: number,
|
||||
key: CompositeStatsKey,
|
||||
composite: CompositeStats,
|
||||
composite: CompositeStats
|
||||
) {
|
||||
if (composite.cumulative_battles === 0) return '--';
|
||||
if (composite.cumulative_battles === 0) return "--";
|
||||
|
||||
const formatting = compositeStatsFormatting[key];
|
||||
const resolvedValue = (formatting.coefficient ?? 1) * value;
|
||||
@@ -62,7 +62,7 @@ export function formatCompositeStat(
|
||||
formatting.localeFormat
|
||||
? Math.round(resolvedValue).toLocaleString()
|
||||
: resolvedValue.toFixed(formatting.fixed)
|
||||
}${formatting.unit ?? ''}`;
|
||||
}${formatting.unit ?? ""}`;
|
||||
}
|
||||
|
||||
export * from './constants';
|
||||
export * from "./constants";
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IndividualTankStats, emptyIndividualTankStats } from '../types';
|
||||
import { type IndividualTankStats, emptyIndividualTankStats } from "../types";
|
||||
|
||||
export function deltaTankStats(
|
||||
tanksA: IndividualTankStats[],
|
||||
tanksB: IndividualTankStats[],
|
||||
tanksB: IndividualTankStats[]
|
||||
) {
|
||||
return tanksB
|
||||
.map((b) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fetchTankDefinitions } from '../blitzkit';
|
||||
import { BlitzStats } from './compositeStats/constants';
|
||||
import type { BlitzStats } from './compositeStats/constants';
|
||||
|
||||
export async function getTierWeights(
|
||||
stats: Record<number, BlitzStats>,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { emptyAllStats } from '../blitz';
|
||||
import { BlitzStats } from '../statistics';
|
||||
import type { BlitzStats } from '../statistics';
|
||||
|
||||
export interface IndividualTankStats {
|
||||
all: BlitzStats;
|
||||
|
||||
Reference in new issue
Block a user