source: trip-planner-front/node_modules/har-validator/lib/promise.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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