@emeryld/rrroutes-client 2.5.7 → 2.5.8
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/README.md +18 -2
- package/dist/index.cjs +35 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +35 -18
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.shared.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -158,7 +158,7 @@ function splitMultipartBody(body, fields) {
|
|
|
158
158
|
}
|
|
159
159
|
const fieldByInputKey = /* @__PURE__ */ new Map();
|
|
160
160
|
for (const field of fields) {
|
|
161
|
-
fieldByInputKey.set(`
|
|
161
|
+
fieldByInputKey.set(`file_${field.name}`, field.name);
|
|
162
162
|
fieldByInputKey.set(field.name, field.name);
|
|
163
163
|
}
|
|
164
164
|
const regularBody = {};
|
|
@@ -174,29 +174,46 @@ function splitMultipartBody(body, fields) {
|
|
|
174
174
|
}
|
|
175
175
|
return { regularBody, multipartFiles };
|
|
176
176
|
}
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
var isReactNativeFile = (v) => v && typeof v === "object" && typeof v.uri === "string" && typeof v.name === "string" && typeof v.type === "string";
|
|
178
|
+
var isFile = (v) => typeof File !== "undefined" && v instanceof File;
|
|
179
|
+
var isBlob = (v) => typeof Blob !== "undefined" && v instanceof Blob;
|
|
180
|
+
function toFormData(body, bodyFiles = []) {
|
|
179
181
|
const fd = new FormData();
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
const fileKeys = new Set(
|
|
183
|
+
bodyFiles.flatMap((f) => [f.name, `file_${f.name}`])
|
|
184
|
+
);
|
|
185
|
+
const appendFile = (fieldName, value) => {
|
|
186
|
+
if (value == null) return;
|
|
187
|
+
if (isReactNativeFile(value)) {
|
|
188
|
+
fd.append(fieldName, value);
|
|
189
|
+
return;
|
|
184
190
|
}
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
fd.append(k, item);
|
|
189
|
-
}
|
|
190
|
-
continue;
|
|
191
|
+
if (isFile(value)) {
|
|
192
|
+
fd.append(fieldName, value, value.name);
|
|
193
|
+
return;
|
|
191
194
|
}
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
if (isBlob(value)) {
|
|
196
|
+
fd.append(fieldName, value, "upload");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
throw new Error(`Invalid upload value for ${fieldName}`);
|
|
200
|
+
};
|
|
201
|
+
for (const [key, value] of Object.entries(body)) {
|
|
202
|
+
if (fileKeys.has(key)) {
|
|
203
|
+
if (Array.isArray(value)) {
|
|
204
|
+
for (const v of value) appendFile(key, v);
|
|
205
|
+
} else {
|
|
206
|
+
appendFile(key, value);
|
|
196
207
|
}
|
|
197
208
|
continue;
|
|
198
209
|
}
|
|
199
|
-
fd.append(
|
|
210
|
+
if (typeof value === "string") fd.append(key, value);
|
|
211
|
+
else if (typeof value === "number" || typeof value === "boolean")
|
|
212
|
+
fd.append(key, String(value));
|
|
213
|
+
else if (value == null) {
|
|
214
|
+
} else {
|
|
215
|
+
fd.append(key, JSON.stringify(value));
|
|
216
|
+
}
|
|
200
217
|
}
|
|
201
218
|
return fd;
|
|
202
219
|
}
|