kernel-libresolver/dist/resolverRegistry.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-02-19 22:17:14 +00:00
import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/libresolver";
import { Client, factory } from "@lumeweb/libkernel-universal";
import { dnsClient } from "./client.js";
2022-08-18 22:28:56 +00:00
export class ResolverRegistry {
2022-08-19 13:57:34 +00:00
get resolvers() {
2023-02-19 22:17:14 +00:00
return dnsClient
.getResolvers()
.then((resolvers) => {
return new Set(resolvers.map((resolver) => factory(ResolverModule, resolver)(this, resolver)));
})
2022-08-19 13:57:34 +00:00
.catch(() => {
return new Set();
});
}
2022-08-20 06:57:45 +00:00
async resolve(domain, options = { type: DNS_RECORD_TYPE.CONTENT }, bypassCache = false) {
2022-08-18 22:28:56 +00:00
try {
2023-02-19 22:17:14 +00:00
return dnsClient.resolve(domain, options, bypassCache);
2022-08-18 22:28:56 +00:00
}
catch (e) {
return resolverError(e);
}
}
2023-02-19 22:17:14 +00:00
register(resolver) { }
clear() { }
2022-08-18 22:28:56 +00:00
}
2023-02-19 22:17:14 +00:00
export class ResolverModule extends Client {
2022-08-19 13:57:34 +00:00
resolver;
domain;
constructor(resolver, domain) {
2023-02-19 22:17:14 +00:00
super();
2022-08-19 13:57:34 +00:00
this.resolver = resolver;
this.domain = domain;
}
async resolve(domain, options, bypassCache) {
2023-02-19 22:17:14 +00:00
try {
return this.callModuleReturn("resolve", {
domain,
options,
bypassCache,
});
}
catch (e) {
return resolverError(e);
2022-08-19 13:57:34 +00:00
}
}
2022-08-19 15:21:13 +00:00
async getSupportedTlds() {
2023-02-19 22:17:14 +00:00
return this.callModuleReturn("getSupportedTlds");
2022-08-19 15:21:13 +00:00
}
2022-08-19 13:57:34 +00:00
}