dino-express
Version:
DinO enabled REST framework based on express
70 lines • 3.01 kB
JavaScript
;
// Copyright 2025 Quirino Brizi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Method = exports.Operation = exports.Path = void 0;
const dino_core_1 = require("dino-core");
const DecoratorMetadataRegistry_1 = require("./registry/DecoratorMetadataRegistry");
const getName = (target) => {
return target.name ?? target.constructor?.name;
};
const Path = function (pathId) {
return function (target) {
const name = getName(target);
if (name !== undefined) {
DecoratorMetadataRegistry_1.decoratorMetadataRegistry.addPath(name, pathId);
}
else {
dino_core_1.Logger.warn(`unable to extract target name while defining Path for ${pathId}`);
}
};
};
exports.Path = Path;
/**
* Allows to define the method that will handle the defined OpenAPI operation
* @param operationId the identifier of the operation as defined on the OpenAPI specification
* @param fcn the method that will handle the operation, if undefined the operationId will be used as a mapping
* @returns the method decorator handler function
*/
const Operation = function (operationId) {
return function (target, property, _descriptor) {
const name = getName(target);
if (name !== undefined) {
DecoratorMetadataRegistry_1.decoratorMetadataRegistry.addOperation(name, operationId, property);
}
else {
dino_core_1.Logger.warn(`unable to extract target name while defining Operation for ${operationId}`);
}
};
};
exports.Operation = Operation;
/**
* Allows to define the HTTP method that will be handled by the function for the defined OpenAPI operation
* @param httpMethod the identifier of the operation as defined on the OpenAPI specification
* @param fcn the method that will handle the operation, if undefined the operationId will be used as a mapping
* @returns the method decorator handler function
*/
const Method = function (httpMethod) {
return function (target, property, _descriptor) {
const name = getName(target);
if (name !== undefined) {
DecoratorMetadataRegistry_1.decoratorMetadataRegistry.addOperation(name, httpMethod.toLowerCase(), property);
}
else {
dino_core_1.Logger.warn(`unable to extract target name while defining Method for ${httpMethod}`);
}
};
};
exports.Method = Method;
//# sourceMappingURL=Api.js.map