libresolver/src/resolverModule.ts

41 lines
898 B
TypeScript
Raw Normal View History

2022-08-19 15:53:26 +00:00
// @ts-nocheck
2022-08-18 14:49:10 +00:00
import type { DNSResult, ResolverOptions } from "./types.js";
import { getTld } from "./util.js";
2022-08-18 17:08:15 +00:00
import { ResolverRegistry } from "@lumeweb/resolver";
2022-08-18 14:49:10 +00:00
2022-08-18 15:01:07 +00:00
export interface ResolverModule {
2022-08-19 15:53:26 +00:00
new (resolver: ResolverRegistry): any;
2022-08-18 14:49:10 +00:00
resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[];
2022-08-18 14:49:10 +00:00
}
2022-08-19 15:53:26 +00:00
// ts-ignore
export abstract class AbstractResolverModule implements ResolverModule {
2022-08-18 17:02:27 +00:00
protected resolver: ResolverRegistry;
2022-08-18 14:49:10 +00:00
2022-08-18 17:02:27 +00:00
constructor(resolver: ResolverRegistry) {
2022-08-18 14:49:10 +00:00
this.resolver = resolver;
2022-08-19 15:53:26 +00:00
return this;
2022-08-18 14:49:10 +00:00
}
abstract resolve(
input: string,
options: ResolverOptions,
2022-08-18 18:08:53 +00:00
bypassCache: boolean
2022-08-18 14:49:10 +00:00
): Promise<DNSResult>;
getSupportedTlds(): string[] {
return [];
}
isTldSupported(domain: string): boolean {
return this.getSupportedTlds().includes(getTld(domain));
}
}