@xmcl/modrinth
Version:
An implementation of modrinth API (https://docs.modrinth.com/api-spec)
247 lines • 7.82 kB
TypeScript
/**
* @module @xmcl/modrinth
*/
import { Category, GameVersion, License, Loader, Project, ProjectVersion, TeamMember, User } from './types';
export * from './types';
export interface SearchResultHit {
/**
* The slug of project, e.g. "my_project"
*/
slug: string;
/**
* The id of the project; prefixed with local-
*/
project_id: string;
/**
* The project type of the project.
* @enum "mod" "modpack"
* */
project_type: string;
/**
* The username of the author of the project
*/
author: string;
/**
* The name of the project.
*/
title: string;
/**
* A short description of the project
*/
description: string;
/**
* A list of the categories the project is in.
*/
categories: Array<string>;
/**
* A list of the minecraft versions supported by the project.
*/
versions: Array<string>;
/**
* The total number of downloads for the project
*/
downloads: number;
follows: number;
/**
* A link to the project's main page; */
page_url: string;
/**
* The url of the project's icon */
icon_url: string;
/**
* The url of the project's author */
author_url: string;
/**
* The date that the project was originally created
*/
date_created: string;
/**
* The date that the project was last modified
*/
date_modified: string;
/**
* The latest version of minecraft that this project supports */
latest_version: string;
/**
* The id of the license this project follows */
license: string;
/**
* The side type id that this project is on the client */
client_side: string;
/**
* The side type id that this project is on the server */
server_side: string;
/**
* The host that this project is from, always modrinth */
host: string;
gallery: string[];
featured_gallery: string;
monetization_status: string;
}
export interface SearchProjectOptions {
/**
* The query to search
*/
query?: string;
/**
* The recommended way of filtering search results. [Learn more about using facets](https://docs.modrinth.com/docs/tutorials/search).
*
* @enum "categories" "versions" "license" "project_type"
* @example [["categories:forge"],["versions:1.17.1"],["project_type:mod"]]
*/
facets?: string;
/**
* A list of filters relating to the properties of a project. Use filters when there isn't an available facet for your needs. [More information](https://docs.meilisearch.com/reference/features/filtering.html)
*
* @example filter=categories="fabric" AND (categories="technology" OR categories="utility")
*/
filter?: string;
/**
* What the results are sorted by
*
* @enum "relevance" "downloads" "follows" "newest" "updated"
* @example "downloads"
* @default relevance
*/
index?: string;
/**
* The offset into the search; skips this number of results
* @default 0
*/
offset?: number;
/**
* The number of mods returned by the search
* @default 10
*/
limit?: number;
}
export interface SearchResult {
/**
* The list of results
*/
hits: Array<SearchResultHit>;
/**
* The number of results that were skipped by the query
*/
offset: number;
/**
* The number of mods returned by the query
*/
limit: number;
/**
* The total number of mods that the query found
*/
total_hits: number;
}
export interface GetProjectVersionsOptions {
id: string;
loaders?: Array<string>;
/**
* Minecraft version filtering
*/
game_versions?: Array<string>;
featured?: boolean;
}
export declare class ModerinthApiError extends Error {
readonly url: string;
readonly status: number;
readonly body: string;
constructor(url: string, status: number, body: string);
}
export interface ModrinthClientOptions {
baseUrl?: string;
/**
* The extra headers
*/
headers?: Record<string, string>;
/**
* The fetch function to use
*/
fetch?: typeof fetch;
}
/**
* @see https://docs.modrinth.com/api-spec
*/
export declare class ModrinthV2Client {
private baseUrl;
private fetch;
headers: Record<string, string>;
constructor(options?: ModrinthClientOptions);
/**
* @see https://docs.modrinth.com/#tag/projects/operation/searchProjects
*/
searchProjects(options: SearchProjectOptions, signal?: AbortSignal): Promise<SearchResult>;
/**
* @see https://docs.modrinth.com/#tag/projects/operation/getProject
*/
getProject(projectId: string, signal?: AbortSignal): Promise<Project>;
/**
* @see https://docs.modrinth.com/#tag/projects/operation/getProject
*/
getProjects(projectIds: string[], signal?: AbortSignal): Promise<Project[]>;
/**
* @see https://docs.modrinth.com/#tag/versions/operation/getProjectVersions
*/
getProjectVersions(projectId: string, { loaders, gameVersions, featured }?: {
loaders?: string[];
gameVersions?: string[];
featured?: boolean;
}, signal?: AbortSignal): Promise<ProjectVersion[]>;
/**
* @see https://docs.modrinth.com/#tag/versions/operation/getVersion
*/
getProjectVersion(versionId: string, signal?: AbortSignal): Promise<ProjectVersion>;
/**
* @see https://docs.modrinth.com/#tag/versions/operation/getVersions
*/
getProjectVersionsById(ids: string[], signal?: AbortSignal): Promise<ProjectVersion[]>;
/**
* @see https://docs.modrinth.com/#tag/version-files/operation/versionsFromHashes
*/
getProjectVersionsByHash(hashes: string[], algorithm?: string, signal?: AbortSignal): Promise<Record<string, ProjectVersion>>;
/**
* @see https://docs.modrinth.com/api-spec#tag/version-files/operation/getLatestVersionsFromHashes
*/
getLatestVersionsFromHashes(hashes: string[], { algorithm, loaders, gameVersions }?: {
algorithm?: string;
loaders?: string[];
gameVersions?: string[];
}, signal?: AbortSignal): Promise<Record<string, ProjectVersion>>;
/**
* @see https://docs.modrinth.com/#tag/version-files/operation/getLatestVersionFromHash
*/
getLatestProjectVersion(sha1: string, { algorithm, loaders, gameVersions }?: {
algorithm?: string;
loaders?: string[];
gameVersions?: string[];
}, signal?: AbortSignal): Promise<ProjectVersion>;
/**
* @see https://docs.modrinth.com/#tag/tags/operation/licenseList
*/
getLicenseTags(signal?: AbortSignal): Promise<License[]>;
/**
* @see https://docs.modrinth.com/#tag/tags/operation/categoryList
*/
getCategoryTags(signal?: AbortSignal): Promise<Category[]>;
/**
* @see https://docs.modrinth.com/#tag/tags/operation/versionList
*/
getGameVersionTags(signal?: AbortSignal): Promise<GameVersion[]>;
/**
* @see https://docs.modrinth.com/#tag/tags/operation/loaderList
*/
getLoaderTags(signal?: AbortSignal): Promise<Loader[]>;
/**
* @see https://docs.modrinth.com/#tag/teams/operation/getProjectTeamMembers
*/
getProjectTeamMembers(projectId: string, signal?: AbortSignal): Promise<TeamMember[]>;
/**
* @see https://docs.modrinth.com/#tag/users/operation/getUser
*/
getUser(id: string, signal?: AbortSignal): Promise<User>;
/**
* @see https://docs.modrinth.com/#tag/users/operation/getUserProjects
*/
getUserProjects(id: string, signal?: AbortSignal): Promise<Project[]>;
}
//# sourceMappingURL=index.d.ts.map