@trapi/metadata
Version:
Generate REST-API metadata scheme from TypeScript Decorators.
68 lines • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParameterError = void 0;
/*
* Copyright (c) 2022-2023.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
const typescript_1 = require("typescript");
const error_1 = require("../../error");
class ParameterError extends error_1.BaseError {
static typeUnsupported(context) {
let text = `@${context.decoratorName}('${context.propertyName}') Does not support '${context.type.typeName}' type`;
if (context.node) {
const location = ParameterError.getCurrentLocation(context.node);
if (location) {
text += ` at location ${location}`;
}
}
return new ParameterError(`${text}.`);
}
static methodUnsupported(context) {
let text = `@${context.decoratorName}('${context.propertyName}') Does not support method ${context.method}`;
if (context.node) {
const location = ParameterError.getCurrentLocation(context.node);
if (location) {
text += ` at location ${location}`;
}
}
return new ParameterError(`${text}.`);
}
static invalidPathMatch(context) {
let text = `@${context.decoratorName}('${context.propertyName}') Does not exist in path ${context.path}`;
if (context.node) {
const location = ParameterError.getCurrentLocation(context.node);
if (location) {
text += ` at location ${location}`;
}
}
return new ParameterError(`${text}.`);
}
static scopeRequired(context) {
let text = `@${context.decoratorName}(xxx) a scope is required`;
if (context.node) {
const location = ParameterError.getCurrentLocation(context.node);
if (location) {
text += ` at location ${location}`;
}
}
return new ParameterError(`${text}.`);
}
static invalidExampleSchema() {
return new ParameterError('The example jsdoc schema is invalid.');
}
static getCurrentLocation(node) {
const parts = [];
if ((0, typescript_1.isMethodDeclaration)(node.parent)) {
parts.push(node.parent.name.getText());
if ((0, typescript_1.isClassDeclaration)(node.parent.parent)) {
parts.unshift(node.parent.parent.name.text);
}
}
return parts.join('.');
}
}
exports.ParameterError = ParameterError;
//# sourceMappingURL=error.js.map