Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing promises in node:dns #3292

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

@vicb vicb Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those 3 are not on dns.promises (nor dns/promises) in node

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
Loading