27 lines
755 B
JavaScript
27 lines
755 B
JavaScript
import npath from 'node:path'
|
|
import { request } from './http.js'
|
|
import { concat, identity, ifElse, isNotEmpty, join, map, pipe, toPairs } from 'rambda'
|
|
|
|
const UserAgent = { 'User-Agent': 'bevy-cli' }
|
|
|
|
export const RootURL = 'https://crates.io/api/v1'
|
|
|
|
const makeParams = ifElse(
|
|
isNotEmpty,
|
|
pipe(
|
|
toPairs,
|
|
map(join('=')),
|
|
join('&'),
|
|
concat('?')
|
|
),
|
|
() => identity('')
|
|
)
|
|
|
|
const get = (path, params = {}) => {
|
|
const url = [RootURL, path].join('/') + makeParams(params)
|
|
return request(url, { headers: UserAgent })
|
|
}
|
|
|
|
export const Crate = (crate, params) => get(npath.join('crates', crate), params)
|
|
export const CrateVersions = (crate, params) => get(npath.join('crates', crate, 'versions'), params)
|
|
|