@emeryld/rrroutes-client 2.7.6 → 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 CHANGED
@@ -317,6 +317,7 @@ function assertFileFieldValue(sourceKey, targetField, value) {
317
317
  if (value == null) return;
318
318
  if (isBlobLike(value)) return;
319
319
  if (isReactNativeFile(value)) return;
320
+ if (isImagePickerAsset(value)) return;
320
321
  if (typeof FileList !== "undefined" && value instanceof FileList) {
321
322
  for (const item of Array.from(value)) {
322
323
  if (!isBlobLike(item)) {
@@ -329,16 +330,16 @@ function assertFileFieldValue(sourceKey, targetField, value) {
329
330
  }
330
331
  if (Array.isArray(value)) {
331
332
  for (const item of value) {
332
- if (!isBlobLike(item) && !isReactNativeFile(item)) {
333
+ if (!isBlobLike(item) && !isReactNativeFile(item) && !isImagePickerAsset(item)) {
333
334
  throw new Error(
334
- `Multipart field "${sourceKey}" must contain Blob/File values for "${targetField}".`
335
+ `Multipart field "${sourceKey}" must contain Blob/File, ReactNativeFile or ImagePickerAsset values for "${targetField}".`
335
336
  );
336
337
  }
337
338
  }
338
339
  return;
339
340
  }
340
341
  throw new Error(
341
- `Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, Blob[]/ReactNativeFile[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
342
+ `Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, ImagePickerAsset, Blob[]/ReactNativeFile[]/ImagePickerAsset[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
342
343
  );
343
344
  }
344
345
  function splitMultipartBody(body, fields) {
@@ -367,6 +368,7 @@ function splitMultipartBody(body, fields) {
367
368
  return { regularBody, multipartFiles };
368
369
  }
369
370
  var isReactNativeFile = (v) => v && typeof v === "object" && typeof v.uri === "string" && typeof v.name === "string" && typeof v.type === "string";
371
+ 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");
370
372
  var isFile = (v) => typeof File !== "undefined" && v instanceof File;
371
373
  var isBlob = (v) => typeof Blob !== "undefined" && v instanceof Blob;
372
374
  function toFormData(body, bodyFiles = []) {
@@ -378,6 +380,14 @@ function toFormData(body, bodyFiles = []) {
378
380
  fd.append(fieldName, value);
379
381
  return;
380
382
  }
383
+ if (isImagePickerAsset(value)) {
384
+ fd.append(fieldName, {
385
+ uri: value.uri,
386
+ name: value.fileName ?? "upload",
387
+ type: value.mimeType ?? "application/octet-stream"
388
+ });
389
+ return;
390
+ }
381
391
  if (isFile(value)) {
382
392
  fd.append(fieldName, value, value.name);
383
393
  return;