Skip to content

Commit

Permalink
Fix types for #38
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Sep 5, 2024
1 parent 53be53a commit 017341e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
8 changes: 6 additions & 2 deletions pkg/dohdec/lib/dnsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ const PAD_SIZE = 128;
* @property {string} [rrtype] The Resource Record type to retrive.
* @property {number} [id] The 2-byte unsigned integer for the request.
* For DOH, should be 0 or undefined.
* @property {boolean} [json] Force JSON lookups for DOH. Ignored for DOT.
* @property {boolean} [decode=true] Decode the response, either into JSON
* or an object representing the DNS format result.
* @property {boolean} [stream=false] Encode for streaming, with the packet
* prefixed by a 2-byte big-endian integer of the number of bytes in the
* packet.
* @property {boolean} [dnssec=false] Request DNSSec records. Currently
* requires `json: false`.
* @property {boolean} [dnssecCheckingDisabled=false] Disable DNSSEC
*/

// Extracted from node source.
Expand Down Expand Up @@ -236,7 +240,7 @@ export class DNSutils extends EventEmitter {
*/
static normalizeArgs(name, opts, defaults) {
/** @type {LookupOptions} */
let nopts = {};
let nopts = Object.create(null);
if (name != null) {
switch (typeof name) {
case 'object':
Expand Down
33 changes: 16 additions & 17 deletions pkg/dohdec/lib/doh.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ const USER_AGENT = `${pkg.name} v${pkg.version}`;
/**
* Options for doing DOH lookups.
*
* @typedef {object} DOH_LookupOptions
* @property {string} [name] The DNS name to look up.
* @property {string} [rrtype='A'] The Resource Record type
* to retrive.
* @property {boolean} [json=true] Retrieve a JSON response. If false,
* retrieve using DNS format.
* @property {boolean} [decode=true] Decode the response, either into JSON
* or an object representing the DNS format result.
* @typedef {object} DOH_SpecificLookupOptions
* @property {boolean} [preferPost=true] For DNS format requests, should
* the HTTP POST verb be used? If false, uses GET.
* @property {boolean} [dnssec=false] Request DNSSec records. Currently
* requires `json: false`.
* @property {string} [url=CLOUDFLARE_API] What DoH endpoint should be
* used?
* @property {boolean} [json=true] Force JSON lookups for DOH.
*/

/**
* @typedef {DOH_SpecificLookupOptions &
* import('./dnsUtils.js').LookupOptions} DOH_LookupOptions
*/

/**
Expand Down Expand Up @@ -200,13 +197,15 @@ export class DNSoverHTTPS extends DNSutils {
* @returns {Promise<Buffer|string|object>} DNS result.
*/
lookup(name, opts = {}) {
const nopts = DNSutils.normalizeArgs(name, opts, {
rrtype: 'A',
json: true,
decode: true,
dnssec: false,
dnssecCheckingDisabled: false,
});
const nopts = /** @type {Required<DOH_LookupOptions>} */ (
DNSutils.normalizeArgs(name, opts, {
rrtype: 'A',
json: true,
decode: true,
dnssec: false,
dnssecCheckingDisabled: false,
})
);
this.verbose(1, 'DNSoverHTTPS.lookup options:', nopts);

return nopts.json ? this.getJSON(nopts) : this.getDNS(nopts);
Expand Down
10 changes: 1 addition & 9 deletions pkg/dohdec/lib/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@ const DEFAULT_SERVER = '1.1.1.1';
/**
* Options for doing DOT lookups.
*
* @typedef {object} DOT_LookupOptions
* @property {string} [name] The DNS name to look up.
* @property {string} [rrtype='A'] The Resource Record type
* to retrive.
* @property {number} [id] 2-byte ID for the DNS packet. Defaults to random.
* @property {boolean} [decode=true] Decode the response, either into JSON
* or an object representing the DNS format result.
* @property {boolean} [dnssec=false] Request DNSSec records. Currently
* requires `json: false`.
* @typedef {import('./dnsUtils.js').LookupOptions} DOT_LookupOptions
*/

/**
Expand Down

0 comments on commit 017341e

Please sign in to comment.