Files
shields/services/crates/crates-version.service.js
chris48s b71f812b68 migrate examples to openApi part 17; affects [buildkite cii codeship crates jsdelivr npms] and bundlephobia (#9584)
* update crates service test

* migrate some services from examples to openApi

* migrate crates from examples to openApi, improve titles

* explain what hd,hw,hm,hy actually mean

* improve descriptions
2023-12-22 13:25:38 +00:00

37 lines
977 B
JavaScript

import { renderVersionBadge } from '../version.js'
import { InvalidResponse, pathParams } from '../index.js'
import { BaseCratesService, description } from './crates-base.js'
export default class CratesVersion extends BaseCratesService {
static category = 'version'
static route = { base: 'crates/v', pattern: ':crate' }
static openApi = {
'/crates/v/{crate}': {
get: {
summary: 'Crates.io Version',
description,
parameters: pathParams({
name: 'crate',
example: 'rustc-serialize',
}),
},
},
}
transform(json) {
if (json.errors) {
throw new InvalidResponse({ prettyMessage: json.errors[0].detail })
}
return json.crate.max_stable_version
? json.crate.max_stable_version
: json.crate.max_version
}
async handle({ crate }) {
const json = await this.fetch({ crate })
const version = this.transform(json)
return renderVersionBadge({ version })
}
}