promise.js
2.74 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validate = validate;
exports.afterRequest = afterRequest;
exports.beforeRequest = beforeRequest;
exports.browser = browser;
exports.cache = cache;
exports.content = content;
exports.cookie = cookie;
exports.creator = creator;
exports.entry = entry;
exports.har = har;
exports.header = header;
exports.log = log;
exports.page = page;
exports.pageTimings = pageTimings;
exports.postData = postData;
exports.query = query;
exports.request = request;
exports.response = response;
exports.timings = timings;
var _harSchema = require('har-schema');
var schemas = _interopRequireWildcard(_harSchema);
var _ajv = require('ajv');
var _ajv2 = _interopRequireDefault(_ajv);
var _error = require('./error');
var _error2 = _interopRequireDefault(_error);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var ajv = void 0;
function validate(name) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// validator config
ajv = ajv || new _ajv2.default({
allErrors: true,
schemas: schemas
});
var validate = ajv.getSchema(name + '.json');
return new Promise(function (resolve, reject) {
var valid = validate(data);
!valid ? reject(new _error2.default(validate.errors)) : resolve(data);
});
}
function afterRequest(data) {
return validate('afterRequest', data);
}
function beforeRequest(data) {
return validate('beforeRequest', data);
}
function browser(data) {
return validate('browser', data);
}
function cache(data) {
return validate('cache', data);
}
function content(data) {
return validate('content', data);
}
function cookie(data) {
return validate('cookie', data);
}
function creator(data) {
return validate('creator', data);
}
function entry(data) {
return validate('entry', data);
}
function har(data) {
return validate('har', data);
}
function header(data) {
return validate('header', data);
}
function log(data) {
return validate('log', data);
}
function page(data) {
return validate('page', data);
}
function pageTimings(data) {
return validate('pageTimings', data);
}
function postData(data) {
return validate('postData', data);
}
function query(data) {
return validate('query', data);
}
function request(data) {
return validate('request', data);
}
function response(data) {
return validate('response', data);
}
function timings(data) {
return validate('timings', data);
}