Initial commit
[yaffs-website] / node_modules / har-validator / lib / node6 / async.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6 exports.validate = validate;
7 exports.afterRequest = afterRequest;
8 exports.beforeRequest = beforeRequest;
9 exports.browser = browser;
10 exports.cache = cache;
11 exports.content = content;
12 exports.cookie = cookie;
13 exports.creator = creator;
14 exports.entry = entry;
15 exports.har = har;
16 exports.header = header;
17 exports.log = log;
18 exports.page = page;
19 exports.pageTimings = pageTimings;
20 exports.postData = postData;
21 exports.query = query;
22 exports.request = request;
23 exports.response = response;
24 exports.timings = timings;
25
26 var _harSchema = require('har-schema');
27
28 var schemas = _interopRequireWildcard(_harSchema);
29
30 var _ajv = require('ajv');
31
32 var _ajv2 = _interopRequireDefault(_ajv);
33
34 var _error = require('./error');
35
36 var _error2 = _interopRequireDefault(_error);
37
38 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
40 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; } }
41
42 let ajv;
43
44 function validate(name, data = {}, next) {
45   // validator config
46   ajv = ajv || new _ajv2.default({
47     allErrors: true,
48     schemas: schemas
49   });
50
51   let validate = ajv.getSchema(name + '.json');
52
53   let valid = validate(data);
54
55   // callback?
56   if (typeof next === 'function') {
57     return next(!valid ? new _error2.default(validate.errors) : null, valid);
58   }
59
60   return valid;
61 }
62
63 function afterRequest(data, next) {
64   return validate('afterRequest', data, next);
65 }
66
67 function beforeRequest(data, next) {
68   return validate('beforeRequest', data, next);
69 }
70
71 function browser(data, next) {
72   return validate('browser', data, next);
73 }
74
75 function cache(data, next) {
76   return validate('cache', data, next);
77 }
78
79 function content(data, next) {
80   return validate('content', data, next);
81 }
82
83 function cookie(data, next) {
84   return validate('cookie', data, next);
85 }
86
87 function creator(data, next) {
88   return validate('creator', data, next);
89 }
90
91 function entry(data, next) {
92   return validate('entry', data, next);
93 }
94
95 function har(data, next) {
96   return validate('har', data, next);
97 }
98
99 function header(data, next) {
100   return validate('header', data, next);
101 }
102
103 function log(data, next) {
104   return validate('log', data, next);
105 }
106
107 function page(data, next) {
108   return validate('page', data, next);
109 }
110
111 function pageTimings(data, next) {
112   return validate('pageTimings', data, next);
113 }
114
115 function postData(data, next) {
116   return validate('postData', data, next);
117 }
118
119 function query(data, next) {
120   return validate('query', data, next);
121 }
122
123 function request(data, next) {
124   return validate('request', data, next);
125 }
126
127 function response(data, next) {
128   return validate('response', data, next);
129 }
130
131 function timings(data, next) {
132   return validate('timings', data, next);
133 }