@ventlio/tanstack-query 0.2.50 → 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,23 +115,41 @@ 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 is array and the first item is array, append everything to the
122
- if (inputValue instanceof Array && inputValue.length > 0) {
123
- // append all files
124
- for (const file of inputValue) {
125
- formData.append(key, file);
126
- }
144
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
145
+ handleArrayValue(key, inputValue);
127
146
  }
128
- // else if inputValue is Object upload it as blob
129
147
  else if (inputValue instanceof Object) {
130
- formData.append(key, new Blob([JSON.stringify(inputValue)], {
131
- type: 'application/json',
132
- }));
148
+ handleObjectValue(key, inputValue);
149
+ }
150
+ else {
151
+ handlePrimitiveValue(key, inputValue);
133
152
  }
134
- formData.append(key, inputValue);
135
153
  });
136
154
  return formData;
137
155
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,23 +2,41 @@
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 is array and the first item is array, append everything to the
9
- if (inputValue instanceof Array && inputValue.length > 0) {
10
- // append all files
11
- for (const file of inputValue) {
12
- formData.append(key, file);
13
- }
31
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
32
+ handleArrayValue(key, inputValue);
14
33
  }
15
- // else if inputValue is Object upload it as blob
16
34
  else if (inputValue instanceof Object) {
17
- formData.append(key, new Blob([JSON.stringify(inputValue)], {
18
- type: 'application/json',
19
- }));
35
+ handleObjectValue(key, inputValue);
36
+ }
37
+ else {
38
+ handlePrimitiveValue(key, inputValue);
20
39
  }
21
- formData.append(key, inputValue);
22
40
  });
23
41
  return formData;
24
42
  };
@@ -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.50",
3
+ "version": "0.2.51",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "contributors": [
@@ -1,29 +1,48 @@
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
38
 
9
- // if inputValue is array and the first item is array, append everything to the
10
- if (inputValue instanceof Array && inputValue.length > 0) {
11
- // append all files
12
- for (const file of inputValue) {
13
- formData.append(key, file);
14
- }
39
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
40
+ handleArrayValue(key, inputValue);
41
+ } else if (inputValue instanceof Object) {
42
+ handleObjectValue(key, inputValue);
43
+ } else {
44
+ handlePrimitiveValue(key, inputValue);
15
45
  }
16
- // else if inputValue is Object upload it as blob
17
- else if (inputValue instanceof Object) {
18
- formData.append(
19
- key,
20
- new Blob([JSON.stringify(inputValue)], {
21
- type: 'application/json',
22
- })
23
- );
24
- }
25
-
26
- formData.append(key, inputValue);
27
46
  });
28
47
 
29
48
  return formData;