Compare commits

...

3 Commits

5 changed files with 73 additions and 5 deletions

4
dist/index.d.ts vendored
View File

@ -1,9 +1,10 @@
import { Client } from "@lumeweb/libkernel-universal"; import { Client } from "@lumeweb/libkernel-universal";
import { DNSResult, ResolverOptions } from "@lumeweb/libresolver"; import { DNSResult, ResolverOptions } from "@lumeweb/libresolver";
import { ResolverModule } from "./module.js";
export declare class DnsClient extends Client { export declare class DnsClient extends Client {
register(): Promise<void>; register(): Promise<void>;
clear(): Promise<void>; clear(): Promise<void>;
get resolvers(): Promise<string[]>; get resolvers(): Promise<Set<ResolverModule>>;
ready(): Promise<void>; ready(): Promise<void>;
resolve( resolve(
domain: string, domain: string,
@ -12,4 +13,5 @@ export declare class DnsClient extends Client {
): Promise<DNSResult>; ): Promise<DNSResult>;
} }
export declare const createClient: (...args: any) => DnsClient; export declare const createClient: (...args: any) => DnsClient;
export * from "./module.js";
//# sourceMappingURL=index.d.ts.map //# sourceMappingURL=index.d.ts.map

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAEL,SAAS,EACT,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAI9B,qBAAa,SAAU,SAAQ,MAAM;IACtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAGzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAGnC,IAAI,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAEjC;IACY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAGtB,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAmD,EAC5D,WAAW,GAAE,OAAe,GAC3B,OAAO,CAAC,SAAS,CAAC;CAGtB;AAED,eAAO,MAAM,YAAY,6BAAwC,CAAC"} {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAEL,SAAS,EACT,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAgB,cAAc,EAAE,MAAM,aAAa,CAAC;AAI3D,qBAAa,SAAU,SAAQ,MAAM;IACtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAGzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAGnC,IAAI,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAQ5C;IACY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAGtB,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAmD,EAC5D,WAAW,GAAE,OAAe,GAC3B,OAAO,CAAC,SAAS,CAAC;CAGtB;AAED,eAAO,MAAM,YAAY,6BAAwC,CAAC;AAClE,cAAc,aAAa,CAAC"}

8
dist/index.js vendored
View File

@ -1,5 +1,6 @@
import { Client, factory } from "@lumeweb/libkernel-universal"; import { Client, factory } from "@lumeweb/libkernel-universal";
import { DNS_RECORD_TYPE, } from "@lumeweb/libresolver"; import { DNS_RECORD_TYPE, } from "@lumeweb/libresolver";
import { createModule } from "./module.js";
const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA"; const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA";
export class DnsClient extends Client { export class DnsClient extends Client {
async register() { async register() {
@ -9,7 +10,11 @@ export class DnsClient extends Client {
return this.callModuleReturn("clear"); return this.callModuleReturn("clear");
} }
get resolvers() { get resolvers() {
return this.callModuleReturn("getResolvers"); return this.callModuleReturn("getResolvers").then((resolvers) => {
return new Set(resolvers.map((resolver) => {
return createModule(resolver, this);
}));
});
} }
async ready() { async ready() {
return this.callModuleReturn("ready"); return this.callModuleReturn("ready");
@ -19,3 +24,4 @@ export class DnsClient extends Client {
} }
} }
export const createClient = factory(DnsClient, MODULE); export const createClient = factory(DnsClient, MODULE);
export * from "./module.js";

View File

@ -4,6 +4,7 @@ import {
DNSResult, DNSResult,
ResolverOptions, ResolverOptions,
} from "@lumeweb/libresolver"; } from "@lumeweb/libresolver";
import { createModule, ResolverModule } from "./module.js";
const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA"; const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA";
@ -14,8 +15,14 @@ export class DnsClient extends Client {
public async clear(): Promise<void> { public async clear(): Promise<void> {
return this.callModuleReturn("clear"); return this.callModuleReturn("clear");
} }
get resolvers(): Promise<string[]> { get resolvers(): Promise<Set<ResolverModule>> {
return this.callModuleReturn("getResolvers"); return this.callModuleReturn("getResolvers").then((resolvers: string[]) => {
return new Set(
resolvers.map((resolver: string): ResolverModule => {
return createModule(resolver, this);
})
);
});
} }
public async ready(): Promise<void> { public async ready(): Promise<void> {
return this.callModuleReturn("ready"); return this.callModuleReturn("ready");
@ -30,3 +37,4 @@ export class DnsClient extends Client {
} }
export const createClient = factory<DnsClient>(DnsClient, MODULE); export const createClient = factory<DnsClient>(DnsClient, MODULE);
export * from "./module.js";

52
src/module.ts Normal file
View File

@ -0,0 +1,52 @@
import { Client, factory } from "@lumeweb/libkernel-universal";
import { DnsClient } from "./index.js";
import {
DNSResult,
resolverError,
ResolverOptions,
} from "@lumeweb/libresolver";
export class ResolverModule extends Client {
private domain: string;
constructor(domain: string, resolver?: DnsClient) {
super();
this._resolver = resolver;
this.domain = domain;
}
private _resolver?: DnsClient;
get resolver(): DnsClient {
return this._resolver as DnsClient;
}
set resolver(value: DnsClient) {
this._resolver = value;
}
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");
}
}
export const createModule = (
module: string,
client: DnsClient
): ResolverModule =>
factory<ResolverModule>(ResolverModule, module)(module, client);