@ventlio/tanstack-query 0.2.50 → 0.2.52

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,46 @@ 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
+ if (value instanceof File) {
135
+ formData.append(key, value);
136
+ }
137
+ else {
138
+ formData.append(key, new Blob([JSON.stringify(value)], {
139
+ type: 'application/json',
140
+ }));
141
+ }
142
+ };
143
+ const handlePrimitiveValue = (key, value) => {
144
+ formData.append(key, value);
145
+ };
118
146
  const bodyKeys = Object.keys(body);
119
147
  bodyKeys.forEach((key) => {
120
148
  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
- }
149
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
150
+ handleArrayValue(key, inputValue);
127
151
  }
128
- // else if inputValue is Object upload it as blob
129
152
  else if (inputValue instanceof Object) {
130
- formData.append(key, new Blob([JSON.stringify(inputValue)], {
131
- type: 'application/json',
132
- }));
153
+ handleObjectValue(key, inputValue);
154
+ }
155
+ else {
156
+ handlePrimitiveValue(key, inputValue);
133
157
  }
134
- formData.append(key, inputValue);
135
158
  });
136
159
  return formData;
137
160
  };
@@ -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,46 @@
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
+ if (value instanceof File) {
22
+ formData.append(key, value);
23
+ }
24
+ else {
25
+ formData.append(key, new Blob([JSON.stringify(value)], {
26
+ type: 'application/json',
27
+ }));
28
+ }
29
+ };
30
+ const handlePrimitiveValue = (key, value) => {
31
+ formData.append(key, value);
32
+ };
5
33
  const bodyKeys = Object.keys(body);
6
34
  bodyKeys.forEach((key) => {
7
35
  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
- }
36
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
37
+ handleArrayValue(key, inputValue);
14
38
  }
15
- // else if inputValue is Object upload it as blob
16
39
  else if (inputValue instanceof Object) {
17
- formData.append(key, new Blob([JSON.stringify(inputValue)], {
18
- type: 'application/json',
19
- }));
40
+ handleObjectValue(key, inputValue);
41
+ }
42
+ else {
43
+ handlePrimitiveValue(key, inputValue);
20
44
  }
21
- formData.append(key, inputValue);
22
45
  });
23
46
  return formData;
24
47
  };
@@ -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.52",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "contributors": [
@@ -1,29 +1,52 @@
1
1
  export const buildFormData = (body: Record<string, any>) => {
2
2
  const formData = new FormData();
3
3
 
4
- const bodyKeys = Object.keys(body);
5
-
6
- bodyKeys.forEach((key) => {
7
- const inputValue = body[key];
8
-
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);
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);
14
17
  }
15
18
  }
16
- // else if inputValue is Object upload it as blob
17
- else if (inputValue instanceof Object) {
19
+ };
20
+
21
+ const handleObjectValue = (key: string, value: any) => {
22
+ if (value instanceof File) {
23
+ formData.append(key, value);
24
+ } else {
18
25
  formData.append(
19
26
  key,
20
- new Blob([JSON.stringify(inputValue)], {
27
+ new Blob([JSON.stringify(value)], {
21
28
  type: 'application/json',
22
29
  })
23
30
  );
24
31
  }
32
+ };
33
+
34
+ const handlePrimitiveValue = (key: string, value: any) => {
35
+ formData.append(key, value);
36
+ };
25
37
 
26
- formData.append(key, inputValue);
38
+ const bodyKeys = Object.keys(body);
39
+
40
+ bodyKeys.forEach((key) => {
41
+ const inputValue = body[key];
42
+
43
+ if (Array.isArray(inputValue) && inputValue.length > 0) {
44
+ handleArrayValue(key, inputValue);
45
+ } else if (inputValue instanceof Object) {
46
+ handleObjectValue(key, inputValue);
47
+ } else {
48
+ handlePrimitiveValue(key, inputValue);
49
+ }
27
50
  });
28
51
 
29
52
  return formData;