mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
# Conflicts: # jsowell-ui/.env.development # jsowell-ui/.env.staging # jsowell-ui/bin/build-sit.bat # jsowell-ui/bin/build.bat # jsowell-ui/src/api/adapayMember/adapayMember.js # jsowell-ui/src/api/pile/merchant.js # jsowell-ui/src/router/index.js # jsowell-ui/src/views/financial/financeDetail.vue # jsowell-ui/src/views/financial/merchant.vue # jsowell-ui/src/views/homeIndex/homeIndex.vue # jsowell-ui/src/views/login.vue # jsowell-ui/src/views/pile/basic/detail.vue # jsowell-ui/src/views/pile/station/components/SiteInfo.vue # jsowell-ui/src/views/pile/station/detail.vue # jsowell-ui/src/views/pile/station/orderReport.vue
103 lines
1.9 KiB
JavaScript
103 lines
1.9 KiB
JavaScript
var Ajv = require('ajv')
|
|
var HARError = require('./error')
|
|
var schemas = require('har-schema')
|
|
|
|
var ajv
|
|
|
|
function createAjvInstance () {
|
|
var ajv = new Ajv({
|
|
allErrors: true
|
|
})
|
|
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'))
|
|
ajv.addSchema(schemas)
|
|
|
|
return ajv
|
|
}
|
|
|
|
function validate (name, data) {
|
|
data = data || {}
|
|
|
|
// validator config
|
|
ajv = ajv || createAjvInstance()
|
|
|
|
var validate = ajv.getSchema(name + '.json')
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
var valid = validate(data)
|
|
|
|
!valid ? reject(new HARError(validate.errors)) : resolve(data)
|
|
})
|
|
}
|
|
|
|
exports.afterRequest = function (data) {
|
|
return validate('afterRequest', data)
|
|
}
|
|
|
|
exports.beforeRequest = function (data) {
|
|
return validate('beforeRequest', data)
|
|
}
|
|
|
|
exports.browser = function (data) {
|
|
return validate('browser', data)
|
|
}
|
|
|
|
exports.cache = function (data) {
|
|
return validate('cache', data)
|
|
}
|
|
|
|
exports.content = function (data) {
|
|
return validate('content', data)
|
|
}
|
|
|
|
exports.cookie = function (data) {
|
|
return validate('cookie', data)
|
|
}
|
|
|
|
exports.creator = function (data) {
|
|
return validate('creator', data)
|
|
}
|
|
|
|
exports.entry = function (data) {
|
|
return validate('entry', data)
|
|
}
|
|
|
|
exports.har = function (data) {
|
|
return validate('har', data)
|
|
}
|
|
|
|
exports.header = function (data) {
|
|
return validate('header', data)
|
|
}
|
|
|
|
exports.log = function (data) {
|
|
return validate('log', data)
|
|
}
|
|
|
|
exports.page = function (data) {
|
|
return validate('page', data)
|
|
}
|
|
|
|
exports.pageTimings = function (data) {
|
|
return validate('pageTimings', data)
|
|
}
|
|
|
|
exports.postData = function (data) {
|
|
return validate('postData', data)
|
|
}
|
|
|
|
exports.query = function (data) {
|
|
return validate('query', data)
|
|
}
|
|
|
|
exports.request = function (data) {
|
|
return validate('request', data)
|
|
}
|
|
|
|
exports.response = function (data) {
|
|
return validate('response', data)
|
|
}
|
|
|
|
exports.timings = function (data) {
|
|
return validate('timings', data)
|
|
}
|