@sapphire/plugin-api
Version:
Plugin for @sapphire/framework to expose a REST API
50 lines (47 loc) • 1.96 kB
JavaScript
;
var pieces = require('@sapphire/pieces');
var utilities = require('@sapphire/utilities');
var RouterRoot_cjs = require('./router/RouterRoot.cjs');
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var _Route = class _Route extends pieces.Piece {
constructor(context, options = {}) {
super(context, options);
/**
* (RFC 7230 3.3.2) The maximum decimal number of octets.
*/
__publicField(this, "maximumBodyLength");
/**
* The path this route represents.
*/
__publicField(this, "path");
/**
* The methods this route accepts.
*/
__publicField(this, "methods");
const api = this.container.server.options;
const path = RouterRoot_cjs.RouterRoot.normalize(api.prefix);
const methods = new Set(options.methods);
if (options.route) {
path.push(...RouterRoot_cjs.RouterRoot.normalize(options.route));
} else {
let lastPart = context.name;
const implied = RouterRoot_cjs.RouterRoot.extractMethod(lastPart);
if (!utilities.isNullish(implied)) {
lastPart = lastPart.slice(0, lastPart.length - implied.length - 1);
methods.add(implied);
}
path.push(...RouterRoot_cjs.RouterRoot.normalize(RouterRoot_cjs.RouterRoot.makeRoutePathForPiece(this.location.directories, lastPart)));
}
this.path = path;
this.methods = methods;
this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
}
};
__name(_Route, "Route");
var Route = _Route;
exports.Route = Route;
//# sourceMappingURL=Route.cjs.map
//# sourceMappingURL=Route.cjs.map