@ventlio/tanstack-query 0.2.49 → 0.2.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -115,16 +115,40 @@ const axiosInstance = ({ baseURL, timeout, headers, }) => {
115
115
 
116
116
  const buildFormData = (body) => {
117
117
  const formData = new FormData();
118
+ const handleArrayValue = (key, value) => {
119
+ for (const item of value) {
120
+ if (item instanceof File) {
121
+ formData.append(key, item);
122
+ }
123
+ else if (item instanceof Object) {
124
+ formData.append(key, new Blob([JSON.stringify(item)], {
125
+ type: 'application/json',
126
+ }));
127
+ }
128
+ else {
129
+ formData.append(key, item);
130
+ }
131
+ }
132
+ };
133
+ const handleObjectValue = (key, value) => {
134
+ formData.append(key, new Blob([JSON.stringify(value)], {
135
+ type: 'application/json',
136
+ }));
137
+ };
138
+ const handlePrimitiveValue = (key, value) => {
139
+ formData.append(key, value);
140
+ };
118
141
  const bodyKeys = Object.keys(body);
119
142
  bodyKeys.forEach((key) => {
120
143
  const inputValue = body[key];
121
- if (inputValue instanceof Array) {
122
- for (const value of inputValue) {
123
- formData.append(key, value);
124
- }
144
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
145
+ handleArrayValue(key, inputValue);
146
+ }
147
+ else if (inputValue instanceof Object) {
148
+ handleObjectValue(key, inputValue);
125
149
  }
126
150
  else {
127
- formData.append(key, inputValue);
151
+ handlePrimitiveValue(key, inputValue);
128
152
  }
129
153
  });
130
154
  return formData;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,16 +2,40 @@
2
2
 
3
3
  const buildFormData = (body) => {
4
4
  const formData = new FormData();
5
+ const handleArrayValue = (key, value) => {
6
+ for (const item of value) {
7
+ if (item instanceof File) {
8
+ formData.append(key, item);
9
+ }
10
+ else if (item instanceof Object) {
11
+ formData.append(key, new Blob([JSON.stringify(item)], {
12
+ type: 'application/json',
13
+ }));
14
+ }
15
+ else {
16
+ formData.append(key, item);
17
+ }
18
+ }
19
+ };
20
+ const handleObjectValue = (key, value) => {
21
+ formData.append(key, new Blob([JSON.stringify(value)], {
22
+ type: 'application/json',
23
+ }));
24
+ };
25
+ const handlePrimitiveValue = (key, value) => {
26
+ formData.append(key, value);
27
+ };
5
28
  const bodyKeys = Object.keys(body);
6
29
  bodyKeys.forEach((key) => {
7
30
  const inputValue = body[key];
8
- if (inputValue instanceof Array) {
9
- for (const value of inputValue) {
10
- formData.append(key, value);
11
- }
31
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
32
+ handleArrayValue(key, inputValue);
33
+ }
34
+ else if (inputValue instanceof Object) {
35
+ handleObjectValue(key, inputValue);
12
36
  }
13
37
  else {
14
- formData.append(key, inputValue);
38
+ handlePrimitiveValue(key, inputValue);
15
39
  }
16
40
  });
17
41
  return formData;
@@ -1 +1 @@
1
- {"version":3,"file":"buildFormData.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"buildFormData.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ventlio/tanstack-query",
3
- "version": "0.2.49",
3
+ "version": "0.2.51",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "contributors": [
@@ -1,16 +1,47 @@
1
1
  export const buildFormData = (body: Record<string, any>) => {
2
2
  const formData = new FormData();
3
3
 
4
+ const handleArrayValue = (key: string, value: any) => {
5
+ for (const item of value) {
6
+ if (item instanceof File) {
7
+ formData.append(key, item);
8
+ } else if (item instanceof Object) {
9
+ formData.append(
10
+ key,
11
+ new Blob([JSON.stringify(item)], {
12
+ type: 'application/json',
13
+ })
14
+ );
15
+ } else {
16
+ formData.append(key, item);
17
+ }
18
+ }
19
+ };
20
+
21
+ const handleObjectValue = (key: string, value: any) => {
22
+ formData.append(
23
+ key,
24
+ new Blob([JSON.stringify(value)], {
25
+ type: 'application/json',
26
+ })
27
+ );
28
+ };
29
+
30
+ const handlePrimitiveValue = (key: string, value: any) => {
31
+ formData.append(key, value);
32
+ };
33
+
4
34
  const bodyKeys = Object.keys(body);
5
35
 
6
36
  bodyKeys.forEach((key) => {
7
37
  const inputValue = body[key];
8
- if (inputValue instanceof Array) {
9
- for (const value of inputValue) {
10
- formData.append(key, value);
11
- }
38
+
39
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
40
+ handleArrayValue(key, inputValue);
41
+ } else if (inputValue instanceof Object) {
42
+ handleObjectValue(key, inputValue);
12
43
  } else {
13
- formData.append(key, inputValue);
44
+ handlePrimitiveValue(key, inputValue);
14
45
  }
15
46
  });
16
47