promise.js
1.67 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
import * as schemas from 'har-schema'
import Ajv from 'ajv'
import HARError from './error'
let ajv
export function validate (name, data = {}) {
// validator config
ajv = ajv || new Ajv({
allErrors: true,
schemas: schemas
})
let validate = ajv.getSchema(name + '.json')
return new Promise((resolve, reject) => {
let valid = validate(data)
!valid ? reject(new HARError(validate.errors)) : resolve(data)
})
}
export function afterRequest (data) {
return validate('afterRequest', data)
}
export function beforeRequest (data) {
return validate('beforeRequest', data)
}
export function browser (data) {
return validate('browser', data)
}
export function cache (data) {
return validate('cache', data)
}
export function content (data) {
return validate('content', data)
}
export function cookie (data) {
return validate('cookie', data)
}
export function creator (data) {
return validate('creator', data)
}
export function entry (data) {
return validate('entry', data)
}
export function har (data) {
return validate('har', data)
}
export function header (data) {
return validate('header', data)
}
export function log (data) {
return validate('log', data)
}
export function page (data) {
return validate('page', data)
}
export function pageTimings (data) {
return validate('pageTimings', data)
}
export function postData (data) {
return validate('postData', data)
}
export function query (data) {
return validate('query', data)
}
export function request (data) {
return validate('request', data)
}
export function response (data) {
return validate('response', data)
}
export function timings (data) {
return validate('timings', data)
}