*Initial version

This commit is contained in:
Derrick Hammer 2022-08-18 17:58:00 -04:00
parent 7ef8dbfdde
commit 183199247d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 65 additions and 1 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022 Lume Web
Copyright (c) 2022 Hammer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

9
package.json Normal file
View File

@ -0,0 +1,9 @@
{
"name": "@lumeweb/kernel-resolver-common",
"version": "0.1.0",
"dependencies": {
"@lumeweb/kernel-dns-client": "github:LumeWeb/kernel-dns-client",
"@lumeweb/resolver-common": "github:LumeWeb/resolver-common",
"libkmodule": "^0.2.51"
}
}

43
src/index.ts Normal file
View File

@ -0,0 +1,43 @@
import { addHandler, ActiveQuery, handleMessage } from "libkmodule";
import { register } from "@lumeweb/kernel-dns-client";
import type { DNSResult, ResolverModule } from "@lumeweb/resolver-common";
let resolver: ResolverModule;
export function setup(rm: ResolverModule) {
addHandler("resolve", handleResolve);
addHandler("register", handleRegister);
onmessage = handleMessage;
resolver = rm;
}
async function handleRegister(aq: ActiveQuery) {
await register();
aq.respond();
}
async function handleResolve(aq: ActiveQuery) {
if (!("domain" in aq.callerInput)) {
aq.reject("domain required");
return;
}
let ret: DNSResult;
try {
ret = await resolver.resolve(
aq.callerInput.domain,
aq.callerInput?.options ?? {},
aq.callerInput?.bypassCache || false
);
} catch (e: any) {
aq.reject(e);
return;
}
if (ret.error) {
aq.reject(ret.error as any);
return;
}
aq.respond(ret);
}

12
tsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "esnext",
"declaration": true,
"moduleResolution": "node",
"outDir": "./dist",
"strict": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}