From 66d817b2a6c94f93874eb5405b461f1107483867 Mon Sep 17 00:00:00 2001 From: Vedat Baday <54285744+badayvedat@users.noreply.github.com> Date: Fri, 16 Feb 2024 03:30:00 +0300 Subject: [PATCH] fix: nested blob upload (#48) * fix: nested blob upload * refactor: export to a utility function * chore: bump version to 0.8.3 --- libs/client/package.json | 2 +- libs/client/src/storage.ts | 4 ++++ libs/client/src/utils.ts | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/client/package.json b/libs/client/package.json index 5c323cf..8d1f95e 100644 --- a/libs/client/package.json +++ b/libs/client/package.json @@ -1,7 +1,7 @@ { "name": "@fal-ai/serverless-client", "description": "The fal serverless JS/TS client", - "version": "0.8.2", + "version": "0.8.3", "license": "MIT", "repository": { "type": "git", diff --git a/libs/client/src/storage.ts b/libs/client/src/storage.ts index 203bbbd..063a583 100644 --- a/libs/client/src/storage.ts +++ b/libs/client/src/storage.ts @@ -1,5 +1,6 @@ import { getConfig, getRestApiUrl } from './config'; import { dispatchRequest } from './request'; +import { isPlainObject } from './utils'; /** * File support for the client. This interface establishes the contract for @@ -117,6 +118,9 @@ export const storageImpl: StorageSupport = { const url = await storageImpl.upload(blob as Blob); return [key, url]; } + if (isPlainObject(value)) { + return [key, await storageImpl.transformInput(value)]; + } return [key, value] as KeyValuePair; }); const results = await Promise.all(promises); diff --git a/libs/client/src/utils.ts b/libs/client/src/utils.ts index e3634bc..750a584 100644 --- a/libs/client/src/utils.ts +++ b/libs/client/src/utils.ts @@ -82,3 +82,12 @@ export function isReact() { } return isRunningInReact; } + +/** + * Check if a value is a plain object. + * @param value - The value to check. + * @returns `true` if the value is a plain object, `false` otherwise. + */ +export function isPlainObject(value: any): boolean { + return !!value && Object.getPrototypeOf(value) === Object.prototype; +}