*Update dist

This commit is contained in:
Derrick Hammer 2023-02-19 17:17:14 -05:00
parent 657131b6ff
commit e8954d7fe9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 41 additions and 46 deletions

2
dist/index.d.ts vendored
View File

@ -1,3 +1,3 @@
import type { ResolverModuleConstructor } from "@lumeweb/resolver-common";
import { ResolverModuleConstructor } from "./resolverRegistry.js";
export declare function setup(rm: ResolverModuleConstructor): void;
export * from "./resolverRegistry.js";

9
dist/index.js vendored
View File

@ -1,18 +1,17 @@
import { addHandler, handleMessage } from "libkmodule";
import { register } from "@lumeweb/kernel-dns-client";
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
import { ResolverRegistry } from "./resolverRegistry.js";
import { ResolverRegistry, } from "./resolverRegistry.js";
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
import { dnsClient } from "./client.js";
let resolver;
export function setup(rm) {
addHandler("resolve", handleResolve);
addHandler("register", handleRegister);
addHandler("getSupportedTlds", handleGetSupportedTlds);
onmessage = handleMessage;
resolver = new rm(new ResolverRegistry(new RpcNetwork()));
resolver = new rm(new ResolverRegistry());
}
async function handleRegister(aq) {
await register();
await dnsClient.register();
aq.respond();
}
async function handleResolve(aq) {

View File

@ -1,17 +1,24 @@
import { DNSResult, ResolverOptions } from "@lumeweb/resolver-common";
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
import {
DNSResult,
ResolverOptions,
ResolverModuleConstructor as ResolverModuleConstructorBase,
} from "@lumeweb/libresolver";
import { Client } from "@lumeweb/libkernel-universal";
export interface ResolverModuleConstructor
extends ResolverModuleConstructorBase {
new (resolver: ResolverRegistry): ResolverModule;
}
export declare class ResolverRegistry {
private _rpcNetwork;
constructor(network: RpcNetwork);
get rpcNetwork(): RpcNetwork;
get resolvers(): Promise<Set<ResolverModule>>;
resolve(
domain: string,
options?: ResolverOptions,
bypassCache?: boolean
): Promise<DNSResult>;
register(resolver: ResolverModule): void;
clear(): void;
}
export declare class ResolverModule {
export declare class ResolverModule extends Client {
private resolver;
private domain;
constructor(resolver: ResolverRegistry, domain: string);
@ -22,4 +29,3 @@ export declare class ResolverModule {
): Promise<DNSResult>;
getSupportedTlds(): Promise<string[]>;
}
export { RpcNetwork };

View File

@ -1,59 +1,49 @@
import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/resolver-common";
import { getResolvers, resolve } from "@lumeweb/kernel-dns-client";
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
import { callModule } from "libkmodule";
import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/libresolver";
import { Client, factory } from "@lumeweb/libkernel-universal";
import { dnsClient } from "./client.js";
export class ResolverRegistry {
_rpcNetwork;
constructor(network) {
this._rpcNetwork = network;
}
get rpcNetwork() {
return this._rpcNetwork;
}
get resolvers() {
return getResolvers()
return dnsClient
.getResolvers()
.then((resolvers) => {
return new Set(resolvers.map((resolver) => factory(ResolverModule, resolver)(this, resolver)));
})
.catch(() => {
return new Set();
})
.then((resolvers) => {
return new Set(resolvers.map((resolver) => new ResolverModule(this, resolver)));
});
}
async resolve(domain, options = { type: DNS_RECORD_TYPE.CONTENT }, bypassCache = false) {
let result;
try {
result = await resolve(domain, options, bypassCache);
return dnsClient.resolve(domain, options, bypassCache);
}
catch (e) {
return resolverError(e);
}
return result;
}
register(resolver) { }
clear() { }
}
export class ResolverModule {
export class ResolverModule extends Client {
resolver;
domain;
constructor(resolver, domain) {
super();
this.resolver = resolver;
this.domain = domain;
}
async resolve(domain, options, bypassCache) {
const [ret, err] = await callModule(this.domain, "resolve", {
domain,
options,
bypassCache,
});
if (err) {
return resolverError(err);
try {
return this.callModuleReturn("resolve", {
domain,
options,
bypassCache,
});
}
catch (e) {
return resolverError(e);
}
return ret;
}
async getSupportedTlds() {
const [ret, err] = await callModule(this.domain, "getSupportedTlds");
if (err) {
throw new Error(err);
}
return ret;
return this.callModuleReturn("getSupportedTlds");
}
}
export { RpcNetwork };