diff --git a/src/games/game-version-provider.ts b/src/games/game-version-provider.ts new file mode 100644 index 0000000..04ee3a5 --- /dev/null +++ b/src/games/game-version-provider.ts @@ -0,0 +1,35 @@ +import { Awaitable } from "@/utils/types"; +import { GameVersion } from "./game-version"; +import { MINECRAFT, MINECRAFT_VERSION_PROVIDER } from "./minecraft"; + +/** + * Represents a provider for game version. + */ +export interface GameVersionProvider { + /** + * Returns an array of game versions that satisfy the given version range. + * + * @param versions - A version range. + * + * @returns An array of game versions that satisfy the given version range. + */ + (versions: string[]): Awaitable; +} + +/** + * A map of game version providers keyed by game name. + */ +const GAME_VERSION_PROVIDERS: ReadonlyMap = new Map([ + [MINECRAFT, MINECRAFT_VERSION_PROVIDER], +]); + +/** + * Returns the game version provider for the given game name. + * + * @param name - The name of the game. + * + * @returns The {@link GameVersionProvider} for the given game name, or `undefined` if it does not exist. + */ +export function getGameVersionProviderByName(name: string): GameVersionProvider | undefined { + return GAME_VERSION_PROVIDERS.get(name); +} diff --git a/tests/unit/games/game-version-provider.spec.ts b/tests/unit/games/game-version-provider.spec.ts new file mode 100644 index 0000000..a2b1340 --- /dev/null +++ b/tests/unit/games/game-version-provider.spec.ts @@ -0,0 +1,15 @@ +import { getGameVersionProviderByName } from "@/games/game-version-provider"; + +describe("getGameVersionProviderByName", () => { + test("returns the correct provider for a given game name", async () => { + const provider = getGameVersionProviderByName("minecraft"); + + expect(provider).toBeDefined(); + }); + + test("returns undefined for a non-existing game name", async () => { + const provider = getGameVersionProviderByName("unknown-game"); + + expect(provider).toBeUndefined(); + }); +});