Compare commits
No commits in common. "e8954d7fe9deba5ae593605ef427b3d3f1cc3db9" and "cf3f54f2ee8c69b6656f1a179945e92e017b54e0" have entirely different histories.
e8954d7fe9
...
cf3f54f2ee
|
@ -1,3 +1,3 @@
|
||||||
import { ResolverModuleConstructor } from "./resolverRegistry.js";
|
import type { ResolverModuleConstructor } from "@lumeweb/resolver-common";
|
||||||
export declare function setup(rm: ResolverModuleConstructor): void;
|
export declare function setup(rm: ResolverModuleConstructor): void;
|
||||||
export * from "./resolverRegistry.js";
|
export * from "./resolverRegistry.js";
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import { addHandler, handleMessage } from "libkmodule";
|
import { addHandler, handleMessage } from "libkmodule";
|
||||||
import { ResolverRegistry, } from "./resolverRegistry.js";
|
import { register } from "@lumeweb/kernel-dns-client";
|
||||||
|
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());
|
resolver = new rm(new ResolverRegistry(new RpcNetwork()));
|
||||||
}
|
}
|
||||||
async function handleRegister(aq) {
|
async function handleRegister(aq) {
|
||||||
await dnsClient.register();
|
await register();
|
||||||
aq.respond();
|
aq.respond();
|
||||||
}
|
}
|
||||||
async function handleResolve(aq) {
|
async function handleResolve(aq) {
|
||||||
|
|
|
@ -1,24 +1,17 @@
|
||||||
import {
|
import { DNSResult, ResolverOptions } from "@lumeweb/resolver-common";
|
||||||
DNSResult,
|
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
|
||||||
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 extends Client {
|
export declare class ResolverModule {
|
||||||
private resolver;
|
private resolver;
|
||||||
private domain;
|
private domain;
|
||||||
constructor(resolver: ResolverRegistry, domain: string);
|
constructor(resolver: ResolverRegistry, domain: string);
|
||||||
|
@ -29,3 +22,4 @@ export declare class ResolverModule extends Client {
|
||||||
): Promise<DNSResult>;
|
): Promise<DNSResult>;
|
||||||
getSupportedTlds(): Promise<string[]>;
|
getSupportedTlds(): Promise<string[]>;
|
||||||
}
|
}
|
||||||
|
export { RpcNetwork };
|
||||||
|
|
|
@ -1,49 +1,59 @@
|
||||||
import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/libresolver";
|
import { DNS_RECORD_TYPE, resolverError, } from "@lumeweb/resolver-common";
|
||||||
import { Client, factory } from "@lumeweb/libkernel-universal";
|
import { getResolvers, resolve } from "@lumeweb/kernel-dns-client";
|
||||||
import { dnsClient } from "./client.js";
|
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
|
||||||
|
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 dnsClient
|
return getResolvers()
|
||||||
.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 {
|
||||||
return dnsClient.resolve(domain, options, bypassCache);
|
result = await resolve(domain, options, bypassCache);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return resolverError(e);
|
return resolverError(e);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
register(resolver) { }
|
|
||||||
clear() { }
|
|
||||||
}
|
}
|
||||||
export class ResolverModule extends Client {
|
export class ResolverModule {
|
||||||
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) {
|
||||||
try {
|
const [ret, err] = await callModule(this.domain, "resolve", {
|
||||||
return this.callModuleReturn("resolve", {
|
domain,
|
||||||
domain,
|
options,
|
||||||
options,
|
bypassCache,
|
||||||
bypassCache,
|
});
|
||||||
});
|
if (err) {
|
||||||
}
|
return resolverError(err);
|
||||||
catch (e) {
|
|
||||||
return resolverError(e);
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async getSupportedTlds() {
|
async getSupportedTlds() {
|
||||||
return this.callModuleReturn("getSupportedTlds");
|
const [ret, err] = await callModule(this.domain, "getSupportedTlds");
|
||||||
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export { RpcNetwork };
|
||||||
|
|
16
package.json
16
package.json
|
@ -3,17 +3,13 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/kernel-dns-client": "git+https://git.lumeweb.com/LumeWeb/kernel-dns-client.git",
|
"@lumeweb/kernel-dns-client": "https://github.com/LumeWeb/kernel-dns-client.git",
|
||||||
"@lumeweb/kernel-libresolver": "git+https://git.lumeweb.com/LumeWeb/kernel-libresolver.git",
|
"@lumeweb/kernel-rpc-client": "https://github.com/LumeWeb/kernel-rpc-client.git",
|
||||||
"@lumeweb/kernel-rpc-client": "git+https://git.lumeweb.com/LumeWeb/kernel-rpc-client.git",
|
"@lumeweb/libresolver": "https://github.com/LumeWeb/libresolver.git",
|
||||||
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
|
"libkmodule": "^0.2.51"
|
||||||
"@lumeweb/libresolver": "git+https://git.lumeweb.com/LumeWeb/libresolver.git",
|
|
||||||
"libkmodule": "^0.2.53"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lumeweb/relay-types": "git+https://git.lumeweb.com/LumeWeb/relay-types.git",
|
"@lumeweb/relay-types": "https://github.com/LumeWeb/relay-types.git",
|
||||||
"@types/node": "^18.14.0",
|
"@types/node": "^18.7.14"
|
||||||
"prettier": "^2.8.4",
|
|
||||||
"typescript": "^4.9.5"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
import { createClient } from "@lumeweb/kernel-dns-client";
|
|
||||||
|
|
||||||
export const dnsClient = createClient();
|
|
18
src/index.ts
18
src/index.ts
|
@ -1,13 +1,13 @@
|
||||||
import { addHandler, ActiveQuery, handleMessage } from "libkmodule";
|
import { addHandler, ActiveQuery, handleMessage } from "libkmodule";
|
||||||
|
import { register } from "@lumeweb/kernel-dns-client";
|
||||||
import type { DNSResult } from "@lumeweb/libresolver";
|
import type {
|
||||||
import {
|
DNSResult,
|
||||||
ResolverModule,
|
|
||||||
ResolverModuleConstructor,
|
ResolverModuleConstructor,
|
||||||
ResolverRegistry,
|
ResolverModule,
|
||||||
} from "./resolverRegistry.js";
|
} from "@lumeweb/resolver-common";
|
||||||
|
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: ResolverModule;
|
let resolver: ResolverModule;
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ export function setup(rm: ResolverModuleConstructor) {
|
||||||
addHandler("register", handleRegister);
|
addHandler("register", handleRegister);
|
||||||
addHandler("getSupportedTlds", handleGetSupportedTlds);
|
addHandler("getSupportedTlds", handleGetSupportedTlds);
|
||||||
onmessage = handleMessage;
|
onmessage = handleMessage;
|
||||||
resolver = new rm(new ResolverRegistry());
|
resolver = new rm(new ResolverRegistry(new RpcNetwork()) as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleRegister(aq: ActiveQuery) {
|
async function handleRegister(aq: ActiveQuery) {
|
||||||
await dnsClient.register();
|
await register();
|
||||||
aq.respond();
|
aq.respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,29 +3,31 @@ import {
|
||||||
ResolverOptions,
|
ResolverOptions,
|
||||||
DNS_RECORD_TYPE,
|
DNS_RECORD_TYPE,
|
||||||
resolverError,
|
resolverError,
|
||||||
ResolverModuleConstructor as ResolverModuleConstructorBase,
|
} from "@lumeweb/resolver-common";
|
||||||
} 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 interface ResolverModuleConstructor
|
|
||||||
extends ResolverModuleConstructorBase {
|
|
||||||
new (resolver: ResolverRegistry): ResolverModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ResolverRegistry {
|
export class ResolverRegistry {
|
||||||
|
private _rpcNetwork: RpcNetwork;
|
||||||
|
|
||||||
|
constructor(network: RpcNetwork) {
|
||||||
|
this._rpcNetwork = network;
|
||||||
|
}
|
||||||
|
|
||||||
|
get rpcNetwork(): RpcNetwork {
|
||||||
|
return this._rpcNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
get resolvers(): Promise<Set<ResolverModule>> {
|
get resolvers(): Promise<Set<ResolverModule>> {
|
||||||
return dnsClient
|
return getResolvers()
|
||||||
.getResolvers()
|
|
||||||
.then((resolvers: string[]) => {
|
|
||||||
return new Set(
|
|
||||||
resolvers.map((resolver) =>
|
|
||||||
factory<ResolverModule>(ResolverModule, resolver)(this, resolver)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
return new Set();
|
return new Set();
|
||||||
|
})
|
||||||
|
.then((resolvers: string[]) => {
|
||||||
|
return new Set(
|
||||||
|
resolvers.map((resolver) => new ResolverModule(this, resolver))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,22 +36,23 @@ export class ResolverRegistry {
|
||||||
options: ResolverOptions = { type: DNS_RECORD_TYPE.CONTENT },
|
options: ResolverOptions = { type: DNS_RECORD_TYPE.CONTENT },
|
||||||
bypassCache: boolean = false
|
bypassCache: boolean = false
|
||||||
): Promise<DNSResult> {
|
): Promise<DNSResult> {
|
||||||
|
let result: DNSResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return dnsClient.resolve(domain, options, bypassCache);
|
result = await resolve(domain, options, bypassCache);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return resolverError(e);
|
return resolverError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
public register(resolver: ResolverModule): void {}
|
|
||||||
public clear(): void {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ResolverModule extends Client {
|
export class ResolverModule {
|
||||||
private resolver: ResolverRegistry;
|
private resolver: ResolverRegistry;
|
||||||
private domain: string;
|
private domain: string;
|
||||||
|
|
||||||
constructor(resolver: ResolverRegistry, domain: string) {
|
constructor(resolver: ResolverRegistry, domain: string) {
|
||||||
super();
|
|
||||||
this.resolver = resolver;
|
this.resolver = resolver;
|
||||||
this.domain = domain;
|
this.domain = domain;
|
||||||
}
|
}
|
||||||
|
@ -59,17 +62,25 @@ export class ResolverModule extends Client {
|
||||||
options: ResolverOptions,
|
options: ResolverOptions,
|
||||||
bypassCache: boolean
|
bypassCache: boolean
|
||||||
): Promise<DNSResult> {
|
): Promise<DNSResult> {
|
||||||
try {
|
const [ret, err] = await callModule(this.domain, "resolve", {
|
||||||
return this.callModuleReturn("resolve", {
|
domain,
|
||||||
domain,
|
options,
|
||||||
options,
|
bypassCache,
|
||||||
bypassCache,
|
});
|
||||||
});
|
if (err) {
|
||||||
} catch (e) {
|
return resolverError(err);
|
||||||
return resolverError(e as Error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async getSupportedTlds(): Promise<string[]> {
|
async getSupportedTlds(): Promise<string[]> {
|
||||||
return this.callModuleReturn("getSupportedTlds");
|
const [ret, err] = await callModule(this.domain, "getSupportedTlds");
|
||||||
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { RpcNetwork };
|
||||||
|
|
Loading…
Reference in New Issue