*Abort if module is already registered
This commit is contained in:
parent
92241c3748
commit
a7b6948312
|
@ -8,17 +8,18 @@ import type { RpcNetwork } from "@lumeweb/kernel-rpc-client";
|
|||
import { callModule } from "libkmodule/dist";
|
||||
|
||||
export class ResolverRegistry {
|
||||
private _resolvers: Set<ResolverModule> = new Set();
|
||||
private _rpcNetwork: RpcNetwork;
|
||||
|
||||
constructor(network: RpcNetwork) {
|
||||
this._rpcNetwork = network;
|
||||
}
|
||||
|
||||
private _resolvers: Set<ResolverModule> = new Set<ResolverModule>();
|
||||
|
||||
get resolvers(): Set<ResolverModule> {
|
||||
return this._resolvers;
|
||||
}
|
||||
|
||||
private _rpcNetwork: RpcNetwork;
|
||||
|
||||
get rpcNetwork(): RpcNetwork {
|
||||
return this._rpcNetwork;
|
||||
}
|
||||
|
@ -28,7 +29,7 @@ export class ResolverRegistry {
|
|||
options: ResolverOptions = { type: DNS_RECORD_TYPE.DEFAULT },
|
||||
bypassCache: boolean = false
|
||||
): Promise<DNSResult> {
|
||||
for (const resolver of this._resolvers) {
|
||||
for (const resolver: ResolverModule of this._resolvers) {
|
||||
const result = await resolver.resolve(domain, options, bypassCache);
|
||||
if (!result.error && result.records.length) {
|
||||
return result;
|
||||
|
@ -39,6 +40,13 @@ export class ResolverRegistry {
|
|||
}
|
||||
|
||||
public register(resolver: ResolverModule): void {
|
||||
if (
|
||||
[...this._resolvers.values()].filter(
|
||||
(item) => item.domain === resolver.domain
|
||||
).length > 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this._resolvers.add(resolver);
|
||||
}
|
||||
|
||||
|
@ -48,12 +56,17 @@ export class ResolverRegistry {
|
|||
}
|
||||
|
||||
export class ResolverModule {
|
||||
private resolver: ResolverRegistry;
|
||||
private domain: string;
|
||||
private _resolver: ResolverRegistry;
|
||||
|
||||
constructor(resolver: ResolverRegistry, domain: string) {
|
||||
this.resolver = resolver;
|
||||
this.domain = domain;
|
||||
this._resolver = resolver;
|
||||
this._domain = domain;
|
||||
}
|
||||
|
||||
private _domain: string;
|
||||
|
||||
get domain(): string {
|
||||
return this._domain;
|
||||
}
|
||||
|
||||
async resolve(
|
||||
|
@ -61,7 +74,7 @@ export class ResolverModule {
|
|||
options: ResolverOptions,
|
||||
bypassCache: boolean
|
||||
): Promise<DNSResult> {
|
||||
const [ret, err] = await callModule(this.domain, "resolve", {
|
||||
const [ret, err] = await callModule(this._domain, "resolve", {
|
||||
domain,
|
||||
options,
|
||||
bypassCache,
|
||||
|
|
Loading…
Reference in New Issue