faker-api
Version:
A fully customizible rest api faking package that allows you to mock , clone and fake Rest API with fake yet realistic data
65 lines • 2.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewSet = void 0;
var ViewSet = /** @class */ (function () {
function ViewSet() {
}
ViewSet.prototype.description = function () {
return "No description";
};
/**
* A alias funtion for the decorator `_action` that converts the ViewSet nethod into a request handler
* @param detail - Specifics if an id is required or not for the method
* @methods - The http request methods the Viewset method will handle
* pathName - The sufix of the request path that the method would handle, id non is peovided then the name of the method is used
* description - The discription od the Viewset route, (used to generated the api documentation)
* @returns - The decorator function _action
*/
ViewSet.action = _action;
return ViewSet;
}());
exports.ViewSet = ViewSet;
/**
* A decorator function that converts the ViewSet nethod into a request handler
* @param detail - Specifics if an id is required or not for the method
* @methods - The http request methods the Viewset method will handle
* pathName - The sufix of the request path that the method would handle, id non is peovided then the name of the method is used
* description - The discription od the Viewset route, (used to generated the api documentation)
* @returns - The decorator function _action
*/
function _action(detail, methods, pathName, description) {
if (detail === void 0) { detail = false; }
if (methods === void 0) { methods = ["GET"]; }
if (pathName === void 0) { pathName = null; }
if (description === void 0) { description = "No Description"; }
return function (target, actionKey, actionHandler) {
var viewset = target;
// Insuring that the viewset class object as __action__ and __path__ defined
if (!viewset.__actions__)
viewset.__actions__ = new Map();
if (!viewset.__paths__)
viewset.__paths__ = new Map();
/***
* The __actions__ contains a Map mapping various handlers to a handler method name
* while the __paths__ contains various url paths mapping to the method name
*/
if (!viewset.__actions__.has(actionKey)) {
viewset.__actions__.set(actionKey, {
methods: methods,
description: description,
method: actionKey,
detail: detail,
handler: actionHandler.value,
});
var path = (pathName ? pathName : actionKey) + "/";
if (path.startsWith("/")) {
path.replace(/^\//, "");
}
if (detail) {
path = ":id/" + path;
}
viewset.__paths__.set(path, actionKey);
}
};
}
//# sourceMappingURL=viewset.js.map
;