From af4799d0b507644ac87a07d91f7f49186651c6cd Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 25 Nov 2024 14:59:23 -0500 Subject: [PATCH] add node:dns constants --- src/node/BUILD.bazel | 1 + src/node/dns.ts | 5 ++++ src/node/dns/promises.ts | 7 ++++++ src/node/internal/internal_dns_constants.ts | 24 +++++++++++++++++++ src/node/tsconfig.json | 1 + src/workerd/api/node/tests/dns-nodejs-test.js | 8 +++++++ 6 files changed, 46 insertions(+) create mode 100644 src/node/dns/promises.ts create mode 100644 src/node/internal/internal_dns_constants.ts diff --git a/src/node/BUILD.bazel b/src/node/BUILD.bazel index 440c167a704..c9da6ef4736 100644 --- a/src/node/BUILD.bazel +++ b/src/node/BUILD.bazel @@ -13,6 +13,7 @@ wd_ts_bundle( "*.ts", "*.js", "assert/*.ts", + "dns/*.ts", "stream/*.js", "path/*.ts", "util/*.ts", diff --git a/src/node/dns.ts b/src/node/dns.ts index 9dc7d5b3377..52a495ac85c 100644 --- a/src/node/dns.ts +++ b/src/node/dns.ts @@ -1,4 +1,7 @@ import { default as dnsUtil } from 'node-internal:dns'; +import * as errorCodes from 'node-internal:internal_dns_constants'; + +export * from 'node-internal:internal_dns_constants'; export const getServers = dnsUtil.getServers.bind(dnsUtil); export const lookup = dnsUtil.lookup.bind(dnsUtil); @@ -44,4 +47,6 @@ export default { setDefaultResultOrder, getDefaultResultOrder, setServers, + + ...errorCodes, }; diff --git a/src/node/dns/promises.ts b/src/node/dns/promises.ts new file mode 100644 index 00000000000..fad3d749fb1 --- /dev/null +++ b/src/node/dns/promises.ts @@ -0,0 +1,7 @@ +import * as errorCodes from 'node-internal:internal_dns_constants'; + +export * from 'node-internal:internal_dns_constants'; + +export default { + ...errorCodes, +}; diff --git a/src/node/internal/internal_dns_constants.ts b/src/node/internal/internal_dns_constants.ts new file mode 100644 index 00000000000..871a48c78e5 --- /dev/null +++ b/src/node/internal/internal_dns_constants.ts @@ -0,0 +1,24 @@ +export const NODATA = 'ENODATA'; +export const FORMERR = 'EFORMERR'; +export const SERVFAIL = 'ESERVFAIL'; +export const NOTFOUND = 'ENOTFOUND'; +export const NOTIMP = 'ENOTIMP'; +export const REFUSED = 'EREFUSED'; +export const BADQUERY = 'EBADQUERY'; +export const BADNAME = 'EBADNAME'; +export const BADFAMILY = 'EBADFAMILY'; +export const BADRESP = 'EBADRESP'; +export const CONNREFUSED = 'ECONNREFUSED'; +export const TIMEOUT = 'ETIMEOUT'; +export const EOF = 'EOF'; +export const FILE = 'EFILE'; +export const NOMEM = 'ENOMEM'; +export const DESTRUCTION = 'EDESTRUCTION'; +export const BADSTR = 'EBADSTR'; +export const BADFLAGS = 'EBADFLAGS'; +export const NONAME = 'ENONAME'; +export const BADHINTS = 'EBADHINTS'; +export const NOTINITIALIZED = 'ENOTINITIALIZED'; +export const LOADIPHLPAPI = 'ELOADIPHLPAPI'; +export const ADDRGETNETWORKPARAMS = 'EADDRGETNETWORKPARAMS'; +export const CANCELLED = 'ECANCELLED'; diff --git a/src/node/tsconfig.json b/src/node/tsconfig.json index f51a22dac8a..1a926356e18 100644 --- a/src/node/tsconfig.json +++ b/src/node/tsconfig.json @@ -24,6 +24,7 @@ "paths": { "node:*": ["./*"], "node:assert/*": ["./*"], + "node:dns/*": ["./*"], "node:util/*": ["./*"], "node:path/*": ["./*"], "node:stream/*": ["./*"], diff --git a/src/workerd/api/node/tests/dns-nodejs-test.js b/src/workerd/api/node/tests/dns-nodejs-test.js index b571bceb699..b0479f32b01 100644 --- a/src/workerd/api/node/tests/dns-nodejs-test.js +++ b/src/workerd/api/node/tests/dns-nodejs-test.js @@ -1,4 +1,5 @@ import dns from 'node:dns'; +import dnsPromises from 'node:dns/promises'; import { strictEqual } from 'node:assert'; export const functionsExist = { @@ -29,3 +30,10 @@ export const functionsExist = { } }, }; + +export const errorCodesExist = { + async test() { + strictEqual(typeof dns.NODATA, 'string'); + strictEqual(typeof dnsPromises.NODATA, 'string'); + }, +};