1 | 'use strict'
|
2 |
|
3 | const bsplit = require('buffer-split')
|
4 | const errcode = require('err-code')
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | const verifyRecord = (validators, record, callback) => {
|
16 | const key = record.key
|
17 | const parts = bsplit(key, Buffer.from('/'))
|
18 |
|
19 | if (parts.length < 3) {
|
20 |
|
21 | return callback()
|
22 | }
|
23 |
|
24 | const validator = validators[parts[1].toString()]
|
25 |
|
26 | if (!validator) {
|
27 | const errMsg = `Invalid record keytype`
|
28 |
|
29 | return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_KEY_TYPE'))
|
30 | }
|
31 |
|
32 | validator.func(key, record.value, callback)
|
33 | }
|
34 |
|
35 | module.exports = {
|
36 | verifyRecord: verifyRecord,
|
37 | validators: require('./validators')
|
38 | }
|