UNPKG

1.65 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const util_1 = require("../util");
4const parser_helpers_1 = require("./parser-helpers");
5function parseConfig(klass) {
6 const decorator = klass.getDecoratorOrThrow("config");
7 const decoratorConfig = parser_helpers_1.getDecoratorConfigOrThrow(decorator);
8 const paramStratProp = parser_helpers_1.getObjLiteralPropOrThrow(decoratorConfig, "paramSerializationStrategy");
9 const paramsStrat = defaultConfig();
10 const paramStratLiteral = parser_helpers_1.getPropValueAsObjectOrThrow(paramStratProp);
11 const queryStrategyProp = parser_helpers_1.getObjLiteralProp(paramStratLiteral, "query");
12 if (queryStrategyProp) {
13 const queryStratLiteral = parser_helpers_1.getPropValueAsObjectOrThrow(queryStrategyProp);
14 const queryArrayStratProp = parser_helpers_1.getObjLiteralProp(queryStratLiteral, "array");
15 if (queryArrayStratProp) {
16 const queryArrayStratValue = parser_helpers_1.getPropValueAsStringOrThrow(queryArrayStratProp).getLiteralText();
17 if (!parser_helpers_1.isQueryParamArrayStrategy(queryArrayStratValue)) {
18 throw new Error(`expected a QueryParamArrayStrategy, got ${queryArrayStratValue}`);
19 }
20 paramsStrat.paramSerializationStrategy.query.array = queryArrayStratValue;
21 }
22 }
23 return util_1.ok(paramsStrat);
24}
25exports.parseConfig = parseConfig;
26function defaultConfig() {
27 return {
28 paramSerializationStrategy: {
29 query: {
30 array: "ampersand"
31 }
32 }
33 };
34}
35exports.defaultConfig = defaultConfig;