/** * Files: files in spaces (buckets), at `/v1/files` (`/storage/v1` in the old vocabulary). * * Who may read or write a file is row-level security on the project's files table, exactly as * for a table, so the same signed-in session that reads rows reads files. A public space's * files are also served without a key, at the URL `publicLink` builds. */ import { type Transport, type Vocabulary } from './http.js'; export declare class StorageError extends Error { readonly status: number; constructor(message: string, status: number); } export type StorageResult = { data: T; error: null; } | { data: null; error: StorageError; }; export interface Space { id: string; name: string; owner: string; public: boolean; file_size_limit: number | null; allowed_mime_types: string[] | null; created_at: string; updated_at: string; } /** @deprecated Since 0.4.0: `Space`. */ export type Bucket = Space; export interface FileObject { name: string; id: string | null; bucket_id?: string; owner?: string; updated_at: string | null; created_at: string | null; last_accessed_at: string | null; metadata: Record | null; } /** Image transformation, applied on the way out. */ export interface Transform { width?: number; height?: number; resize?: 'cover' | 'contain' | 'fill'; quality?: number; format?: 'origin'; } export type Body = Blob | ArrayBuffer | ArrayBufferView | ReadableStream | string | FormData; export interface UploadOptions { /** Seconds a CDN or browser may cache it. Default 3600. */ cacheControl?: string; contentType?: string; /** Replace an object already at that path instead of refusing. */ upsert?: boolean; metadata?: Record; } export interface SpaceOptions { public?: boolean; fileSizeLimit?: number | string | null; allowedMimeTypes?: string[] | null; } export declare class StorageClient { /** @internal */ readonly url: string; private readonly transport; private readonly vocabulary; constructor( /** @internal */ url: string, transport: Transport, vocabulary?: Vocabulary); /** @deprecated Since 0.4.0: use `space()`, the same function. Removed in 0.5.0. */ from: StorageClient['space']; /** @deprecated Since 0.4.0: use `listSpaces()`, the same function. Removed in 0.5.0. */ listBuckets: StorageClient['listSpaces']; /** @deprecated Since 0.4.0: use `getSpace()`, the same function. Removed in 0.5.0. */ getBucket: StorageClient['getSpace']; /** @deprecated Since 0.4.0: use `createSpace()`, the same function. Removed in 0.5.0. */ createBucket: StorageClient['createSpace']; /** @deprecated Since 0.4.0: use `updateSpace()`, the same function. Removed in 0.5.0. */ updateBucket: StorageClient['updateSpace']; /** @deprecated Since 0.4.0: use `emptySpace()`, the same function. Removed in 0.5.0. */ emptyBucket: StorageClient['emptySpace']; /** @deprecated Since 0.4.0: use `deleteSpace()`, the same function. Removed in 0.5.0. */ deleteBucket: StorageClient['deleteSpace']; private spaceUrl; /** The files of one space. */ space(space: string): SpaceClient; listSpaces(): Promise>; getSpace(id: string): Promise>; createSpace(id: string, options?: SpaceOptions): Promise>; updateSpace(id: string, options: SpaceOptions): Promise>; /** Removes every file in it. The space stays. */ emptySpace(id: string): Promise>; /** A space must be empty to be deleted. */ deleteSpace(id: string): Promise>; } /** The files of one space: what `files.space(name)` returns. */ export declare class SpaceClient { private readonly url; private readonly bucket; private readonly transport; private readonly vocabulary; constructor(url: string, bucket: string, transport: Transport, vocabulary?: Vocabulary); /** @deprecated Since 0.4.0: use `put()`, the same function. Removed in 0.5.0. */ upload: SpaceClient['put']; /** @deprecated Since 0.4.0: use `get()`, the same function. Removed in 0.5.0. */ download: SpaceClient['get']; /** @deprecated Since 0.4.0: use `signedLink()`, the same function. Removed in 0.5.0. */ createSignedUrl: SpaceClient['signedLink']; /** @deprecated Since 0.4.0: use `publicLink()`, the same function. Removed in 0.5.0. */ getPublicUrl: SpaceClient['publicLink']; private at; private objectPath; private write; /** Puts a file at `path`. Refuses if something is already there, unless `upsert`. */ put(path: string, body: Body, options?: UploadOptions): Promise>; /** Replaces the file at `path`. */ update(path: string, body: Body, options?: UploadOptions): Promise>; /** The file at `path`, transformed on the way out when `transform` says so. */ get(path: string, options?: { transform?: Transform; }): Promise>; /** An object's size, type and metadata. */ info(path: string): Promise>>; exists(path: string): Promise>; /** The files directly under `prefix`; folders appear as entries with a null `id`. */ list(prefix?: string, options?: { limit?: number; offset?: number; sortBy?: { column: string; order: 'asc' | 'desc'; }; search?: string; }): Promise>; remove(paths: string[]): Promise>; move(from: string, to: string, options?: { destinationBucket?: string; }): Promise>; copy(from: string, to: string, options?: { destinationBucket?: string; }): Promise>; /** * A URL anyone holding it can read for `expiresIn` seconds. `download` makes the browser * save it (under that name when a string) instead of showing it. */ signedLink(path: string, expiresIn: number, options?: { download?: string | boolean; transform?: Transform; }): Promise>; createSignedUrls(paths: string[], expiresIn: number, options?: { download?: string | boolean; }): Promise>; /** A URL a browser can upload to without a session, for two hours. Pair with `uploadToSignedUrl`. */ createSignedUploadUrl(path: string, options?: { upsert?: boolean; }): Promise>; uploadToSignedUrl(path: string, token: string, body: Body, options?: UploadOptions): Promise>; /** The URL of a file in a PUBLIC space. Builds a string; checks nothing. */ publicLink(path: string, options?: { download?: string | boolean; transform?: Transform; }): { data: { publicUrl: string; }; }; private absolute; } /** @deprecated Since 0.4.0: `SpaceClient`, the same class. */ export declare const BucketClient: typeof SpaceClient; /** @deprecated Since 0.4.0: `SpaceClient`. */ export type BucketClient = SpaceClient;