@supabase-cache-helpers/storage-core
Version:
A collection of cache utilities for working with the Supabase Storage API. It is not meant to be used standalone.
65 lines (55 loc) • 2.9 kB
text/typescript
import * as _supabase_storage_js from '@supabase/storage-js';
import { FileObject, TransformOptions, FileOptions } from '@supabase/storage-js';
import StorageFileApi from '@supabase/storage-js/dist/module/packages/StorageFileApi';
type DecodedStorageKey = {
bucketId: string;
path: string;
};
type StoragePrivacy = 'public' | 'private';
declare const fetchDirectory: (fileApi: StorageFileApi, path: string) => Promise<FileObject[]>;
type URLFetcher = (fileApi: StorageFileApi, path: string) => Promise<string | undefined>;
type URLFetcherConfig = {
expiresIn?: number;
ensureExistence?: boolean;
download?: string | boolean | undefined;
transform?: TransformOptions | undefined;
};
declare const createUrlFetcher: (mode: StoragePrivacy, config?: URLFetcherConfig) => URLFetcher;
type DirectoryURLsFetcher = (fileApi: StorageFileApi, path: string) => Promise<(FileObject & {
url: string;
})[]>;
declare const createDirectoryUrlsFetcher: (mode: StoragePrivacy, config?: Pick<URLFetcherConfig, "expiresIn">) => DirectoryURLsFetcher;
type Cache<KeyType> = {
/**
* The keys currently present in the cache
*/
cacheKeys: KeyType[];
/**
* Decode a key. Should return null if not a Storage key.
*/
decode: (k: KeyType) => DecodedStorageKey | null;
/**
* The mutation function from the cache library
*/
mutate: (key: KeyType) => Promise<void>;
};
declare const mutatePaths: <KeyType>(bucketId: string, paths: string[], { cacheKeys, decode, mutate }: Cache<KeyType>) => Promise<void>;
declare const createRemoveDirectoryFetcher: (fileApi: StorageFileApi) => (path: string) => Promise<_supabase_storage_js.FileObject[]>;
declare const createRemoveFilesFetcher: (fileApi: StorageFileApi) => (paths: string[]) => Promise<_supabase_storage_js.FileObject[]>;
type BuildFileNameFn = ({ path, fileName, }: {
path?: string;
fileName: string;
}) => string;
type UploadFetcherConfig = Partial<Pick<FileOptions, 'cacheControl' | 'upsert'>> & {
buildFileName?: BuildFileNameFn;
};
type UploadFileResponse = Awaited<ReturnType<StorageFileApi['upload']>>;
type UploadFileInput = {
data: Parameters<StorageFileApi['upload']>[1];
type?: string;
name: string;
metadata?: NonNullable<Parameters<StorageFileApi['upload']>[2]>['metadata'];
};
type FileInput = File | UploadFileInput;
declare const createUploadFetcher: (fileApi: StorageFileApi, config?: UploadFetcherConfig) => (files: FileList | FileInput[], path?: string) => Promise<UploadFileResponse[]>;
export { type BuildFileNameFn, type Cache, type DecodedStorageKey, type FileInput, type StoragePrivacy, type URLFetcherConfig, type UploadFetcherConfig, type UploadFileInput, type UploadFileResponse, createDirectoryUrlsFetcher, createRemoveDirectoryFetcher, createRemoveFilesFetcher, createUploadFetcher, createUrlFetcher, fetchDirectory, mutatePaths };