initial
This commit is contained in:
96
node_modules/har-validator/src/async.js
generated
vendored
Normal file
96
node_modules/har-validator/src/async.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
import * as schemas from 'har-schema'
|
||||
import Ajv from 'ajv'
|
||||
import HARError from './error'
|
||||
|
||||
let ajv
|
||||
|
||||
export function validate (name, data = {}, next) {
|
||||
// validator config
|
||||
ajv = ajv || new Ajv({
|
||||
allErrors: true,
|
||||
schemas: schemas
|
||||
})
|
||||
|
||||
let validate = ajv.getSchema(name + '.json')
|
||||
|
||||
let valid = validate(data)
|
||||
|
||||
// callback?
|
||||
if (typeof next === 'function') {
|
||||
return next(!valid ? new HARError(validate.errors) : null, valid)
|
||||
}
|
||||
|
||||
return valid
|
||||
}
|
||||
|
||||
export function afterRequest (data, next) {
|
||||
return validate('afterRequest', data, next)
|
||||
}
|
||||
|
||||
export function beforeRequest (data, next) {
|
||||
return validate('beforeRequest', data, next)
|
||||
}
|
||||
|
||||
export function browser (data, next) {
|
||||
return validate('browser', data, next)
|
||||
}
|
||||
|
||||
export function cache (data, next) {
|
||||
return validate('cache', data, next)
|
||||
}
|
||||
|
||||
export function content (data, next) {
|
||||
return validate('content', data, next)
|
||||
}
|
||||
|
||||
export function cookie (data, next) {
|
||||
return validate('cookie', data, next)
|
||||
}
|
||||
|
||||
export function creator (data, next) {
|
||||
return validate('creator', data, next)
|
||||
}
|
||||
|
||||
export function entry (data, next) {
|
||||
return validate('entry', data, next)
|
||||
}
|
||||
|
||||
export function har (data, next) {
|
||||
return validate('har', data, next)
|
||||
}
|
||||
|
||||
export function header (data, next) {
|
||||
return validate('header', data, next)
|
||||
}
|
||||
|
||||
export function log (data, next) {
|
||||
return validate('log', data, next)
|
||||
}
|
||||
|
||||
export function page (data, next) {
|
||||
return validate('page', data, next)
|
||||
}
|
||||
|
||||
export function pageTimings (data, next) {
|
||||
return validate('pageTimings', data, next)
|
||||
}
|
||||
|
||||
export function postData (data, next) {
|
||||
return validate('postData', data, next)
|
||||
}
|
||||
|
||||
export function query (data, next) {
|
||||
return validate('query', data, next)
|
||||
}
|
||||
|
||||
export function request (data, next) {
|
||||
return validate('request', data, next)
|
||||
}
|
||||
|
||||
export function response (data, next) {
|
||||
return validate('response', data, next)
|
||||
}
|
||||
|
||||
export function timings (data, next) {
|
||||
return validate('timings', data, next)
|
||||
}
|
||||
15
node_modules/har-validator/src/error.js
generated
vendored
Normal file
15
node_modules/har-validator/src/error.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
export default function HARError (errors) {
|
||||
let message = 'validation failed'
|
||||
|
||||
this.name = 'HARError'
|
||||
this.message = message
|
||||
this.errors = errors
|
||||
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, this.constructor)
|
||||
} else {
|
||||
this.stack = (new Error(message)).stack
|
||||
}
|
||||
}
|
||||
|
||||
HARError.prototype = Error.prototype
|
||||
93
node_modules/har-validator/src/promise.js
generated
vendored
Normal file
93
node_modules/har-validator/src/promise.js
generated
vendored
Normal file
@@ -0,0 +1,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)
|
||||
}
|
||||
Reference in New Issue
Block a user