*add ResolverModule client class and factory

This commit is contained in:
Derrick Hammer 2023-02-19 20:49:06 -05:00
parent dd1b25aa30
commit 2bf62cbd3e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 52 additions and 0 deletions

52
src/module.ts Normal file
View File

@ -0,0 +1,52 @@
import { Client, factory } from "@lumeweb/libkernel-universal";
import { DnsClient } from "./index.js";
import {
DNSResult,
resolverError,
ResolverOptions,
} from "@lumeweb/libresolver";
export class ResolverModule extends Client {
private domain: string;
constructor(domain: string, resolver?: DnsClient) {
super();
this._resolver = resolver;
this.domain = domain;
}
private _resolver?: DnsClient;
get resolver(): DnsClient {
return this._resolver as DnsClient;
}
set resolver(value: DnsClient) {
this._resolver = value;
}
async resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult> {
try {
return this.callModuleReturn("resolve", {
domain,
options,
bypassCache,
});
} catch (e) {
return resolverError(e as Error);
}
}
async getSupportedTlds(): Promise<string[]> {
return this.callModuleReturn("getSupportedTlds");
}
}
export const createModule = (
module: string,
client: DnsClient
): ResolverModule =>
factory<ResolverModule>(ResolverModule, module)(module, client);