refactor: rename GetOperationReturn to GetOperationResult and use it in all situations when it is used

This commit is contained in:
b1ek 2024-07-29 11:46:52 +10:00
parent cd1f4e9525
commit 30c538b530
Signed by: blek
GPG Key ID: 14546221E3595D0C
5 changed files with 10 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import { Address4, Address6 } from 'ip-address'
export type AdditionalData = { ip: Address4 | Address6 } export type AdditionalData = { ip: Address4 | Address6 }
export type HKPOperation = keyof AbstractKeysProvider export type HKPOperation = keyof AbstractKeysProvider
export type GetOperationReturn = string | 404 export type GetOperationResult = string | 404
export const VALID_OPS: readonly HKPOperation[] = Object.freeze([ export const VALID_OPS: readonly HKPOperation[] = Object.freeze([
'get', 'get',
@ -29,7 +29,7 @@ export abstract class AbstractKeysProvider {
async get( async get(
search: string, search: string,
data: AdditionalData data: AdditionalData
): Promise<GetOperationReturn> { ): Promise<GetOperationResult> {
return 404 return 404
} }

View File

@ -1,6 +1,7 @@
import { Get, Injectable } from '@nestjs/common' import { Get, Injectable } from '@nestjs/common'
import { import {
AbstractKeysProvider, AbstractKeysProvider,
GetOperationResult,
type AdditionalData, type AdditionalData,
} from './abstract.provider.js' } from './abstract.provider.js'
import { Indexes, InfoLine } from '../indexes.js' import { Indexes, InfoLine } from '../indexes.js'
@ -24,7 +25,7 @@ export class AllKeysProvider implements AbstractKeysProvider {
} }
@Get() @Get()
async get(search: string, data: AdditionalData): Promise<string | 404> { async get(search: string, data: AdditionalData): Promise<GetOperationResult> {
const all = this.getAll() const all = this.getAll()
const promises = await Promise.all(all.map((x) => x.get(search, data))) const promises = await Promise.all(all.map((x) => x.get(search, data)))

View File

@ -1,7 +1,7 @@
import { Get, Injectable } from '@nestjs/common' import { Get, Injectable } from '@nestjs/common'
import { AbstractKeysProvider } from './abstract.provider.js' import { AbstractKeysProvider } from './abstract.provider.js'
import type { AdditionalData } from './abstract.provider.js' import type { AdditionalData, GetOperationResult } from './abstract.provider.js'
import { proxyGetOp, proxyIndexOp } from './utils.js' import { proxyGetOp, proxyIndexOp } from './utils.js'
import { Indexes } from '../indexes.js' import { Indexes } from '../indexes.js'
@ -10,7 +10,7 @@ export class OpenPGPKeysProvider implements AbstractKeysProvider {
readonly url = Object.freeze('https://keys.openpgp.org') readonly url = Object.freeze('https://keys.openpgp.org')
@Get() @Get()
async get(search: string, data: AdditionalData): Promise<string | 404> { async get(search: string, data: AdditionalData): Promise<GetOperationResult> {
return proxyGetOp(this.url + '/pks/lookup', search, data) return proxyGetOp(this.url + '/pks/lookup', search, data)
} }

View File

@ -1,7 +1,7 @@
import { Get, Injectable } from '@nestjs/common' import { Get, Injectable } from '@nestjs/common'
import { AbstractKeysProvider } from './abstract.provider.js' import { AbstractKeysProvider } from './abstract.provider.js'
import type { AdditionalData } from './abstract.provider.js' import type { AdditionalData, GetOperationResult } from './abstract.provider.js'
import { proxyGetOp, proxyIndexOp } from './utils.js' import { proxyGetOp, proxyIndexOp } from './utils.js'
import { Indexes } from '../indexes.js' import { Indexes } from '../indexes.js'
@ -10,7 +10,7 @@ export class UbuntuKeysProvider implements AbstractKeysProvider {
readonly url = Object.freeze('https://keyserver.ubuntu.com') readonly url = Object.freeze('https://keyserver.ubuntu.com')
@Get() @Get()
async get(search: string, data: AdditionalData): Promise<string | 404> { async get(search: string, data: AdditionalData): Promise<GetOperationResult> {
return proxyGetOp(this.url + '/pks/lookup', search, data) return proxyGetOp(this.url + '/pks/lookup', search, data)
} }

View File

@ -2,7 +2,7 @@ import type { KyResponse, ResponsePromise } from 'ky'
import ky from 'ky' import ky from 'ky'
import type { import type {
AdditionalData, AdditionalData,
GetOperationReturn, GetOperationResult,
HKPOperation, HKPOperation,
} from './abstract.provider.js' } from './abstract.provider.js'
import type { Indexes } from '../indexes.js' import type { Indexes } from '../indexes.js'
@ -42,7 +42,7 @@ export async function proxyGetOp(
url: string, url: string,
search: string, search: string,
data: AdditionalData data: AdditionalData
): Promise<GetOperationReturn> { ): Promise<GetOperationResult> {
let httpRes: KyResponse let httpRes: KyResponse
try { try {
httpRes = await proxyRequest(url, 'get', search, data) httpRes = await proxyRequest(url, 'get', search, data)