diff --git a/dist/index.d.ts b/dist/index.d.ts index a1fbefc..aed4123 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,3 +1,3 @@ -import type { ResolverModuleConstructor } from "@lumeweb/resolver-common"; +import { ResolverModuleConstructor } from "./resolverRegistry.js"; export declare function setup(rm: ResolverModuleConstructor): void; export * from "./resolverRegistry.js"; diff --git a/dist/index.js b/dist/index.js index e31191b..82c8a35 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,18 +1,17 @@ import { addHandler, handleMessage } from "libkmodule"; -import { register } from "@lumeweb/kernel-dns-client"; -import { RpcNetwork } from "@lumeweb/kernel-rpc-client"; -import { ResolverRegistry } from "./resolverRegistry.js"; +import { ResolverRegistry, } from "./resolverRegistry.js"; import { DNS_RECORD_TYPE } from "@lumeweb/libresolver"; +import { dnsClient } from "./client.js"; let resolver; export function setup(rm) { addHandler("resolve", handleResolve); addHandler("register", handleRegister); addHandler("getSupportedTlds", handleGetSupportedTlds); onmessage = handleMessage; - resolver = new rm(new ResolverRegistry(new RpcNetwork())); + resolver = new rm(new ResolverRegistry()); } async function handleRegister(aq) { - await register(); + await dnsClient.register(); aq.respond(); } async function handleResolve(aq) { diff --git a/dist/resolverRegistry.d.ts b/dist/resolverRegistry.d.ts index dcbc0a9..29f2b8f 100644 --- a/dist/resolverRegistry.d.ts +++ b/dist/resolverRegistry.d.ts @@ -1,17 +1,24 @@ -import { DNSResult, ResolverOptions } from "@lumeweb/resolver-common"; -import { RpcNetwork } from "@lumeweb/kernel-rpc-client"; +import { + DNSResult, + ResolverOptions, + ResolverModuleConstructor as ResolverModuleConstructorBase, +} from "@lumeweb/libresolver"; +import { Client } from "@lumeweb/libkernel-universal"; +export interface ResolverModuleConstructor + extends ResolverModuleConstructorBase { + new (resolver: ResolverRegistry): ResolverModule; +} export declare class ResolverRegistry { - private _rpcNetwork; - constructor(network: RpcNetwork); - get rpcNetwork(): RpcNetwork; get resolvers(): Promise>; resolve( domain: string, options?: ResolverOptions, bypassCache?: boolean ): Promise; + register(resolver: ResolverModule): void; + clear(): void; } -export declare class ResolverModule { +export declare class ResolverModule extends Client { private resolver; private domain; constructor(resolver: ResolverRegistry, domain: string); @@ -22,4 +29,3 @@ export declare class ResolverModule { ): Promise; getSupportedTlds(): Promise; } -export { RpcNetwork }; diff --git a/dist/resolverRegistry.js b/dist/resolverRegistry.js index 9e23aa4..0cf89e5 100644 --- a/dist/resolverRegistry.js +++ b/dist/resolverRegistry.js @@ -1,59 +1,49 @@ -import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/resolver-common"; -import { getResolvers, resolve } from "@lumeweb/kernel-dns-client"; -import { RpcNetwork } from "@lumeweb/kernel-rpc-client"; -import { callModule } from "libkmodule"; +import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/libresolver"; +import { Client, factory } from "@lumeweb/libkernel-universal"; +import { dnsClient } from "./client.js"; export class ResolverRegistry { - _rpcNetwork; - constructor(network) { - this._rpcNetwork = network; - } - get rpcNetwork() { - return this._rpcNetwork; - } get resolvers() { - return getResolvers() + return dnsClient + .getResolvers() + .then((resolvers) => { + return new Set(resolvers.map((resolver) => factory(ResolverModule, resolver)(this, resolver))); + }) .catch(() => { return new Set(); - }) - .then((resolvers) => { - return new Set(resolvers.map((resolver) => new ResolverModule(this, resolver))); }); } async resolve(domain, options = { type: DNS_RECORD_TYPE.CONTENT }, bypassCache = false) { - let result; try { - result = await resolve(domain, options, bypassCache); + return dnsClient.resolve(domain, options, bypassCache); } catch (e) { return resolverError(e); } - return result; } + register(resolver) { } + clear() { } } -export class ResolverModule { +export class ResolverModule extends Client { resolver; domain; constructor(resolver, domain) { + super(); this.resolver = resolver; this.domain = domain; } async resolve(domain, options, bypassCache) { - const [ret, err] = await callModule(this.domain, "resolve", { - domain, - options, - bypassCache, - }); - if (err) { - return resolverError(err); + try { + return this.callModuleReturn("resolve", { + domain, + options, + bypassCache, + }); + } + catch (e) { + return resolverError(e); } - return ret; } async getSupportedTlds() { - const [ret, err] = await callModule(this.domain, "getSupportedTlds"); - if (err) { - throw new Error(err); - } - return ret; + return this.callModuleReturn("getSupportedTlds"); } } -export { RpcNetwork };