async.js
1.98 KB
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
var Ajv = require('ajv')
var HARError = require('./error')
var schemas = require('har-schema')
var ajv
function validate (name, data, next) {
data = data || {}
// validator config
ajv = ajv || new Ajv({
allErrors: true,
schemas: schemas
})
var validate = ajv.getSchema(name + '.json')
var valid = validate(data)
// callback?
if (typeof next === 'function') {
return next(!valid ? new HARError(validate.errors) : null, valid)
}
return valid
}
exports.afterRequest = function (data, next) {
return validate('afterRequest', data, next)
}
exports.beforeRequest = function (data, next) {
return validate('beforeRequest', data, next)
}
exports.browser = function (data, next) {
return validate('browser', data, next)
}
exports.cache = function (data, next) {
return validate('cache', data, next)
}
exports.content = function (data, next) {
return validate('content', data, next)
}
exports.cookie = function (data, next) {
return validate('cookie', data, next)
}
exports.creator = function (data, next) {
return validate('creator', data, next)
}
exports.entry = function (data, next) {
return validate('entry', data, next)
}
exports.har = function (data, next) {
return validate('har', data, next)
}
exports.header = function (data, next) {
return validate('header', data, next)
}
exports.log = function (data, next) {
return validate('log', data, next)
}
exports.page = function (data, next) {
return validate('page', data, next)
}
exports.pageTimings = function (data, next) {
return validate('pageTimings', data, next)
}
exports.postData = function (data, next) {
return validate('postData', data, next)
}
exports.query = function (data, next) {
return validate('query', data, next)
}
exports.request = function (data, next) {
return validate('request', data, next)
}
exports.response = function (data, next) {
return validate('response', data, next)
}
exports.timings = function (data, next) {
return validate('timings', data, next)
}