*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 declare function setup(rm: ResolverModuleConstructor): void;
export * from "./resolverRegistry.js"; export * from "./resolverRegistry.js";

9
dist/index.js vendored
View File

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

View File

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

View File

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