Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async validate(func, ...args) {
// The validator's `ctx` as passed to Ajv with passContext as `this`:
const params = getParams(this, ...args)
let result
try {
result = (await func(params)) ?? true
} catch (error) {
// Async validate methods need to throw their errors.
throw new Ajv.ValidationError(getErrors(error, params))
}
return result
}
}
_validateGeoJson(data) {
if (typeof data.type !== 'string') { // ToDo: Fully check against GeoJSON schema
throw new ajv.ValidationError([{
message: "Invalid GeoJSON specified (no type property)."
}]);
}
return true;
}
validate: function filesValidation(schema, data) {
filesValidation.errors = [];
const dataFileName = data.map((element) => { return element[fileNameField] });
let missingFiles = missingElements(dataFileName, schema.required);
if (missingFiles.length > 0) {
filesValidation.errors.push(new Ajv.ValidationError({
keyword: 'files',
message: `Missing required files: ${missingFiles.toString()}`,
params: { requiredFiles: schema.required, missingFiles: missingFiles }
}));
return false;
}
// Check that only the optional files exists
let allFiles = schema.required.concat(schema.optional);
let extraFiles = missingElements(allFiles, dataFileName);
if (extraFiles.length > 0) {
filesValidation.errors.push(new Ajv.ValidationError({
keyword: 'files',
message: `Extra files are not allowed. Not allowed files: ${extraFiles}`,
params: { allowedFiles: allFiles, extraFiles: extraFiles }
}));
: function(data) {
// Emulate `options.throw == true` behavior for sync validation:
// Return `true` if successful, throw `Ajv.ValidationError` otherwise.
// Use `call()` to pass `this` as context to Ajv, see passContext:
const result = validator.call(this, data)
if (!result) {
throw new Ajv.ValidationError(validator.errors)
}
return result
}
}
timeId = setTimeout(() => {
updateItemMeta({
parentKeys: options.parentKeys,
keys: [],
meta: root.value
});
}, 200);
if (Map.isMap(dataRaw) || List.isList(dataRaw)) {
dataRaw = dataRaw.toJS();
}
curAjv.errors = undefined;
if (!(yield validate(dataRaw))) {
if (!validate.errors) {
validate.errors = [];
}
throw new ValidationError(validate.errors.concat(curAjv.errors || []));
}
root.value = root.value.merge({
isValid: true
});
updateItemMeta({
parentKeys: options.parentKeys,
keys: [],
meta: root.value
});
}
catch (e) {
if (!(e instanceof ValidationError)) {
return {
isValid: false,
errMsg: e.message
};
_validateCollectionId(data) {
if (this.context.getCollection(data) === null) {
throw new ajv.ValidationError([{
message: "Collection doesn't exist."
}]);
}
return true;
}
_validateOutputFormat(data) {
if (!this.context.server().isValidOutputFormat(data)) {
throw new ajv.ValidationError([{
message: "Output format not supported."
}]);
}
return true;
}
async _validateProcessGraphId() {
var pg = await this.context.getStoredProcessGraph(data);
if (pg === null) {
throw new ajv.ValidationError([{
message: "Stored process graph doesn't exist."
}]);
}
return true;
}
setTimeout(() => {
if (data === "nick" || data === "nora") {
return resolve(true);
}
reject(new ajv.ValidationError([{ message: "idExists不是nick" }]));
}, 2000);
});
async _validateJobId() {
var job = await this.context.getJob(data);
if (job === null) {
throw new ajv.ValidationError([{
message: "Job doesn't exist."
}]);
}
return true;
}