import { logger } from '../../logger' ; import { cache } from '../../util/cache/package/decorator' ; import type { HttpResponse } from '../../util/http' ; import * as hexVersioning from '../../versioning/hex' ; import { Datasource } from '../datasource' ; import type { GetReleasesConfig , ReleaseResult } from '../types' ; import type { HexRelease } from './types' ; export class HexDatasource extends Datasource { static readonly id = 'hex' ; constructor ( ) { super ( HexDatasource . id ) ; } override readonly defaultRegistryUrls = [ 'https://hex.pm/' ] ; override readonly customRegistrySupport = false ; override readonly defaultVersioning = hexVersioning . id ; @ cache ( { namespace : `datasource-${ HexDatasource . id }` , key : ( { lookupName } ) => lookupName , } ) async getReleases ( { lookupName , registryUrl , } ) { const [ hexPackageName , organizationName ] = lookupName . split ( ':' ) ; const organizationUrlPrefix = organizationName ? `repos/${ organizationName }/` : '' ; const hexUrl = `${ registryUrl }api/${ organizationUrlPrefix }packages/${ hexPackageName }` ; let response ; try { response = await this . http . getJson < HexRelease > ( hexUrl ) ; } catch ( err ) { this . handleGenericErrors ( err ) ; } const hexRelease = response . body ; if ( ! hexRelease ) { logger . warn ( { datasource : 'hex' , lookupName } , `Invalid response body` ) ; return null ; } const { releases = [ ] , html_url : homepage , meta } = hexRelease ; if ( releases . length === 0 ) { logger . debug ( `No versions found for ${ hexPackageName } (${ hexUrl })` ) ; return null ; } const result = { releases : releases . map ( ( { version , inserted_at } ) => inserted_at ? { version , releaseTimestamp : inserted_at , } : { version } ) , } ; if ( homepage ) { result . homepage = homepage ; } if ( meta ?. links ?. Github ) { result . sourceUrl = hexRelease . meta . links . Github ; } return result ; } }