Compare commits
3 Commits
dd1b25aa30
...
cf6435ef1e
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | cf6435ef1e | |
Derrick Hammer | 827505438d | |
Derrick Hammer | 2bf62cbd3e |
|
@ -1,9 +1,10 @@
|
|||
import { Client } from "@lumeweb/libkernel-universal";
|
||||
import { DNSResult, ResolverOptions } from "@lumeweb/libresolver";
|
||||
import { ResolverModule } from "./module.js";
|
||||
export declare class DnsClient extends Client {
|
||||
register(): Promise<void>;
|
||||
clear(): Promise<void>;
|
||||
get resolvers(): Promise<string[]>;
|
||||
get resolvers(): Promise<Set<ResolverModule>>;
|
||||
ready(): Promise<void>;
|
||||
resolve(
|
||||
domain: string,
|
||||
|
@ -12,4 +13,5 @@ export declare class DnsClient extends Client {
|
|||
): Promise<DNSResult>;
|
||||
}
|
||||
export declare const createClient: (...args: any) => DnsClient;
|
||||
export * from "./module.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
|
|
|
@ -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"}
|
|
@ -1,5 +1,6 @@
|
|||
import { Client, factory } from "@lumeweb/libkernel-universal";
|
||||
import { DNS_RECORD_TYPE, } from "@lumeweb/libresolver";
|
||||
import { createModule } from "./module.js";
|
||||
const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA";
|
||||
export class DnsClient extends Client {
|
||||
async register() {
|
||||
|
@ -9,7 +10,11 @@ export class DnsClient extends Client {
|
|||
return this.callModuleReturn("clear");
|
||||
}
|
||||
get resolvers() {
|
||||
return this.callModuleReturn("getResolvers");
|
||||
return this.callModuleReturn("getResolvers").then((resolvers) => {
|
||||
return new Set(resolvers.map((resolver) => {
|
||||
return createModule(resolver, this);
|
||||
}));
|
||||
});
|
||||
}
|
||||
async ready() {
|
||||
return this.callModuleReturn("ready");
|
||||
|
@ -19,3 +24,4 @@ export class DnsClient extends Client {
|
|||
}
|
||||
}
|
||||
export const createClient = factory(DnsClient, MODULE);
|
||||
export * from "./module.js";
|
||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -4,6 +4,7 @@ import {
|
|||
DNSResult,
|
||||
ResolverOptions,
|
||||
} from "@lumeweb/libresolver";
|
||||
import { createModule, ResolverModule } from "./module.js";
|
||||
|
||||
const MODULE = "PACYNuYbp_5hgCjMK16EGcytB9QCxDLe4_uitahwePdeaA";
|
||||
|
||||
|
@ -14,8 +15,14 @@ export class DnsClient extends Client {
|
|||
public async clear(): Promise<void> {
|
||||
return this.callModuleReturn("clear");
|
||||
}
|
||||
get resolvers(): Promise<string[]> {
|
||||
return this.callModuleReturn("getResolvers");
|
||||
get resolvers(): Promise<Set<ResolverModule>> {
|
||||
return this.callModuleReturn("getResolvers").then((resolvers: string[]) => {
|
||||
return new Set(
|
||||
resolvers.map((resolver: string): ResolverModule => {
|
||||
return createModule(resolver, this);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
public async ready(): Promise<void> {
|
||||
return this.callModuleReturn("ready");
|
||||
|
@ -30,3 +37,4 @@ export class DnsClient extends Client {
|
|||
}
|
||||
|
||||
export const createClient = factory<DnsClient>(DnsClient, MODULE);
|
||||
export * from "./module.js";
|
||||
|
|
|
@ -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);
|
Loading…
Reference in New Issue