@odata2ts/http-client-fetch
Version:
HTTP client based on fetch and consumable by odata2ts
35 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeFetchConfig = exports.getDefaultConfig = void 0;
const tslib_1 = require("tslib");
const DEFAULT_CONFIG = {
// headers: { Accept: "application/json", "Content-Type": "application/json" },
cache: "no-store",
};
function getDefaultConfig(config) {
return mergeFetchConfig(DEFAULT_CONFIG, config);
}
exports.getDefaultConfig = getDefaultConfig;
function mergeFetchConfig(...configs) {
if (!configs.length) {
return undefined;
}
return configs
.filter((c) => !!c)
.reduce((collector, current) => {
const { headers } = current, passThrough = tslib_1.__rest(current, ["headers"]);
const collectedHeaders = collector.headers;
// headers as Headers object
if (headers && headers instanceof Headers) {
// @ts-ignore: fails on CI test
headers.forEach((val, key) => collectedHeaders.set(key, val));
}
// headers as plain Record<string,string>
else if (headers) {
Object.entries(headers).forEach(([key, val]) => collectedHeaders.set(key, val));
}
return Object.assign(Object.assign({}, collector), passThrough);
}, { headers: new Headers() });
}
exports.mergeFetchConfig = mergeFetchConfig;
//# sourceMappingURL=FetchRequestConfig.js.map