type-arango
Version:
ArangoDB Foxx decorators and utilities for TypeScript
79 lines • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Scalar = void 0;
var joi_1 = require("../joi");
var utils_1 = require("../utils");
var Scalar = /** @class */ (function () {
function Scalar(type, name) {
if (type === void 0) { type = 'any'; }
if (type.includes('=')) {
var parts = type.split('=');
name = parts[0];
type = parts[1];
}
else if (!name) {
name = type;
type = 'string';
}
var isRequired = type.includes('!') || (name && name.includes('!')) ? true
: type.includes('?') || (name && name.includes('?')) ? false : false;
if (isRequired) {
type = type.replace(/[!?]/g, '');
name = name ? name.replace(/[!?]/g, '') : undefined;
}
var isArray = type.endsWith('[]');
if (isArray)
type = type.substr(0, type.length - 2);
var joi = isArray ? joi_1.Joi.array().items(utils_1.toJoi(type)) : utils_1.toJoi(type);
if (isRequired)
joi = joi.required();
this.name = name;
this.type = type;
this.joi = joi;
this.isArray = isArray;
this.isRequired = isRequired;
}
Scalar.prototype.toString = function () { return this.type + (this.isArray ? '[]' : ''); };
Object.defineProperty(Scalar.prototype, "query", {
get: function () {
return (this.name ? this.name + (this.isArray ? '[]' : '') + '=' : '') + this.example;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Scalar.prototype, "path", {
get: function () {
return '/' + this.example;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Scalar.prototype, "example", {
get: function () {
return Scalar.example(this.type);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Scalar.prototype, "requiredIcon", {
get: function () {
return Scalar.iconRequired(this.isRequired);
},
enumerable: false,
configurable: true
});
Scalar.iconRequired = function (isRequired) {
return isRequired ? '⚫' : '⚪';
};
Scalar.example = function (type) {
switch (type) {
default:
case 'string': return 'string';
case 'number': return 0;
case 'boolean': return true;
}
};
return Scalar;
}());
exports.Scalar = Scalar;
//# sourceMappingURL=Scalar.model.js.map