diff --git a/.changeset/chilly-tigers-grin.md b/.changeset/chilly-tigers-grin.md new file mode 100644 index 00000000..e68360ec --- /dev/null +++ b/.changeset/chilly-tigers-grin.md @@ -0,0 +1,8 @@ +--- +"@supabase-cache-helpers/postgrest-react-query": patch +"@supabase-cache-helpers/storage-react-query": patch +"@supabase-cache-helpers/postgrest-swr": patch +"@supabase-cache-helpers/storage-swr": patch +--- + +fix: type configuration parameter and add tests for fallbackData diff --git a/packages/storage-react-query/src/query/use-directory-urls.ts b/packages/storage-react-query/src/query/use-directory-urls.ts index c84794e8..721bfd5b 100644 --- a/packages/storage-react-query/src/query/use-directory-urls.ts +++ b/packages/storage-react-query/src/query/use-directory-urls.ts @@ -9,7 +9,6 @@ import { UseQueryResult as UseReactQueryResult, UseQueryOptions as UseReactQueryOptions, } from '@tanstack/react-query'; -import { useCallback } from 'react'; import { encode, StorageFileApi } from '../lib'; @@ -39,14 +38,14 @@ function useDirectoryFileUrls( (FileObject & { url: string })[] | undefined, StorageError > { - const fetcher = useCallback(createDirectoryUrlsFetcher(mode, config), [ - mode, - config, - ]); return useReactQuery< (FileObject & { url: string })[] | undefined, StorageError - >(encode([fileApi, path]), () => fetcher(fileApi, path), config); + >( + encode([fileApi, path]), + () => createDirectoryUrlsFetcher(mode, config)(fileApi, path), + config + ); } export { useDirectoryFileUrls }; diff --git a/packages/storage-react-query/src/query/use-directory.ts b/packages/storage-react-query/src/query/use-directory.ts index d1214582..d82fc995 100644 --- a/packages/storage-react-query/src/query/use-directory.ts +++ b/packages/storage-react-query/src/query/use-directory.ts @@ -5,7 +5,6 @@ import { UseQueryResult as UseReactQueryResult, UseQueryOptions as UseReactQueryOptions, } from '@tanstack/react-query'; -import { useCallback } from 'react'; import { StorageFileApi, encode } from '../lib'; @@ -25,11 +24,11 @@ function useDirectory( 'queryKey' | 'queryFn' > ): UseReactQueryResult { - const fetcher = useCallback( + return useReactQuery( + encode([fileApi, path]), () => fetchDirectory(fileApi, path), - [fileApi, path] + config ); - return useReactQuery(encode([fileApi, path]), fetcher, config); } export { useDirectory }; diff --git a/packages/storage-react-query/src/query/use-file-url.ts b/packages/storage-react-query/src/query/use-file-url.ts index d47e24ab..c21bc8b6 100644 --- a/packages/storage-react-query/src/query/use-file-url.ts +++ b/packages/storage-react-query/src/query/use-file-url.ts @@ -9,7 +9,6 @@ import { UseQueryResult as UseReactQueryResult, UseQueryOptions as UseReactQueryOptions, } from '@tanstack/react-query'; -import { useCallback } from 'react'; import { StorageFileApi, encode } from '../lib'; @@ -32,15 +31,9 @@ function useFileUrl( > & URLFetcherConfig ): UseReactQueryResult { - const fetcher = useCallback(createUrlFetcher(mode, config), [ - config, - mode, - fileApi, - path, - ]); return useReactQuery( encode([fileApi, path]), - () => fetcher(fileApi, path), + () => createUrlFetcher(mode, config)(fileApi, path), config ); } diff --git a/packages/storage-swr/src/query/use-directory-urls.ts b/packages/storage-swr/src/query/use-directory-urls.ts index 1aa9abe7..a7cb84ba 100644 --- a/packages/storage-swr/src/query/use-directory-urls.ts +++ b/packages/storage-swr/src/query/use-directory-urls.ts @@ -4,7 +4,6 @@ import { URLFetcherConfig, } from '@supabase-cache-helpers/storage-core'; import { FileObject, StorageError } from '@supabase/storage-js'; -import { useCallback } from 'react'; import useSWR, { SWRConfiguration, SWRResponse } from 'swr'; import { StorageKeyInput, middleware, StorageFileApi } from '../lib'; @@ -23,16 +22,16 @@ function useDirectoryFileUrls( fileApi: StorageFileApi, path: string | null, mode: StoragePrivacy, - config?: SWRConfiguration & Pick + config?: SWRConfiguration< + (FileObject & { url: string })[] | undefined, + StorageError + > & + Pick ): SWRResponse<(FileObject & { url: string })[] | undefined, StorageError> { - const fetcher = useCallback( - ([fileApi, path]: StorageKeyInput) => - createDirectoryUrlsFetcher(mode, config)(fileApi, path), - [mode, config] - ); return useSWR<(FileObject & { url: string })[] | undefined, StorageError>( path ? [fileApi, path] : null, - fetcher, + ([fileApi, path]: StorageKeyInput) => + createDirectoryUrlsFetcher(mode, config)(fileApi, path), { ...config, use: [...(config?.use ?? []), middleware], diff --git a/packages/storage-swr/src/query/use-directory.ts b/packages/storage-swr/src/query/use-directory.ts index 6806b034..aa062eee 100644 --- a/packages/storage-swr/src/query/use-directory.ts +++ b/packages/storage-swr/src/query/use-directory.ts @@ -1,6 +1,5 @@ import { fetchDirectory } from '@supabase-cache-helpers/storage-core'; import { FileObject, StorageError } from '@supabase/storage-js'; -import { useCallback } from 'react'; import useSWR, { SWRConfiguration, SWRResponse } from 'swr'; import { middleware, StorageKeyInput, StorageFileApi } from '../lib'; @@ -16,15 +15,11 @@ import { middleware, StorageKeyInput, StorageFileApi } from '../lib'; function useDirectory( fileApi: StorageFileApi, path: string | null, - config?: SWRConfiguration + config?: SWRConfiguration ): SWRResponse { - const fetcher = useCallback( - ([fileApi, path]: StorageKeyInput) => fetchDirectory(fileApi, path), - [] - ); return useSWR( path ? [fileApi, path] : null, - fetcher, + ([fileApi, path]: StorageKeyInput) => fetchDirectory(fileApi, path), { ...config, use: [...(config?.use ?? []), middleware], diff --git a/packages/storage-swr/src/query/use-file-url.ts b/packages/storage-swr/src/query/use-file-url.ts index b36b9909..2a716f31 100644 --- a/packages/storage-swr/src/query/use-file-url.ts +++ b/packages/storage-swr/src/query/use-file-url.ts @@ -4,7 +4,6 @@ import { URLFetcherConfig, } from '@supabase-cache-helpers/storage-core'; import { StorageError } from '@supabase/storage-js'; -import { useCallback } from 'react'; import useSWR, { SWRConfiguration, SWRResponse } from 'swr'; import { StorageKeyInput, middleware, StorageFileApi } from '../lib'; @@ -22,17 +21,17 @@ function useFileUrl( fileApi: StorageFileApi, path: string | null, mode: StoragePrivacy, - config?: SWRConfiguration & URLFetcherConfig + config?: SWRConfiguration & URLFetcherConfig ): SWRResponse { - const fetcher = useCallback( + return useSWR( + path ? [fileApi, path] : null, ([fileApi, path]: StorageKeyInput) => createUrlFetcher(mode, config)(fileApi, path), - [config, mode] + { + ...config, + use: [...(config?.use ?? []), middleware], + } ); - return useSWR(path ? [fileApi, path] : null, fetcher, { - ...config, - use: [...(config?.use ?? []), middleware], - }); } export { useFileUrl };