这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
4 changes: 1 addition & 3 deletions workers/loc.api/data-validator/filter-schemas/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict'

const path = require('node:path')

const FILTER_SCHEMA_NAMES = require('../filter.schema.names')
const { requireSchemas } = require('../helpers')

module.exports = requireSchemas(
FILTER_SCHEMA_NAMES,
path.join(__dirname, '../filter-schemas')
__dirname
)
58 changes: 35 additions & 23 deletions workers/loc.api/data-validator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,33 @@ const FILTER_SCHEMA_IDS = require('./filter.schema.ids')
const schemas = require('./schemas')
const filterSchemas = require('./filter-schemas')

const ajv = new Ajv({
// Compile schema on initialization
schemas: [
...Object.values(schemas),
...Object.values(filterSchemas)
],

// Strict mode
strict: true,
strictRequired: true,
allowMatchingProperties: true,
allowUnionTypes: true,

$data: true,
ownProperties: true,
allErrors: true,
messages: true,
formats: { reserved: true },
verbose: isDevEnv
})
addFormats(ajv)
let ajv

const init = () => {
ajv = new Ajv({
// Compile schema on initialization
schemas: [
...Object.values(schemas),
...Object.values(filterSchemas)
],

// Strict mode
strict: true,
strictRequired: true,
allowMatchingProperties: true,
allowUnionTypes: true,

$data: true,
ownProperties: true,
allErrors: true,
messages: true,
formats: { reserved: true },
verbose: isDevEnv
})
addFormats(ajv)

return module.exports
}

const addSchemas = (schemas = []) => {
const _schemas = Array.isArray(schemas)
Expand Down Expand Up @@ -104,15 +110,17 @@ const reinit = (args) => {
schemaIds,
filterSchemaNames,
filterSchemaIds,
schemas = []
schemas = {}
} = args ?? {}

Object.assign(SCHEMA_NAMES, schemaNames)
Object.assign(SCHEMA_IDS, schemaIds)
Object.assign(FILTER_SCHEMA_NAMES, filterSchemaNames)
Object.assign(FILTER_SCHEMA_IDS, filterSchemaIds)

addSchemas(schemas)
addSchemas(Object.values(schemas))

return module.exports
}

module.exports = {
Expand All @@ -122,6 +130,10 @@ module.exports = {
FILTER_SCHEMA_NAMES,
FILTER_SCHEMA_IDS,

schemas,
filterSchemas,

init,
reinit,
addSchemas,
validate
Expand Down
4 changes: 4 additions & 0 deletions workers/loc.api/data-validator/schemas/defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ module.exports = {
},
method: {
type: 'string'
},
candleTimeframe: {
type: 'string',
minLength: 2
}
}
}
3 changes: 1 addition & 2 deletions workers/loc.api/data-validator/schemas/getCandlesFileReq.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ module.exports = {
$ref: 'defs#/definitions/sort'
},
timeframe: {
type: 'string',
minLength: 2
$ref: 'defs#/definitions/candleTimeframe'
},
section: {
type: 'string',
Expand Down
3 changes: 1 addition & 2 deletions workers/loc.api/data-validator/schemas/getCandlesReq.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ module.exports = {
$ref: 'defs#/definitions/sort'
},
timeframe: {
type: 'string',
minLength: 2
$ref: 'defs#/definitions/candleTimeframe'
},
section: {
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion workers/loc.api/di/core.deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ module.exports = () => {
[TYPES.CONF]
)
}).inSingletonScope()
bind(TYPES.DataValidator).toConstantValue(dataValidator)
bind(TYPES.DataValidator).toConstantValue(dataValidator.init())
})
}
4 changes: 2 additions & 2 deletions workers/loc.api/generate-report-file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const _truncateFileNameEnding = (name) => {
return `${cleanedName[0].toLowerCase()}${cleanedName.slice(1)}`
}

const _getfilterApiMethodNamesAndArgs = (
const _getFilterApiMethodNamesAndArgs = (
name,
reqArgs
) => {
Expand Down Expand Up @@ -141,7 +141,7 @@ module.exports = (
rootPath,
conf
})
const checkingDataArr = _getfilterApiMethodNamesAndArgs(
const checkingDataArr = _getFilterApiMethodNamesAndArgs(
name,
args
)
Expand Down
Loading