UNPKG

2.56 kBTypeScriptView Raw
1/**
2 * @public
3 *
4 * DNS record types
5 */
6export declare enum HostAddressType {
7 /**
8 * IPv6
9 */
10 AAAA = "AAAA",
11 /**
12 * IPv4
13 */
14 A = "A"
15}
16/**
17 * @public
18 */
19export interface HostAddress {
20 /**
21 * The {@link HostAddressType} of the host address.
22 */
23 addressType: HostAddressType;
24 /**
25 * The resolved numerical address represented as a
26 * string.
27 */
28 address: string;
29 /**
30 * The host name the {@link address} was resolved from.
31 */
32 hostName: string;
33 /**
34 * The service record of {@link hostName}.
35 */
36 service?: string;
37}
38/**
39 * @public
40 */
41export interface HostResolverArguments {
42 /**
43 * The host name to resolve.
44 */
45 hostName: string;
46 /**
47 * The service record of {@link hostName}.
48 */
49 service?: string;
50}
51/**
52 * @public
53 *
54 * Host Resolver interface for DNS queries
55 */
56export interface HostResolver {
57 /**
58 * Resolves the address(es) for {@link HostResolverArguments} and returns a
59 * list of addresses with (most likely) two addresses, one {@link HostAddressType.AAAA}
60 * and one {@link HostAddressType.A}. Calls to this function will likely alter
61 * the cache (if implemented) so that if there's multiple addresses, a different
62 * set will be returned on the next call.
63 * In the case of multi-answer, still only a maximum of two records should be
64 * returned. The resolver implementation is responsible for caching and rotation
65 * of the multiple addresses that get returned.
66 * Implementations don't have to explictly call getaddrinfo(), they can use
67 * high level abstractions provided in their language runtimes/libraries.
68 * @param args - arguments with host name query addresses for
69 * @returns promise with a list of {@link HostAddress}
70 */
71 resolveAddress(args: HostResolverArguments): Promise<HostAddress[]>;
72 /**
73 * Reports a failure on a {@link HostAddress} so that the cache (if implemented)
74 * can accomodate the failure and likely not return the address until it recovers.
75 * @param addr - host address to report a failure on
76 */
77 reportFailureOnAddress(addr: HostAddress): void;
78 /**
79 * Empties the cache (if implemented) for a {@link HostResolverArguments.hostName}.
80 * If {@link HostResolverArguments.hostName} is not provided, the cache (if
81 * implemented) is emptied for all host names.
82 * @param args - optional arguments to empty the cache for
83 */
84 purgeCache(args?: HostResolverArguments): void;
85}