From c329921aa403b65cb5938a8ea421bdbe3796541a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 15 Jul 2023 04:22:59 -0400 Subject: [PATCH] feat: add ready to setup --- src/index.ts | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3bd358e..d8c1975 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,38 +4,17 @@ import { handleMessage, } from "@lumeweb/libkernel/module"; -import type { - DNSResult, - ResolverModule as ResolverModuleBase, -} from "@lumeweb/libresolver"; +import type { DNSResult } from "@lumeweb/libresolver"; import { DNS_RECORD_TYPE } from "@lumeweb/libresolver"; import { dnsClient } from "./client.js"; -import { DnsClient } from "@lumeweb/kernel-dns-client"; -import type { ResolverOptions } from "@lumeweb/libresolver"; +import { ResolverModule } from "@lumeweb/kernel-dns-client"; -let resolver: ResolverModule | ResolverModuleBase; +let resolver: ResolverModule; -export interface ResolverModule { - get resolver(): DnsClient; - - set resolver(value: DnsClient); - - resolve( - domain: string, - options: ResolverOptions, - bypassCache: boolean, - ): Promise; - - getSupportedTlds(): string[]; - - getSupportedTlds(): Promise; - - getSupportedTlds(): any; -} - -export function setup(rm: ResolverModule | ResolverModuleBase) { +export function setup(rm: ResolverModule) { addHandler("resolve", handleResolve); addHandler("register", handleRegister); + addHandler("ready", handleReady); addHandler("getSupportedTlds", handleGetSupportedTlds); onmessage = handleMessage; resolver = rm; @@ -78,6 +57,12 @@ function handleGetSupportedTlds(aq: ActiveQuery) { aq.respond(resolver.getSupportedTlds()); } +async function handleReady(aq: ActiveQuery) { + await resolver.ready(); + + aq.respond(); +} + export * from "@lumeweb/libresolver/lib/util.js"; export * from "@lumeweb/libresolver/lib/types.js"; export { AbstractResolverModule } from "@lumeweb/libresolver/lib/resolverModule.js";