*Initial version
This commit is contained in:
parent
7ef8dbfdde
commit
183199247d
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "esnext",
|
||||||
|
"declaration": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"strict": true,
|
||||||
|
"allowSyntheticDefaultImports": true
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["node_modules", "**/__tests__/*"]
|
||||||
|
}
|
Loading…
Reference in New Issue