1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const util_1 = require("../util");
|
4 | const parser_helpers_1 = require("./parser-helpers");
|
5 | function 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 | }
|
25 | exports.parseConfig = parseConfig;
|
26 | function defaultConfig() {
|
27 | return {
|
28 | paramSerializationStrategy: {
|
29 | query: {
|
30 | array: "ampersand"
|
31 | }
|
32 | }
|
33 | };
|
34 | }
|
35 | exports.defaultConfig = defaultConfig;
|