Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer 3f96c6d1de
*Update dist 2023-02-19 16:21:12 -05:00
Derrick Hammer 5a2c703afe
*rewrite for new system 2023-02-19 16:20:38 -05:00
2 changed files with 17 additions and 67 deletions

View File

@ -4,13 +4,14 @@
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",
"dependencies": { "dependencies": {
"@lumeweb/resolver-common": "github:LumeWeb/resolver-common", "@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
"libkernel": "^0.1.43", "libkernel": "^0.1.43",
"libkmodule": "^0.2.44", "libkmodule": "^0.2.44",
"libskynet": "^0.0.62" "libskynet": "^0.0.62"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^18.0.6", "@types/node": "^18.0.6",
"prettier": "^2.7.1" "prettier": "^2.7.1",
"typescript": "^4.9.5"
} }
} }

View File

@ -1,71 +1,20 @@
import { DNS_RECORD_TYPE, ResolverOptions } from "@lumeweb/resolver-common"; import { Client, factory } from "@lumeweb/libkernel-universal";
const DNS_MODULE = "AQBLKpieqOfKVRgMa8k45P4S_ILYgJmswVso4vT1qzoG-A"; const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA";
let callModule: any, connectModule: any; export class DnsClient extends Client {
public async register(): Promise<void> {
async function loadLibs() { return this.callModuleReturn("register");
if (callModule && connectModule) {
return;
} }
if (typeof window !== "undefined" && window?.document) { public async clear(): Promise<void> {
const pkg = await import("libkernel"); return this.callModuleReturn("clear");
callModule = pkg.callModule; }
connectModule = pkg.connectModule; public async getResolvers(): Promise<void> {
} else { return this.callModuleReturn("clear");
const pkg = await import("libkmodule"); }
callModule = pkg.callModule; public async ready(): Promise<void> {
connectModule = pkg.connectModule; return this.callModuleReturn("ready");
} }
} }
export async function resolve( export const createClient = factory<DnsClient>(DnsClient, MODULE);
domain: string,
options: ResolverOptions = { type: DNS_RECORD_TYPE.CONTENT },
bypassCache = false
) {
await loadLibs();
const [resp, err] = await callModule(DNS_MODULE, "resolve", {
domain,
options,
bypassCache,
});
if (err) {
throw new Error(err);
}
return resp;
}
export async function register() {
await loadLibs();
await callModule(DNS_MODULE, "register");
}
export async function clear() {
await loadLibs();
await callModule(DNS_MODULE, "clear");
}
export async function getResolvers() {
await loadLibs();
const [resp, err] = await callModule(DNS_MODULE, "getResolvers");
if (err) {
throw new Error(err);
}
return resp;
}
export async function ready() {
await loadLibs();
const [resp, err] = await callModule(DNS_MODULE, "ready");
if (err) {
throw new Error(err);
}
return resp;
}