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

39 lines (32 loc) 1.05 kB
import Schema from '../schemas/schema' import Field from './field' export default class FieldSchemas extends Field { constructor (basePath, path, userSchema, options, internal) { super(basePath, path, options, internal) this.schema = new Schema(userSchema, [...basePath, ...path, '..'], false) } validate (data, basePath) { if (this.internal) return const array = this.getByPath(data) if (!Array.isArray(array)) { this.typeError(Array, array, basePath) } array.forEach((value, index) => { if (value !== Object(value)) this.typeError(Object, value, basePath, [index]) const subPath = [...basePath, ...this.path, index] this.schema.validate(value, subPath) }) } convertToModelValue (array) { return array.map(document => { const model = {} return this.schema.documentToModel(model, document) }) } convertToDocumentValue (array) { return array.map(model => { const document = {} return this.schema.modelToDocument(model, document) }) } }