MCPcopy Create free account
hub / github.com/dadi/api / validate

Method validate

dadi/lib/model/schemaStore.js:480–526  ·  view source on GitHub ↗
({fields, name, property, requiredFields = [], settings})

Source from the content-addressed store, hash-verified

478 }
479
480 async validate({fields, name, property, requiredFields = [], settings}) {
481 let combinedErrors = []
482
483 try {
484 const schema = {
485 name: {
486 type: 'string',
487 required: requiredFields.includes('name')
488 },
489 property: {
490 type: 'string',
491 required: requiredFields.includes('property')
492 }
493 }
494
495 await this.validator.validateDocument({
496 document: {name, property},
497 schema
498 })
499 } catch (errors) {
500 combinedErrors = combinedErrors.concat(errors)
501 }
502
503 if (settings !== undefined) {
504 try {
505 await this.validator.validateSchemaSettings(settings)
506 } catch (errors) {
507 combinedErrors = combinedErrors.concat(errors)
508 }
509 }
510
511 if (fields !== undefined) {
512 try {
513 await this.validator.validateSchemaFields(fields)
514 } catch (errors) {
515 combinedErrors = combinedErrors.concat(errors)
516 }
517 }
518
519 if (combinedErrors.length > 0) {
520 const error = new Error('VALIDATION_ERROR')
521
522 error.errors = combinedErrors
523
524 throw error
525 }
526 }
527}
528
529module.exports = new SchemaStore()

Callers 8

addFieldsMethod · 0.95
createMethod · 0.95
deleteFieldsMethod · 0.95
updateFieldsMethod · 0.95
updateSettingsMethod · 0.95
key.jsFile · 0.80
client.jsFile · 0.80
role.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected