@emeryld/rrroutes-client 2.7.7 → 2.7.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/dist/index.cjs +13 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -281,6 +281,7 @@ function assertFileFieldValue(sourceKey, targetField, value) {
|
|
|
281
281
|
if (value == null) return;
|
|
282
282
|
if (isBlobLike(value)) return;
|
|
283
283
|
if (isReactNativeFile(value)) return;
|
|
284
|
+
if (isImagePickerAsset(value)) return;
|
|
284
285
|
if (typeof FileList !== "undefined" && value instanceof FileList) {
|
|
285
286
|
for (const item of Array.from(value)) {
|
|
286
287
|
if (!isBlobLike(item)) {
|
|
@@ -293,16 +294,16 @@ function assertFileFieldValue(sourceKey, targetField, value) {
|
|
|
293
294
|
}
|
|
294
295
|
if (Array.isArray(value)) {
|
|
295
296
|
for (const item of value) {
|
|
296
|
-
if (!isBlobLike(item) && !isReactNativeFile(item)) {
|
|
297
|
+
if (!isBlobLike(item) && !isReactNativeFile(item) && !isImagePickerAsset(item)) {
|
|
297
298
|
throw new Error(
|
|
298
|
-
`Multipart field "${sourceKey}" must contain Blob/File values for "${targetField}".`
|
|
299
|
+
`Multipart field "${sourceKey}" must contain Blob/File, ReactNativeFile or ImagePickerAsset values for "${targetField}".`
|
|
299
300
|
);
|
|
300
301
|
}
|
|
301
302
|
}
|
|
302
303
|
return;
|
|
303
304
|
}
|
|
304
305
|
throw new Error(
|
|
305
|
-
`Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, Blob[]/ReactNativeFile[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
|
|
306
|
+
`Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, ImagePickerAsset, Blob[]/ReactNativeFile[]/ImagePickerAsset[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
|
|
306
307
|
);
|
|
307
308
|
}
|
|
308
309
|
function splitMultipartBody(body, fields) {
|
|
@@ -331,6 +332,7 @@ function splitMultipartBody(body, fields) {
|
|
|
331
332
|
return { regularBody, multipartFiles };
|
|
332
333
|
}
|
|
333
334
|
var isReactNativeFile = (v) => v && typeof v === "object" && typeof v.uri === "string" && typeof v.name === "string" && typeof v.type === "string";
|
|
335
|
+
var isImagePickerAsset = (v) => v && typeof v === "object" && typeof v.uri === "string" && (typeof v.fileName === "string" || typeof v.mimeType === "string" || typeof v.width === "number" || typeof v.height === "number");
|
|
334
336
|
var isFile = (v) => typeof File !== "undefined" && v instanceof File;
|
|
335
337
|
var isBlob = (v) => typeof Blob !== "undefined" && v instanceof Blob;
|
|
336
338
|
function toFormData(body, bodyFiles = []) {
|
|
@@ -342,6 +344,14 @@ function toFormData(body, bodyFiles = []) {
|
|
|
342
344
|
fd.append(fieldName, value);
|
|
343
345
|
return;
|
|
344
346
|
}
|
|
347
|
+
if (isImagePickerAsset(value)) {
|
|
348
|
+
fd.append(fieldName, {
|
|
349
|
+
uri: value.uri,
|
|
350
|
+
name: value.fileName ?? "upload",
|
|
351
|
+
type: value.mimeType ?? "application/octet-stream"
|
|
352
|
+
});
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
345
355
|
if (isFile(value)) {
|
|
346
356
|
fd.append(fieldName, value, value.name);
|
|
347
357
|
return;
|