UNPKG

@api-buddy/types

Version:

Shared types for API Buddy

362 lines 11.7 kB
import type { BaseAdapter } from "./base.js"; import { AdapterType } from "./types.js"; import { z } from 'zod'; /** * Represents a file-like object that can be uploaded to storage */ export type FileLike = File | Blob | ArrayBuffer | Uint8Array | string; /** * Schema for validating file metadata */ export declare const fileMetadataSchema: z.ZodObject<{ /** Name of the file */ name: z.ZodString; /** Size of the file in bytes */ size: z.ZodNumber; /** MIME type of the file */ type: z.ZodString; /** Last modified timestamp */ lastModified: z.ZodOptional<z.ZodNumber>; /** Custom metadata key-value pairs */ customMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; }, "strict", z.ZodTypeAny, { type: string; name: string; size: number; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }, { type: string; name: string; size: number; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }>; /** * Represents metadata for a stored file */ export interface FileMetadata extends z.infer<typeof fileMetadataSchema> { } /** * Represents a file in storage with its metadata */ export interface StoredFile extends FileMetadata { /** Full path to the file in storage */ path: string; /** Public URL to access the file */ url: string; /** When the file was created */ createdAt: Date; /** When the file was last updated */ updatedAt: Date; } /** * Schema for validating stored file objects */ export declare const storedFileSchema: z.ZodObject<{ /** Name of the file */ name: z.ZodString; /** Size of the file in bytes */ size: z.ZodNumber; /** MIME type of the file */ type: z.ZodString; /** Last modified timestamp */ lastModified: z.ZodOptional<z.ZodNumber>; /** Custom metadata key-value pairs */ customMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; } & { path: z.ZodString; url: z.ZodString; createdAt: z.ZodDate; updatedAt: z.ZodDate; }, "strict", z.ZodTypeAny, { path: string; type: string; name: string; size: number; url: string; createdAt: Date; updatedAt: Date; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }, { path: string; type: string; name: string; size: number; url: string; createdAt: Date; updatedAt: Date; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }>; /** * Options for file uploads */ export interface UploadOptions { /** Whether to make the file publicly accessible */ public?: boolean; /** Custom metadata to store with the file */ metadata?: Omit<FileMetadata, 'name' | 'size' | 'type'>; /** Content type override */ contentType?: string; /** Cache control header value */ cacheControl?: string; /** Content encoding */ contentEncoding?: string; /** Content disposition header value */ contentDisposition?: string; } /** * Schema for validating upload options */ export declare const uploadOptionsSchema: z.ZodObject<{ public: z.ZodDefault<z.ZodBoolean>; metadata: z.ZodOptional<z.ZodObject<Omit<{ /** Name of the file */ name: z.ZodString; /** Size of the file in bytes */ size: z.ZodNumber; /** MIME type of the file */ type: z.ZodString; /** Last modified timestamp */ lastModified: z.ZodOptional<z.ZodNumber>; /** Custom metadata key-value pairs */ customMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; }, "type" | "name" | "size">, "strict", z.ZodTypeAny, { lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }, { lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }>>; contentType: z.ZodOptional<z.ZodString>; cacheControl: z.ZodOptional<z.ZodString>; contentEncoding: z.ZodOptional<z.ZodString>; contentDisposition: z.ZodOptional<z.ZodString>; }, "strict", z.ZodTypeAny, { public: boolean; metadata?: { lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; } | undefined; contentType?: string | undefined; cacheControl?: string | undefined; contentEncoding?: string | undefined; contentDisposition?: string | undefined; }, { public?: boolean | undefined; metadata?: { lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; } | undefined; contentType?: string | undefined; cacheControl?: string | undefined; contentEncoding?: string | undefined; contentDisposition?: string | undefined; }>; /** * Options for file downloads */ export interface DownloadOptions { /** Whether to get a temporary download URL */ temporary?: boolean; /** Expiration time in seconds for temporary URLs */ expiresIn?: number; /** Response content type override */ responseContentType?: string; /** Response content disposition */ responseContentDisposition?: string; } /** * Schema for validating download options */ export declare const downloadOptionsSchema: z.ZodObject<{ temporary: z.ZodDefault<z.ZodBoolean>; expiresIn: z.ZodOptional<z.ZodNumber>; responseContentType: z.ZodOptional<z.ZodString>; responseContentDisposition: z.ZodOptional<z.ZodString>; }, "strict", z.ZodTypeAny, { temporary: boolean; expiresIn?: number | undefined; responseContentType?: string | undefined; responseContentDisposition?: string | undefined; }, { temporary?: boolean | undefined; expiresIn?: number | undefined; responseContentType?: string | undefined; responseContentDisposition?: string | undefined; }>; /** * Options for listing files */ export interface ListOptions { /** Maximum number of results to return */ maxResults?: number; /** Pagination token */ pageToken?: string; /** Whether to include file metadata in results */ includeMetadata?: boolean; } /** * Schema for validating list options */ export declare const listOptionsSchema: z.ZodObject<{ maxResults: z.ZodOptional<z.ZodNumber>; pageToken: z.ZodOptional<z.ZodString>; includeMetadata: z.ZodDefault<z.ZodBoolean>; }, "strict", z.ZodTypeAny, { includeMetadata: boolean; maxResults?: number | undefined; pageToken?: string | undefined; }, { maxResults?: number | undefined; pageToken?: string | undefined; includeMetadata?: boolean | undefined; }>; /** * Result of a list operation */ export interface ListResult { /** Array of file paths or objects */ items: (string | StoredFile)[]; /** Pagination token for the next page */ nextPageToken?: string; /** Whether there are more results */ hasMore: boolean; } /** * Schema for validating list results */ export declare const listResultSchema: z.ZodObject<{ items: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{ /** Name of the file */ name: z.ZodString; /** Size of the file in bytes */ size: z.ZodNumber; /** MIME type of the file */ type: z.ZodString; /** Last modified timestamp */ lastModified: z.ZodOptional<z.ZodNumber>; /** Custom metadata key-value pairs */ customMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; } & { path: z.ZodString; url: z.ZodString; createdAt: z.ZodDate; updatedAt: z.ZodDate; }, "strict", z.ZodTypeAny, { path: string; type: string; name: string; size: number; url: string; createdAt: Date; updatedAt: Date; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }, { path: string; type: string; name: string; size: number; url: string; createdAt: Date; updatedAt: Date; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; }>]>, "many">; nextPageToken: z.ZodOptional<z.ZodString>; hasMore: z.ZodBoolean; }, "strict", z.ZodTypeAny, { items: (string | { path: string; type: string; name: string; size: number; url: string; createdAt: Date; updatedAt: Date; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; })[]; hasMore: boolean; nextPageToken?: string | undefined; }, { items: (string | { path: string; type: string; name: string; size: number; url: string; createdAt: Date; updatedAt: Date; lastModified?: number | undefined; customMetadata?: Record<string, string> | undefined; })[]; hasMore: boolean; nextPageToken?: string | undefined; }>; /** * Interface for storage adapters * @template TConfig - Type of the configuration object */ export interface StorageAdapter<TConfig = unknown> extends BaseAdapter<TConfig> { readonly type: AdapterType.STORAGE; /** * Uploads a file to storage * @param file - The file to upload * @param path - The destination path in storage * @param options - Upload options * @returns A promise that resolves to the public URL of the uploaded file * @throws {StorageError} If the upload fails */ upload(file: FileLike, path: string, options?: UploadOptions): Promise<string>; /** * Downloads a file from storage * @param path - The path to the file in storage * @param options - Download options * @returns A promise that resolves to the file data as a Blob * @throws {StorageError} If the download fails */ download(path: string, options?: DownloadOptions): Promise<Blob>; /** * Gets a download URL for a file * @param path - The path to the file in storage * @param options - Download options * @returns A promise that resolves to a download URL * @throws {StorageError} If the operation fails */ getDownloadUrl(path: string, options?: Omit<DownloadOptions, 'temporary'>): Promise<string>; /** * Deletes a file from storage * @param path - The path to the file in storage * @returns A promise that resolves when the operation completes * @throws {StorageError} If the deletion fails */ delete(path: string): Promise<void>; /** * Lists files in a storage path * @param path - The directory path to list * @param options - List options * @returns A promise that resolves to a list of file paths or objects * @throws {StorageError} If the operation fails */ list(path: string, options?: ListOptions): Promise<ListResult>; /** * Gets metadata for a file * @param path - The path to the file in storage * @returns A promise that resolves to the file metadata * @throws {StorageError} If the operation fails */ getMetadata(path: string): Promise<StoredFile>; /** * Updates file metadata * @param path - The path to the file in storage * @param metadata - The metadata to update * @returns A promise that resolves to the updated file metadata * @throws {StorageError} If the operation fails */ updateMetadata(path: string, metadata: Partial<FileMetadata>): Promise<StoredFile>; } //# sourceMappingURL=storage.d.ts.map