feat: add ready to setup
This commit is contained in:
parent
9fa4e3eb12
commit
c329921aa4
37
src/index.ts
37
src/index.ts
|
@ -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";
|
||||||
|
|
Loading…
Reference in New Issue