({fields, name, property, requiredFields = [], settings})
| 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 | |
| 529 | module.exports = new SchemaStore() |
no outgoing calls
no test coverage detected