import type { Project, ProjectV3Partial } from '../types' import type { ModrinthApi } from './index' import type { ModrinthApiProjects, ProjectEditBody, ProjectV3EditBodyPartial } from './projects' export class RestModrinthApi implements ModrinthApi { projects: ModrinthApiProjects constructor(requestApi: (url: string, options?: object) => Promise) { this.projects = new RestModrinthApiProjects(requestApi) } } class RestModrinthApiProjects implements ModrinthApiProjects { constructor(private request: (url: string, options?: object) => Promise) {} async get(id: string): Promise { const res = await this.request(`/v2/project/${id}`) return res.json() } async getV3(id: string): Promise { const res = await this.request(`/v3/project/${id}`) return res.json() } async edit(id: string, data: ProjectEditBody): Promise { await this.request(`/v2/project/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) } async editV3(id: string, data: ProjectV3EditBodyPartial): Promise { await this.request(`/v3/project/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) } }