final-orm
Version:
> Please check out https://github.com/oknoah/final and https://github.com/oknoah/final/packages/arangolize for similar projects that MAY be more up to date
52 lines (40 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fieldType = require('./field-type');
var _fieldType2 = _interopRequireDefault(_fieldType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class FieldTypes extends _fieldType2.default {
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));
}
}
exports.default = FieldTypes;