diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..d803700 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,2 @@ +import type { ResolverModule } from "@lumeweb/resolver-common"; +export declare function setup(rm: ResolverModule): void; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..87e384c --- /dev/null +++ b/dist/index.js @@ -0,0 +1,32 @@ +import { addHandler, handleMessage } from "libkmodule"; +import { register } from "@lumeweb/kernel-dns-client"; +let resolver; +export function setup(rm) { + addHandler("resolve", handleResolve); + addHandler("register", handleRegister); + onmessage = handleMessage; + resolver = rm; +} +async function handleRegister(aq) { + await register(); + aq.respond(); +} +async function handleResolve(aq) { + if (!("domain" in aq.callerInput)) { + aq.reject("domain required"); + return; + } + let ret; + try { + ret = await resolver.resolve(aq.callerInput.domain, aq.callerInput?.options ?? {}, aq.callerInput?.bypassCache || false); + } + catch (e) { + aq.reject(e); + return; + } + if (ret.error) { + aq.reject(ret.error); + return; + } + aq.respond(ret); +}