Compare commits
No commits in common. "6f6a79599c7f7fdf5037d8514f246f929245e977" and "e0a846524923ae5f7c7352caabe44263fa52bc20" have entirely different histories.
6f6a79599c
...
e0a8465249
|
@ -1,19 +1,6 @@
|
||||||
import type { DNSResult } from "@lumeweb/libresolver";
|
import { ResolverModuleConstructor } from "./resolverRegistry.js";
|
||||||
import { DnsClient } from "@lumeweb/kernel-dns-client";
|
export declare function setup(rm: ResolverModuleConstructor): void;
|
||||||
import { ResolverOptions } from "@lumeweb/libresolver/src/types.js";
|
export * from "./resolverRegistry.js";
|
||||||
export interface ResolverModule {
|
|
||||||
get resolver(): DnsClient;
|
|
||||||
set resolver(value: DnsClient);
|
|
||||||
resolve(
|
|
||||||
domain: string,
|
|
||||||
options: ResolverOptions,
|
|
||||||
bypassCache: boolean
|
|
||||||
): Promise<DNSResult>;
|
|
||||||
getSupportedTlds(): string[];
|
|
||||||
getSupportedTlds(): Promise<string[]>;
|
|
||||||
getSupportedTlds(): any;
|
|
||||||
}
|
|
||||||
export declare function setup(rm: ResolverModule): void;
|
|
||||||
export * from "@lumeweb/libresolver/dist/util.js";
|
export * from "@lumeweb/libresolver/dist/util.js";
|
||||||
export * from "@lumeweb/libresolver/dist/types.js";
|
export * from "@lumeweb/libresolver/dist/types.js";
|
||||||
export { AbstractResolverModule } from "@lumeweb/libresolver/dist/resolverModule.js";
|
export { AbstractResolverModule } from "@lumeweb/libresolver/dist/resolverModule.js";
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { addHandler, handleMessage } from "libkmodule";
|
import { addHandler, handleMessage } from "libkmodule";
|
||||||
|
import { ResolverRegistry, } from "./resolverRegistry.js";
|
||||||
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
|
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
|
||||||
import { dnsClient } from "./client.js";
|
import { dnsClient } from "./client.js";
|
||||||
let resolver;
|
let resolver;
|
||||||
|
@ -7,8 +8,7 @@ export function setup(rm) {
|
||||||
addHandler("register", handleRegister);
|
addHandler("register", handleRegister);
|
||||||
addHandler("getSupportedTlds", handleGetSupportedTlds);
|
addHandler("getSupportedTlds", handleGetSupportedTlds);
|
||||||
onmessage = handleMessage;
|
onmessage = handleMessage;
|
||||||
resolver = rm;
|
resolver = new rm(new ResolverRegistry());
|
||||||
resolver.resolver = dnsClient;
|
|
||||||
}
|
}
|
||||||
async function handleRegister(aq) {
|
async function handleRegister(aq) {
|
||||||
await dnsClient.register();
|
await dnsClient.register();
|
||||||
|
@ -36,6 +36,7 @@ async function handleResolve(aq) {
|
||||||
function handleGetSupportedTlds(aq) {
|
function handleGetSupportedTlds(aq) {
|
||||||
aq.respond(resolver.getSupportedTlds());
|
aq.respond(resolver.getSupportedTlds());
|
||||||
}
|
}
|
||||||
|
export * from "./resolverRegistry.js";
|
||||||
export * from "@lumeweb/libresolver/dist/util.js";
|
export * from "@lumeweb/libresolver/dist/util.js";
|
||||||
export * from "@lumeweb/libresolver/dist/types.js";
|
export * from "@lumeweb/libresolver/dist/types.js";
|
||||||
export { AbstractResolverModule } from "@lumeweb/libresolver/dist/resolverModule.js";
|
export { AbstractResolverModule } from "@lumeweb/libresolver/dist/resolverModule.js";
|
||||||
|
|
32
src/index.ts
32
src/index.ts
|
@ -1,37 +1,22 @@
|
||||||
import { addHandler, ActiveQuery, handleMessage } from "libkmodule";
|
import { addHandler, ActiveQuery, handleMessage } from "libkmodule";
|
||||||
|
|
||||||
import type {
|
import type { DNSResult } from "@lumeweb/libresolver";
|
||||||
DNSResult,
|
import {
|
||||||
ResolverModule as ResolverModuleBase,
|
ResolverModule,
|
||||||
} from "@lumeweb/libresolver";
|
ResolverModuleConstructor,
|
||||||
|
ResolverRegistry,
|
||||||
|
} from "./resolverRegistry.js";
|
||||||
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
|
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
|
||||||
import { dnsClient } from "./client.js";
|
import { dnsClient } from "./client.js";
|
||||||
import { DnsClient } from "@lumeweb/kernel-dns-client";
|
|
||||||
import { ResolverOptions } from "@lumeweb/libresolver/src/types.js";
|
|
||||||
|
|
||||||
let resolver: ResolverModule;
|
let resolver: ResolverModule;
|
||||||
|
|
||||||
export interface ResolverModule {
|
export function setup(rm: ResolverModuleConstructor) {
|
||||||
get resolver(): DnsClient;
|
|
||||||
set resolver(value: DnsClient);
|
|
||||||
resolve(
|
|
||||||
domain: string,
|
|
||||||
options: ResolverOptions,
|
|
||||||
bypassCache: boolean
|
|
||||||
): Promise<DNSResult>;
|
|
||||||
|
|
||||||
getSupportedTlds(): string[];
|
|
||||||
getSupportedTlds(): Promise<string[]>;
|
|
||||||
getSupportedTlds(): any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setup(rm: ResolverModule) {
|
|
||||||
addHandler("resolve", handleResolve);
|
addHandler("resolve", handleResolve);
|
||||||
addHandler("register", handleRegister);
|
addHandler("register", handleRegister);
|
||||||
addHandler("getSupportedTlds", handleGetSupportedTlds);
|
addHandler("getSupportedTlds", handleGetSupportedTlds);
|
||||||
onmessage = handleMessage;
|
onmessage = handleMessage;
|
||||||
resolver = rm;
|
resolver = new rm(new ResolverRegistry());
|
||||||
resolver.resolver = dnsClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleRegister(aq: ActiveQuery) {
|
async function handleRegister(aq: ActiveQuery) {
|
||||||
|
@ -69,6 +54,7 @@ function handleGetSupportedTlds(aq: ActiveQuery) {
|
||||||
aq.respond(resolver.getSupportedTlds());
|
aq.respond(resolver.getSupportedTlds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * from "./resolverRegistry.js";
|
||||||
export * from "@lumeweb/libresolver/dist/util.js";
|
export * from "@lumeweb/libresolver/dist/util.js";
|
||||||
export * from "@lumeweb/libresolver/dist/types.js";
|
export * from "@lumeweb/libresolver/dist/types.js";
|
||||||
export { AbstractResolverModule } from "@lumeweb/libresolver/dist/resolverModule.js";
|
export { AbstractResolverModule } from "@lumeweb/libresolver/dist/resolverModule.js";
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
import {
|
||||||
|
DNSResult,
|
||||||
|
ResolverOptions,
|
||||||
|
DNS_RECORD_TYPE,
|
||||||
|
resolverError,
|
||||||
|
ResolverModuleConstructor as ResolverModuleConstructorBase,
|
||||||
|
} from "@lumeweb/libresolver";
|
||||||
|
import { Client, factory } from "@lumeweb/libkernel-universal";
|
||||||
|
import { dnsClient } from "./client.js";
|
||||||
|
|
||||||
|
export interface ResolverModuleConstructor
|
||||||
|
extends ResolverModuleConstructorBase {
|
||||||
|
new (resolver: ResolverRegistry): ResolverModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ResolverRegistry {
|
||||||
|
get resolvers(): Promise<Set<ResolverModule>> {
|
||||||
|
return dnsClient
|
||||||
|
.getResolvers()
|
||||||
|
.then((resolvers: string[]) => {
|
||||||
|
return new Set(
|
||||||
|
resolvers.map((resolver) =>
|
||||||
|
factory<ResolverModule>(ResolverModule, resolver)(this, resolver)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
return new Set();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async resolve(
|
||||||
|
domain: string,
|
||||||
|
options: ResolverOptions = { type: DNS_RECORD_TYPE.CONTENT },
|
||||||
|
bypassCache: boolean = false
|
||||||
|
): Promise<DNSResult> {
|
||||||
|
try {
|
||||||
|
return dnsClient.resolve(domain, options, bypassCache);
|
||||||
|
} catch (e: any) {
|
||||||
|
return resolverError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public register(resolver: ResolverModule): void {}
|
||||||
|
public clear(): void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ResolverModule extends Client {
|
||||||
|
private resolver: ResolverRegistry;
|
||||||
|
private domain: string;
|
||||||
|
|
||||||
|
constructor(resolver: ResolverRegistry, domain: string) {
|
||||||
|
super();
|
||||||
|
this.resolver = resolver;
|
||||||
|
this.domain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
async resolve(
|
||||||
|
domain: string,
|
||||||
|
options: ResolverOptions,
|
||||||
|
bypassCache: boolean
|
||||||
|
): Promise<DNSResult> {
|
||||||
|
try {
|
||||||
|
return this.callModuleReturn("resolve", {
|
||||||
|
domain,
|
||||||
|
options,
|
||||||
|
bypassCache,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return resolverError(e as Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async getSupportedTlds(): Promise<string[]> {
|
||||||
|
return this.callModuleReturn("getSupportedTlds");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue