@avonjs/avonjs
Version:
A fluent Node.js API generator.
88 lines (87 loc) • 2.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const joi_1 = __importDefault(require("joi"));
const Field_1 = __importDefault(require("./Field"));
const TextFilter_1 = __importDefault(require("./Filters/TextFilter"));
class Text extends Field_1.default {
/**
* The callback to be used for the field's default value.
*/
defaultCallback = () => {
return this.isNullable() ? this.nullValue() : '';
};
/**
* The validation rules callback for creation and updates.
*/
rulesSchema = joi_1.default.string();
/**
* The validation rules callback for creation.
*/
creationRulesSchema = joi_1.default.string();
/**
* The validation rules callback for updates.
*/
updateRulesSchema = joi_1.default.string();
/**
* Indicates a minimum acceptable value.
*/
minimum;
/**
* Indicates a maximum acceptable value.
*/
maximum;
/**
* Specifies the minimum number of string characters.
*/
min(minimum = 0) {
this.minimum = minimum;
this.rules(joi_1.default.string().min(minimum));
return this;
}
/**
* Specifies the maximum number of string characters.
*/
max(maximum = 0) {
this.maximum = maximum;
this.rules(joi_1.default.string().max(maximum));
return this;
}
/**
* Mutate the field value for response.
*/
getMutatedValue(request, value) {
return String(value);
}
/**
* Determine field is filterable or not.
*/
isFilterable() {
return true;
}
/**
* Determine field is orderable or not.
*/
isOrderable() {
return true;
}
/**
* Make the field filter.
*/
makeFilter(request) {
return new TextFilter_1.default(this);
}
/**
* Get the swagger-ui schema.
*/
baseSchema(request) {
return {
...super.baseSchema(request),
minLength: this.minimum,
maxLength: this.maximum,
};
}
}
exports.default = Text;