Skip to content

Commit b96ce29

Browse files
committed
perf(util-endpoints): mutate accumulator in getEndpointHeaders reduce
1 parent e0959a9 commit b96ce29

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

packages/util-endpoints/src/utils/getEndpointHeaders.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ import { EndpointError } from "../types";
33
import { evaluateExpression } from "./evaluateExpression";
44

55
export const getEndpointHeaders = (headers: EndpointObjectHeaders, options: EvaluateOptions) =>
6-
Object.entries(headers).reduce(
7-
(acc, [headerKey, headerVal]) => ({
8-
...acc,
9-
[headerKey]: headerVal.map((headerValEntry) => {
10-
const processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
11-
if (typeof processedExpr !== "string") {
12-
throw new EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
13-
}
14-
return processedExpr;
15-
}),
16-
}),
17-
{}
18-
);
6+
Object.entries(headers).reduce((acc, [headerKey, headerVal]) => {
7+
acc[headerKey] = headerVal.map((headerValEntry) => {
8+
const processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
9+
if (typeof processedExpr !== "string") {
10+
throw new EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
11+
}
12+
return processedExpr;
13+
});
14+
return acc;
15+
}, {});

0 commit comments

Comments
 (0)