Skip to content

Commit

Permalink
Merge pull request #42 from torusresearch/feat/remove-lodash
Browse files Browse the repository at this point in the history
replace lodash with deepmerge
  • Loading branch information
chaitanyapotti authored Jun 13, 2024
2 parents 9efa240 + d423ee5 commit eb6f46f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 45 deletions.
43 changes: 6 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
},
"dependencies": {
"lodash.merge": "^4.6.2",
"deepmerge": "^4.3.1",
"loglevel": "^1.9.1"
},
"devDependencies": {
Expand All @@ -39,7 +39,6 @@
"@toruslabs/config": "^2.1.0",
"@toruslabs/eslint-config-typescript": "^3.3.1",
"@toruslabs/torus-scripts": "^6.0.1",
"@types/lodash.merge": "^4.6.9",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
Expand Down
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-throw-literal */
import type { Span, StartSpanOptions } from "@sentry/types";
import merge from "lodash.merge";
import merge from "deepmerge";
import logLevel, { levels, LogLevelDesc } from "loglevel";

const log = logLevel.getLogger("http-helpers");
Expand Down Expand Up @@ -139,7 +139,8 @@ export const get = async <T>(url: string, options_: RequestInit = {}, customOpti
if (customOptions.useAPIKey) {
defaultOptions.headers = { ...defaultOptions.headers, ...getApiKeyHeaders() };
}
const options = merge(defaultOptions, options_, { method: "GET" });
options_.method = "GET";
const options = merge<RequestInit>(defaultOptions, options_);
const response = await fetchAndTrace(url, options);
if (response.ok) {
const responseContentType = response.headers.get("content-type");
Expand All @@ -162,7 +163,8 @@ export const post = <T>(url: string, data: Data = {}, options_: RequestInit = {}
if (customOptions.useAPIKey) {
defaultOptions.headers = { ...defaultOptions.headers, ...getApiKeyHeaders() };
}
const options = merge(defaultOptions, options_, { method: "POST" });
options_.method = "POST";
const options = merge(defaultOptions, options_);

// deep merge changes the structure of form data and url encoded data ,
// so we should not deepmerge body data
Expand Down Expand Up @@ -209,7 +211,8 @@ export const patch = async <T>(url: string, data: Data = {}, options_: RequestIn
if (customOptions.useAPIKey) {
defaultOptions.headers = { ...defaultOptions.headers, ...getApiKeyHeaders() };
}
const options = merge(defaultOptions, options_, { method: "PATCH" });
options_.method = "PATCH";
const options = merge(defaultOptions, options_);
// deep merge changes the structure of form data and url encoded data ,
// so we should not deepmerge body data
if (customOptions.isUrlEncodedData) {
Expand Down Expand Up @@ -247,7 +250,8 @@ export const put = async <T>(url: string, data: Data = {}, options_: RequestInit
if (customOptions.useAPIKey) {
defaultOptions.headers = { ...defaultOptions.headers, ...getApiKeyHeaders() };
}
const options = merge(defaultOptions, options_, { method: "PUT" });
options_.method = "PUT";
const options = merge(defaultOptions, options_);
// deep merge changes the structure of form data and url encoded data ,
// so we should not deepmerge body data
if (customOptions.isUrlEncodedData) {
Expand Down Expand Up @@ -285,7 +289,8 @@ export const remove = async <T>(url: string, data: Data = {}, options_: RequestI
if (customOptions.useAPIKey) {
defaultOptions.headers = { ...defaultOptions.headers, ...getApiKeyHeaders() };
}
const options = merge(defaultOptions, options_, { method: "DELETE" });
options_.method = "DELETE";
const options = merge(defaultOptions, options_);
if (customOptions.isUrlEncodedData) {
// for multipart request browser/client will add multipart content type
// along with multipart boundary , so for multipart request send
Expand Down

0 comments on commit eb6f46f

Please sign in to comment.