UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const util_1 = require("../util");
4const body_parser_1 = require("./body-parser");
5const headers_parser_1 = require("./headers-parser");
6const parser_helpers_1 = require("./parser-helpers");
7const path_params_parser_1 = require("./path-params-parser");
8const query_params_parser_1 = require("./query-params-parser");
9function parseRequest(method, typeTable, lociTable) {
10 method.getDecoratorOrThrow("request");
11 const headersParam = parser_helpers_1.getParamWithDecorator(method, "headers");
12 const pathParamsParam = parser_helpers_1.getParamWithDecorator(method, "pathParams");
13 const queryParamsParam = parser_helpers_1.getParamWithDecorator(method, "queryParams");
14 const bodyParam = parser_helpers_1.getParamWithDecorator(method, "body");
15 const headers = [];
16 if (headersParam) {
17 const headersResult = headers_parser_1.parseHeaders(headersParam, typeTable, lociTable);
18 if (headersResult.isErr())
19 return headersResult;
20 headers.push(...headersResult.unwrap());
21 }
22 const pathParams = [];
23 if (pathParamsParam) {
24 const pathParamsResult = path_params_parser_1.parsePathParams(pathParamsParam, typeTable, lociTable);
25 if (pathParamsResult.isErr())
26 return pathParamsResult;
27 pathParams.push(...pathParamsResult.unwrap());
28 }
29 const queryParams = [];
30 if (queryParamsParam) {
31 const queryParamsResult = query_params_parser_1.parseQueryParams(queryParamsParam, typeTable, lociTable);
32 if (queryParamsResult.isErr())
33 return queryParamsResult;
34 queryParams.push(...queryParamsResult.unwrap());
35 }
36 let body;
37 if (bodyParam) {
38 const bodyResult = body_parser_1.parseBody(bodyParam, typeTable, lociTable);
39 if (bodyResult.isErr())
40 return bodyResult;
41 body = bodyResult.unwrap();
42 }
43 return util_1.ok({
44 headers,
45 pathParams,
46 queryParams,
47 body
48 });
49}
50exports.parseRequest = parseRequest;