1 | import { lowercaseKeys } from "./util/lowercase-keys.js";
|
2 | import { mergeDeep } from "./util/merge-deep.js";
|
3 | import { removeUndefinedProperties } from "./util/remove-undefined-properties.js";
|
4 | function merge(defaults, route, options) {
|
5 | if (typeof route === "string") {
|
6 | let [method, url] = route.split(" ");
|
7 | options = Object.assign(url ? { method, url } : { url: method }, options);
|
8 | } else {
|
9 | options = Object.assign({}, route);
|
10 | }
|
11 | options.headers = lowercaseKeys(options.headers);
|
12 | removeUndefinedProperties(options);
|
13 | removeUndefinedProperties(options.headers);
|
14 | const mergedOptions = mergeDeep(defaults || {}, options);
|
15 | if (options.url === "/graphql") {
|
16 | if (defaults && defaults.mediaType.previews?.length) {
|
17 | mergedOptions.mediaType.previews = defaults.mediaType.previews.filter(
|
18 | (preview) => !mergedOptions.mediaType.previews.includes(preview)
|
19 | ).concat(mergedOptions.mediaType.previews);
|
20 | }
|
21 | mergedOptions.mediaType.previews = (mergedOptions.mediaType.previews || []).map((preview) => preview.replace(/-preview/, ""));
|
22 | }
|
23 | return mergedOptions;
|
24 | }
|
25 | export {
|
26 | merge
|
27 | };
|