UNPKG

@linaframework/arango-orm

Version:

> Please check out https://github.com/awesome-graphql-space/lina and https://github.com/oknoah/final/packages/arangolize for similar projects that MAY be more up to date

48 lines (37 loc) 896 B
import FieldType from './field-type' export default class FieldTypes extends FieldType { constructor (basePath, path, type, options, internal) { super(basePath, path, type, options, internal) } validate (data, basePath) { if (this.internal) return let array = this.getByPath(data) if (!array && this.options.optional) { return } if (!Array.isArray(array)) { this.typeError(Array, array, basePath) } array.forEach((value, index) => { if (!this.validateValue(value)) { this.typeError(this.type, value, basePath, [index]) } }) } convertToModelValue (array) { if (!array && this.options.optional) { return } return array.map(value => super.convertToModelValue(value) ) } convertToDocumentValue (array) { if (!array && this.options.optional) { return } return array.map(value => super.convertToDocumentValue(value) ) } }