parent
cf4df9dc91
commit
0204e4d5e3
|
@ -4,8 +4,9 @@ import {
|
|||
DNS_RECORD_TYPE,
|
||||
resolverError,
|
||||
} from "@lumeweb/resolver-common";
|
||||
import { resolve } from "@lumeweb/kernel-dns-client";
|
||||
import { getResolvers, resolve } from "@lumeweb/kernel-dns-client";
|
||||
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
|
||||
import { callModule } from "libkmodule";
|
||||
|
||||
export class ResolverRegistry {
|
||||
private _rpcNetwork: RpcNetwork;
|
||||
|
@ -18,6 +19,18 @@ export class ResolverRegistry {
|
|||
return this._rpcNetwork;
|
||||
}
|
||||
|
||||
get resolvers(): Promise<Set<ResolverModule>> {
|
||||
return getResolvers()
|
||||
.catch(() => {
|
||||
return new Set();
|
||||
})
|
||||
.then((resolvers: string[]) => {
|
||||
return new Set(
|
||||
resolvers.map((resolver) => new ResolverModule(this, resolver))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public async resolve(
|
||||
domain: string,
|
||||
options: ResolverOptions = { type: DNS_RECORD_TYPE.DEFAULT },
|
||||
|
@ -35,4 +48,31 @@ export class ResolverRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
export class ResolverModule {
|
||||
private resolver: ResolverRegistry;
|
||||
private domain: string;
|
||||
|
||||
constructor(resolver: ResolverRegistry, domain: string) {
|
||||
this.resolver = resolver;
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
async resolve(
|
||||
domain: string,
|
||||
options: ResolverOptions,
|
||||
bypassCache: boolean
|
||||
): Promise<DNSResult> {
|
||||
const [ret, err] = await callModule(this.domain, "resolve", {
|
||||
domain,
|
||||
options,
|
||||
bypassCache,
|
||||
});
|
||||
if (err) {
|
||||
return resolverError(err);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
export { RpcNetwork };
|
||||
|
|
Loading…
Reference in New Issue