@sprucelabs/schema
Version:
Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓
34 lines (33 loc) • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractField_1 = __importDefault(require("./AbstractField"));
class FileField extends AbstractField_1.default {
static generateTemplateDetails(options) {
return {
valueType: `${options.importAs}.FileFieldValue${options.definition.isArray ? '[]' : ''}`,
};
}
validate(value, _) {
const errors = super.validate(value);
const acceptableTypes = this.definition.options?.acceptableTypes ?? [];
if (value &&
!value.base64 &&
acceptableTypes[0] !== '*' &&
acceptableTypes.indexOf(value.type) === -1) {
errors.push({
code: 'INVALID_PARAMETER',
name: this.name,
friendlyMessage: `You sent a '${value.type}' to '${this.label ?? this.name}' and it only accepts '${acceptableTypes.join("', '")}'.`,
});
}
return errors;
}
toValueType(value, _options) {
return value;
}
}
FileField.description = 'A way to handle files. Supports mime-type lookups.';
exports.default = FileField;