*Refactor isTldSupported to support promises

This commit is contained in:
Derrick Hammer 2023-02-19 18:03:32 -05:00
parent aba5fad2c7
commit 1e62962a1d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import type { DNSResult, ResolverOptions } from "./types.js";
import { getTld } from "./util.js";
import { getTld, isPromise } from "./util.js";
declare class ResolverRegistry {
get resolvers(): Set<ResolverModule> | Promise<Set<ResolverModule>>;
@ -23,7 +23,7 @@ export interface ResolverModule extends ResolverModuleConstructor {
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[];
getSupportedTlds(): string[] | Promise<string[]>;
}
// ts-ignore
@ -40,11 +40,18 @@ export abstract class AbstractResolverModule {
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[] {
getSupportedTlds(): string[] | Promise<string[]> {
return [];
}
isTldSupported(domain: string): boolean {
return this.getSupportedTlds().includes(getTld(domain));
isTldSupported(domain: string): boolean | Promise<boolean> {
let supported = this.getSupportedTlds();
if (isPromise(supported as Promise<string[]>)) {
return (supported as Promise<string[]>).then((supported: string[]) => {
return supported.includes(getTld(domain));
});
}
return (supported as string[]).includes(getTld(domain));
}
}