@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
27 lines (26 loc) • 763 B
JavaScript
import { OperationVerbs } from "../constants/OperationVerbs.js";
const ALLOWED_VERBS = new Set([
...Object.keys(OperationVerbs)
.filter((v) => v !== OperationVerbs.CUSTOM)
.map((v) => v.toLowerCase())
]);
export function mapOperationOptions(args) {
let method = undefined;
let path = undefined;
const handlers = args.filter((arg) => {
if (typeof arg === "string" && ALLOWED_VERBS.has(arg.toLowerCase())) {
method = arg.toLocaleUpperCase();
return false;
}
if (typeof arg === "string" || arg instanceof RegExp) {
path = arg || "/";
return false;
}
return !!arg;
});
return {
path,
method,
use: handlers
};
}