renovate/lib/datasource/common.ts
Michael Kriese 00c56d8bde
chore: fix types (#5904)
* chore: fix types

* fix more types

* chore: mote fixes

* fix frmat

* chore: fix tests

* chore: fix type

* chore: cleanup

* chore: cleanup

Co-authored-by: Rhys Arkins <rhys@arkins.net>
2020-05-07 10:23:45 +02:00

92 lines
2.1 KiB
TypeScript

import { DATASOURCE_FAILURE } from '../constants/error-messages';
export interface Config {
datasource?: string;
depName?: string;
lookupName?: string;
registryUrls?: string[];
}
export type DigestConfig = Config;
interface ReleasesConfigBase {
compatibility?: Record<string, string>;
npmrc?: string;
registryUrls?: string[];
}
export interface GetReleasesConfig extends ReleasesConfigBase {
lookupName: string;
}
export interface GetPkgReleasesConfig extends ReleasesConfigBase {
datasource: string;
depName: string;
lookupName?: string;
versioning?: string;
}
export function isGetPkgReleasesConfig(
input: any
): input is GetPkgReleasesConfig {
return (
(input as GetPkgReleasesConfig).datasource !== undefined &&
(input as GetPkgReleasesConfig).depName !== undefined
);
}
export interface Release {
canBeUnpublished?: boolean;
changelogUrl?: string;
checksumUrl?: string;
downloadUrl?: string;
gitRef?: string;
isDeprecated?: boolean;
releaseTimestamp?: any;
version: string;
newDigest?: string;
}
export interface ReleaseResult {
sourceDirectory?: string;
latestVersion?: string;
changelogUrl?: string;
dependencyUrl?: string;
deprecationMessage?: string;
display?: string;
dockerRegistry?: string;
dockerRepository?: string;
group?: string;
homepage?: string;
name?: string;
pkgName?: string;
releases: Release[];
sourceUrl?: string;
tags?: Record<string, string>;
versions?: any;
}
export interface Datasource {
id: string;
getDigest?(config: DigestConfig, newValue?: string): Promise<string | null>;
getReleases(config: GetReleasesConfig): Promise<ReleaseResult | null>;
defaultRegistryUrls?: string[];
appendRegistryUrls?: string[];
defaultConfig?: object;
}
export class DatasourceError extends Error {
err: Error;
datasource?: string;
lookupName?: string;
constructor(err: Error) {
super(DATASOURCE_FAILURE);
// Set the prototype explicitly: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, DatasourceError.prototype);
this.err = err;
}
}