Spaces:
Configuration error
Configuration error
File size: 1,941 Bytes
5641073 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
var Ajv = require('ajv')
var HARError = require('./error')
var schemas = require('har-schema')
var ajv
function createAjvInstance () {
var ajv = new Ajv({
allErrors: true
})
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'))
ajv.addSchema(schemas)
return ajv
}
function validate (name, data) {
data = data || {}
// validator config
ajv = ajv || createAjvInstance()
var validate = ajv.getSchema(name + '.json')
return new Promise(function (resolve, reject) {
var valid = validate(data)
!valid ? reject(new HARError(validate.errors)) : resolve(data)
})
}
exports.afterRequest = function (data) {
return validate('afterRequest', data)
}
exports.beforeRequest = function (data) {
return validate('beforeRequest', data)
}
exports.browser = function (data) {
return validate('browser', data)
}
exports.cache = function (data) {
return validate('cache', data)
}
exports.content = function (data) {
return validate('content', data)
}
exports.cookie = function (data) {
return validate('cookie', data)
}
exports.creator = function (data) {
return validate('creator', data)
}
exports.entry = function (data) {
return validate('entry', data)
}
exports.har = function (data) {
return validate('har', data)
}
exports.header = function (data) {
return validate('header', data)
}
exports.log = function (data) {
return validate('log', data)
}
exports.page = function (data) {
return validate('page', data)
}
exports.pageTimings = function (data) {
return validate('pageTimings', data)
}
exports.postData = function (data) {
return validate('postData', data)
}
exports.query = function (data) {
return validate('query', data)
}
exports.request = function (data) {
return validate('request', data)
}
exports.response = function (data) {
return validate('response', data)
}
exports.timings = function (data) {
return validate('timings', data)
}
|