Rename types

This commit is contained in:
Michael B. Gale
2026-02-11 17:10:39 +00:00
parent 0387f55b70
commit 4d0bec12bf
6 changed files with 58 additions and 38 deletions
+4 -4
View File
@@ -11,22 +11,22 @@ import {
ReachabilityBackend,
ReachabilityError,
} from "./reachability";
import { ProxyInfo, ValidRegistry } from "./types";
import { ProxyInfo, Registry } from "./types";
setupTests(test);
class MockReachabilityBackend implements ReachabilityBackend {
public async checkConnection(_registry: ValidRegistry): Promise<number> {
public async checkConnection(_registry: Registry): Promise<number> {
return 200;
}
}
const mavenRegistry: ValidRegistry = {
const mavenRegistry: Registry = {
type: "maven_registry",
url: "https://repo.maven.apache.org/maven2/",
};
const nugetFeed: ValidRegistry = {
const nugetFeed: Registry = {
type: "nuget_feed",
url: "https://api.nuget.org/v3/index.json",
};
+5 -5
View File
@@ -5,7 +5,7 @@ import { HttpsProxyAgent } from "https-proxy-agent";
import { Logger } from "../logging";
import { getErrorMessage } from "../util";
import { getAddressString, ProxyInfo, ValidRegistry } from "./types";
import { getAddressString, ProxyInfo, Registry } from "./types";
export class ReachabilityError extends Error {
constructor(public readonly statusCode?: number | undefined) {
@@ -25,7 +25,7 @@ export interface ReachabilityBackend {
* @param registry The registry to try and reach.
* @returns The successful status code (in the `<400` range).
*/
checkConnection: (registry: ValidRegistry) => Promise<number>;
checkConnection: (registry: Registry) => Promise<number>;
}
class NetworkReachabilityBackend implements ReachabilityBackend {
@@ -38,7 +38,7 @@ class NetworkReachabilityBackend implements ReachabilityBackend {
this.agent = new HttpsProxyAgent(`http://${proxy.host}:${proxy.port}`);
}
public async checkConnection(registry: ValidRegistry): Promise<number> {
public async checkConnection(registry: Registry): Promise<number> {
return new Promise((resolve, reject) => {
const req = https.request(
getAddressString(registry),
@@ -78,8 +78,8 @@ export async function checkConnections(
logger: Logger,
proxy: ProxyInfo,
backend?: ReachabilityBackend,
): Promise<Set<ValidRegistry>> {
const result: Set<ValidRegistry> = new Set();
): Promise<Set<Registry>> {
const result: Set<Registry> = new Set();
// Don't do anything if there are no registries.
if (proxy.registries.length === 0) return result;
+24 -13
View File
@@ -1,14 +1,28 @@
export interface Credential extends Registry {
username?: string;
password?: string;
token?: string;
}
/**
* After parsing configurations from JSON, we don't know whether all the keys we expect are
* present or not. This type is used to represent such values, which we expect to be
* `Credential` values, but haven't validated yet.
*/
export type RawCredential = Partial<Credential>;
export interface Registry {
/**
* A package registry configuration includes identifying information as well as
* authentication credentials.
*/
export type Credential = {
/** The username needed to authenticate to the package registry, if any. */
username?: string;
/** The password needed to authenticate to the package registry, if any. */
password?: string;
/** The token needed to authenticate to the package registry, if any. */
token?: string;
} & Registry;
/** A package registry is identified by its type and address. */
export type Registry = {
/** The type of the package registry. */
type: string;
host?: string;
url?: string;
}
} & Address;
// If a registry has an `url`, then that takes precedence over the `host` which may or may
// not be defined.
@@ -39,12 +53,9 @@ export function getAddressString(address: Address): string {
}
}
export type ValidRegistry<T extends Registry = Registry> = T & Address;
export type ValidCredential = ValidRegistry<Credential>;
export interface ProxyInfo {
host: string;
port: number;
cert: string;
registries: ValidRegistry[];
registries: Registry[];
}