UNPKG

typerinth

Version:

A TypeScript library for interacting with the Modrinth API.

40 lines (39 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Route_1 = require("../Route"); const errors_1 = require("../../errors"); class GetProjectVersionsRoute extends Route_1.Route { projectId; options; constructor(baseUrl, ua, cacheManager, projectId, options = {}) { super(baseUrl, ua, cacheManager); this.projectId = projectId; this.options = options; } getCacheKey() { return `project_versions:${this.projectId}:${JSON.stringify(this.options)}`; } getUrl() { const url = Route_1.Route.addPathSegment(this.baseUrl, `/project/${this.projectId}/version`); if (this.options.loaders) url.searchParams.append('loaders', `[${this.options.loaders?.map((l) => '"' + l + '"').join(',') ?? ''}]`); if (this.options.game_versions) url.searchParams.append('game_versions', `[${this.options.game_versions?.map((gv) => '"' + gv + '"').join(',') ?? ''}]`); if (!!this.options.featured) url.searchParams.append('featured', this.options.featured?.toString()); return url; } parseData(data) { if (data === null) throw new errors_1.VersionNotFoundError('Project version not found'); if (!data) throw new errors_1.UnexpectedApiError('Unexpected empty response'); if (data.error) { if (data.error === 'not_found') throw new errors_1.VersionNotFoundError('Project version not found'); throw new errors_1.ApiError(data.error, data.description); } return data; } } exports.default = GetProjectVersionsRoute;