@nictool/dns-resource-record 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/rr.js CHANGED
@@ -19,16 +19,15 @@ export default class RR extends Map {
19
19
  this.setClass(opts?.class)
20
20
 
21
21
  for (const f of this.getFields('rdata')) {
22
- const fnName = `set${this.ucfirst(f)}`
23
- if (this[fnName] === undefined)
24
- this.throwHelp(`Missing ${fnName} in class ${this.get('type')}`)
22
+ const fnName = `set${this.ucFirst(f)}`
23
+ if (this[fnName] === undefined) this.throwHelp(`Missing ${fnName} in class ${this.get('type')}`)
25
24
  this[fnName](opts[f])
26
25
  }
27
26
 
28
27
  if (opts.comment) this.set('comment', opts.comment)
29
28
  }
30
29
 
31
- ucfirst(str) {
30
+ ucFirst(str) {
32
31
  return str
33
32
  .split(/\s/)
34
33
  .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
@@ -77,9 +76,7 @@ export default class RR extends Map {
77
76
  if (n === undefined) this.throwHelp(`owner is required`)
78
77
 
79
78
  if (n.length < 1 || n.length > 255)
80
- this.throwHelp(
81
- 'Domain names must have 1-255 octets (characters): RFC 2181',
82
- )
79
+ this.throwHelp('Domain names must have 1-255 octets (characters): RFC 2181')
83
80
 
84
81
  this.isFullyQualified(this.constructor.name, 'owner', n)
85
82
  this.hasValidLabels(n)
@@ -100,11 +97,10 @@ export default class RR extends Map {
100
97
  this.throwHelp('TTL is required, no default available')
101
98
  }
102
99
 
103
- if (typeof t !== 'number')
104
- this.throwHelp(`TTL must be numeric (${typeof t})`)
100
+ if (typeof t !== 'number') this.throwHelp(`TTL must be numeric (${typeof t})`)
105
101
 
106
102
  // RFC 1035, 2181
107
- this.is32bitInt(this.owner, 'TTL', t)
103
+ this.is32bitInt(this.get('type'), 'TTL', t)
108
104
 
109
105
  this.set('ttl', t)
110
106
  }
@@ -126,7 +122,7 @@ export default class RR extends Map {
126
122
  if (this.constructor.name === 'RR') throw new Error(e)
127
123
 
128
124
  const example = this.getCanonical
129
- ? `Example ${this.constructor.name}:\n${this.getCanonical()}\n\n`
125
+ ? `Example ${this.constructor.name}:\n${JSON.stringify(this.getCanonical(), null, '\t')}\n\n`
130
126
  : `${this.constructor.name} records have the fields: ${this.getFields().join(', ')}\n\n`
131
127
 
132
128
  throw new Error(`${e}\n\n${example}${this.citeRFC()}\n`)
@@ -209,8 +205,7 @@ export default class RR extends Map {
209
205
 
210
206
  if (zone_opts.hide?.origin && zone_opts.origin) {
211
207
  if (fqdn === zone_opts.origin) return '@'
212
- if (fqdn.endsWith(zone_opts.origin))
213
- return fqdn.slice(0, fqdn.length - zone_opts.origin.length - 1)
208
+ if (fqdn.endsWith(zone_opts.origin)) return fqdn.slice(0, fqdn.length - zone_opts.origin.length - 1)
214
209
  }
215
210
 
216
211
  return fqdn
@@ -232,9 +227,7 @@ export default class RR extends Map {
232
227
  }
233
228
 
234
229
  getTinydnsPostamble() {
235
- return ['ttl', 'timestamp', 'location']
236
- .map((f) => this.getEmpty(f))
237
- .join(':')
230
+ return ['ttl', 'timestamp', 'location'].map((f) => this.getEmpty(f)).join(':')
238
231
  }
239
232
 
240
233
  hasValidLabels(hostname) {
@@ -258,9 +251,7 @@ export default class RR extends Map {
258
251
  )
259
252
  return true
260
253
 
261
- this.throwHelp(
262
- `${type} ${field} must be a 8-bit integer (in the range 0-255)`,
263
- )
254
+ this.throwHelp(`${type} ${field} must be a 8-bit integer (in the range 0-255)`)
264
255
  }
265
256
 
266
257
  is16bitInt(type, field, value) {
@@ -272,9 +263,7 @@ export default class RR extends Map {
272
263
  )
273
264
  return true
274
265
 
275
- this.throwHelp(
276
- `${type} ${field} must be a 16-bit integer (in the range 0-65535)`,
277
- )
266
+ this.throwHelp(`${type} ${field} must be a 16-bit integer (in the range 0-65535)`)
278
267
  }
279
268
 
280
269
  is32bitInt(type, field, value) {
@@ -286,9 +275,7 @@ export default class RR extends Map {
286
275
  )
287
276
  return true
288
277
 
289
- this.throwHelp(
290
- `${type} ${field} must be a 32-bit integer (in the range 0-2147483647)`,
291
- )
278
+ this.throwHelp(`${type} ${field} must be a 32-bit integer (in the range 0-2147483647)`)
292
279
  }
293
280
 
294
281
  isQuoted(val) {
@@ -306,9 +293,7 @@ export default class RR extends Map {
306
293
  if (!allowed.test(hostname)) return true
307
294
 
308
295
  const matches = allowed.exec(hostname)
309
- this.throwHelp(
310
- `${type}, ${field} has invalid hostname character (${matches[0]})`,
311
- )
296
+ this.throwHelp(`${type}, ${field} has invalid hostname character (${matches[0]})`)
312
297
  }
313
298
 
314
299
  isIPv4(string) {
@@ -330,10 +315,9 @@ export default class RR extends Map {
330
315
 
331
316
  toMaraDNS() {
332
317
  const type = this.get('type')
333
- const supportedTypes =
334
- 'A PTR MX AAAA SRV NAPTR NS SOA TXT SPF RAW FQDN4 FQDN6 CNAME HINFO WKS LOC'.split(
335
- /\s+/g,
336
- )
318
+ const supportedTypes = 'A PTR MX AAAA SRV NAPTR NS SOA TXT SPF RAW FQDN4 FQDN6 CNAME HINFO WKS LOC'.split(
319
+ /\s+/g,
320
+ )
337
321
  if (!supportedTypes.includes(type)) return this.toMaraGeneric()
338
322
  return `${this.get('owner')}\t+${this.get('ttl')}\t${type}\t${this.getRdataFields()
339
323
  .map((f) => this.getQuoted(f))