Skip to content

Commit

Permalink
add missing promises in node:dns (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig authored Jan 6, 2025
1 parent e0bf0d5 commit 094c9e4
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 164 deletions.
4 changes: 3 additions & 1 deletion src/node/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import * as errorCodes from 'node-internal:internal_dns_constants';
import * as dns from 'node-internal:internal_dns';
import { callbackify } from 'node-internal:internal_utils';
import * as dnsPromises from 'node-internal:internal_dns_promises';

export * from 'node-internal:internal_dns_constants';

export const promises = dnsPromises;
export const reverse = callbackify(dns.reverse.bind(dns));
export const resolveTxt = callbackify(dns.resolveTxt.bind(dns));
export const resolveCaa = callbackify(dns.resolveCaa.bind(dns));
Expand Down Expand Up @@ -142,6 +144,6 @@ export default {
getDefaultResultOrder,
setServers,
Resolver,

promises,
...errorCodes,
};
166 changes: 3 additions & 163 deletions src/node/dns/promises.ts
Original file line number Diff line number Diff line change
@@ -1,164 +1,4 @@
import * as errorCodes from 'node-internal:internal_dns_constants';
import {
reverse,
resolveTxt,
resolveCaa,
resolveMx,
resolveCname,
resolveNs,
resolvePtr,
resolveSrv,
resolveSoa,
resolveNaptr,
resolve4,
resolve6,
getServers,
setServers,
getDefaultResultOrder,
setDefaultResultOrder,
lookup,
lookupService,
resolve,
resolveAny,
} from 'node-internal:internal_dns';
import {
CAA,
MX,
NAPTR,
SOA,
SRV,
TTLResponse,
} from 'node:internal/internal_dns_client';
import * as dns from 'node-internal:internal_dns_promises';

export * from 'node-internal:internal_dns_constants';
export {
reverse,
resolveTxt,
resolveCaa,
resolveMx,
resolveCname,
resolveNs,
resolvePtr,
resolveSrv,
resolveSoa,
resolveNaptr,
resolve4,
resolve6,
getServers,
setServers,
getDefaultResultOrder,
setDefaultResultOrder,
lookup,
lookupService,
resolve,
resolveAny,
} from 'node-internal:internal_dns';

export class Resolver {
// eslint-disable-next-line @typescript-eslint/require-await
public async cancel(): Promise<void> {
// TODO(soon): Implement this.
throw new Error('Not implemented');
}

// eslint-disable-next-line @typescript-eslint/require-await
public async setLocalAddress(): Promise<void> {
// Does not apply to workerd implementation
throw new Error('Not implemented');
}

public getServers(): Promise<string[]> {
return getServers();
}

public resolve(): Promise<void> {
return resolve();
}

public resolve4(
input: string,
options?: { ttl?: boolean }
): Promise<(string | TTLResponse)[]> {
return resolve4(input, options);
}

public resolve6(
input: string,
options?: { ttl?: boolean }
): Promise<(string | TTLResponse)[]> {
return resolve6(input, options);
}

public resolveAny(): Promise<void> {
return resolveAny();
}

public resolveCaa(name: string): Promise<CAA[]> {
return resolveCaa(name);
}

public resolveCname(name: string): Promise<string[]> {
return resolveCname(name);
}

public resolveMx(name: string): Promise<MX[]> {
return resolveMx(name);
}

public resolveNaptr(name: string): Promise<NAPTR[]> {
return resolveNaptr(name);
}

public resolveNs(name: string): Promise<string[]> {
return resolveNs(name);
}

public esolvePtr(name: string): Promise<string[]> {
return resolvePtr(name);
}

public resolveSoa(name: string): Promise<SOA> {
return resolveSoa(name);
}

public resolveSrv(name: string): Promise<SRV[]> {
return resolveSrv(name);
}

public resolveTxt(name: string): Promise<string[][]> {
return resolveTxt(name);
}

public reverse(name: string): Promise<string[]> {
return reverse(name);
}

public setServers(): Promise<void> {
return setServers();
}
}

export default {
reverse,
resolveTxt,
resolveCaa,
resolveMx,
resolveCname,
resolveNs,
resolvePtr,
resolveSrv,
resolveSoa,
resolveNaptr,
resolve4,
resolve6,
getServers,
setServers,
getDefaultResultOrder,
setDefaultResultOrder,
lookup,
lookupService,
resolve,
resolveAny,
Resolver,
...errorCodes,
};
export * from 'node-internal:internal_dns_promises';
export default dns;
3 changes: 3 additions & 0 deletions src/node/internal/internal_dns_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ export const NOTINITIALIZED = 'ENOTINITIALIZED';
export const LOADIPHLPAPI = 'ELOADIPHLPAPI';
export const ADDRGETNETWORKPARAMS = 'EADDRGETNETWORKPARAMS';
export const CANCELLED = 'ECANCELLED';
export const ADDRCONFIG = 1024;
export const ALL = 256;
export const V4MAPPED = 2048;
164 changes: 164 additions & 0 deletions src/node/internal/internal_dns_promises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import * as errorCodes from 'node-internal:internal_dns_constants';
import {
reverse,
resolveTxt,
resolveCaa,
resolveMx,
resolveCname,
resolveNs,
resolvePtr,
resolveSrv,
resolveSoa,
resolveNaptr,
resolve4,
resolve6,
getServers,
setServers,
getDefaultResultOrder,
setDefaultResultOrder,
lookup,
lookupService,
resolve,
resolveAny,
} from 'node-internal:internal_dns';
import {
CAA,
MX,
NAPTR,
SOA,
SRV,
TTLResponse,
} from 'node:internal/internal_dns_client';

export * from 'node-internal:internal_dns_constants';
export {
reverse,
resolveTxt,
resolveCaa,
resolveMx,
resolveCname,
resolveNs,
resolvePtr,
resolveSrv,
resolveSoa,
resolveNaptr,
resolve4,
resolve6,
getServers,
setServers,
getDefaultResultOrder,
setDefaultResultOrder,
lookup,
lookupService,
resolve,
resolveAny,
} from 'node-internal:internal_dns';

export class Resolver {
// eslint-disable-next-line @typescript-eslint/require-await
public async cancel(): Promise<void> {
// TODO(soon): Implement this.
throw new Error('Not implemented');
}

// eslint-disable-next-line @typescript-eslint/require-await
public async setLocalAddress(): Promise<void> {
// Does not apply to workerd implementation
throw new Error('Not implemented');
}

public getServers(): Promise<string[]> {
return getServers();
}

public resolve(): Promise<void> {
return resolve();
}

public resolve4(
input: string,
options?: { ttl?: boolean }
): Promise<(string | TTLResponse)[]> {
return resolve4(input, options);
}

public resolve6(
input: string,
options?: { ttl?: boolean }
): Promise<(string | TTLResponse)[]> {
return resolve6(input, options);
}

public resolveAny(): Promise<void> {
return resolveAny();
}

public resolveCaa(name: string): Promise<CAA[]> {
return resolveCaa(name);
}

public resolveCname(name: string): Promise<string[]> {
return resolveCname(name);
}

public resolveMx(name: string): Promise<MX[]> {
return resolveMx(name);
}

public resolveNaptr(name: string): Promise<NAPTR[]> {
return resolveNaptr(name);
}

public resolveNs(name: string): Promise<string[]> {
return resolveNs(name);
}

public esolvePtr(name: string): Promise<string[]> {
return resolvePtr(name);
}

public resolveSoa(name: string): Promise<SOA> {
return resolveSoa(name);
}

public resolveSrv(name: string): Promise<SRV[]> {
return resolveSrv(name);
}

public resolveTxt(name: string): Promise<string[][]> {
return resolveTxt(name);
}

public reverse(name: string): Promise<string[]> {
return reverse(name);
}

public setServers(): Promise<void> {
return setServers();
}
}

export default {
reverse,
resolveTxt,
resolveCaa,
resolveMx,
resolveCname,
resolveNs,
resolvePtr,
resolveSrv,
resolveSoa,
resolveNaptr,
resolve4,
resolve6,
getServers,
setServers,
getDefaultResultOrder,
setDefaultResultOrder,
lookup,
lookupService,
resolve,
resolveAny,
Resolver,
...errorCodes,
};
2 changes: 2 additions & 0 deletions src/workerd/api/node/tests/dns-nodejs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const functionsExist = {
for (const fn of syncFns) {
strictEqual(typeof dns[fn], 'function');
}

ok(dns.promises !== undefined);
},
};

Expand Down

0 comments on commit 094c9e4

Please sign in to comment.