feat: add ready to setup

This commit is contained in:
Derrick Hammer 2023-07-15 04:22:59 -04:00
parent 9fa4e3eb12
commit c329921aa4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 26 deletions

View File

@ -4,38 +4,17 @@ import {
handleMessage, handleMessage,
} from "@lumeweb/libkernel/module"; } from "@lumeweb/libkernel/module";
import type { import type { DNSResult } from "@lumeweb/libresolver";
DNSResult,
ResolverModule as ResolverModuleBase,
} from "@lumeweb/libresolver";
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver"; import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
import { dnsClient } from "./client.js"; import { dnsClient } from "./client.js";
import { DnsClient } from "@lumeweb/kernel-dns-client"; import { ResolverModule } from "@lumeweb/kernel-dns-client";
import type { ResolverOptions } from "@lumeweb/libresolver";
let resolver: ResolverModule | ResolverModuleBase; let resolver: ResolverModule;
export interface ResolverModule { export function setup(rm: ResolverModule) {
get resolver(): DnsClient;
set resolver(value: DnsClient);
resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean,
): Promise<DNSResult>;
getSupportedTlds(): string[];
getSupportedTlds(): Promise<string[]>;
getSupportedTlds(): any;
}
export function setup(rm: ResolverModule | ResolverModuleBase) {
addHandler("resolve", handleResolve); addHandler("resolve", handleResolve);
addHandler("register", handleRegister); addHandler("register", handleRegister);
addHandler("ready", handleReady);
addHandler("getSupportedTlds", handleGetSupportedTlds); addHandler("getSupportedTlds", handleGetSupportedTlds);
onmessage = handleMessage; onmessage = handleMessage;
resolver = rm; resolver = rm;
@ -78,6 +57,12 @@ function handleGetSupportedTlds(aq: ActiveQuery) {
aq.respond(resolver.getSupportedTlds()); 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/util.js";
export * from "@lumeweb/libresolver/lib/types.js"; export * from "@lumeweb/libresolver/lib/types.js";
export { AbstractResolverModule } from "@lumeweb/libresolver/lib/resolverModule.js"; export { AbstractResolverModule } from "@lumeweb/libresolver/lib/resolverModule.js";