Removed modules/contrib/media module to allow update to the core media module
[yaffs-website] / node_modules / har-validator / lib / node4 / 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 var ajv = void 0;
43
44 function validate(name) {
45   var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46   var next = arguments[2];
47
48   // validator config
49   ajv = ajv || new _ajv2.default({
50     allErrors: true,
51     schemas: schemas
52   });
53
54   var validate = ajv.getSchema(name + '.json');
55
56   var valid = validate(data);
57
58   // callback?
59   if (typeof next === 'function') {
60     return next(!valid ? new _error2.default(validate.errors) : null, valid);
61   }
62
63   return valid;
64 }
65
66 function afterRequest(data, next) {
67   return validate('afterRequest', data, next);
68 }
69
70 function beforeRequest(data, next) {
71   return validate('beforeRequest', data, next);
72 }
73
74 function browser(data, next) {
75   return validate('browser', data, next);
76 }
77
78 function cache(data, next) {
79   return validate('cache', data, next);
80 }
81
82 function content(data, next) {
83   return validate('content', data, next);
84 }
85
86 function cookie(data, next) {
87   return validate('cookie', data, next);
88 }
89
90 function creator(data, next) {
91   return validate('creator', data, next);
92 }
93
94 function entry(data, next) {
95   return validate('entry', data, next);
96 }
97
98 function har(data, next) {
99   return validate('har', data, next);
100 }
101
102 function header(data, next) {
103   return validate('header', data, next);
104 }
105
106 function log(data, next) {
107   return validate('log', data, next);
108 }
109
110 function page(data, next) {
111   return validate('page', data, next);
112 }
113
114 function pageTimings(data, next) {
115   return validate('pageTimings', data, next);
116 }
117
118 function postData(data, next) {
119   return validate('postData', data, next);
120 }
121
122 function query(data, next) {
123   return validate('query', data, next);
124 }
125
126 function request(data, next) {
127   return validate('request', data, next);
128 }
129
130 function response(data, next) {
131   return validate('response', data, next);
132 }
133
134 function timings(data, next) {
135   return validate('timings', data, next);
136 }