import { StorageRepository } from "./StorageRepository.js"; /** * R2-compatible bucket interface (Cloudflare Workers binding). */ export interface R2Bucket { put(key: string, value: string | ArrayBuffer | ReadableStream): Promise; get(key: string): Promise; delete(key: string): Promise; list(options?: { prefix?: string; }): Promise; } /** * Represents an object retrieved from R2. */ export interface R2ObjectBody { body: ReadableStream; text(): Promise; arrayBuffer(): Promise; } /** * Represents the result of listing objects in an R2 bucket. */ export interface R2Objects { objects: { key: string; }[]; } /** * R2Repository: A StorageRepository implementation for Cloudflare R2. */ export declare class R2Repository implements StorageRepository { private bucket; private prefix?; constructor(bucket: R2Bucket, prefix?: string | undefined); /** * Adds a namespace prefix to keys (if specified). */ private buildKey; /** * Lists file paths in the R2 bucket under a given prefix. * * Supports wildcard patterns by trimming after `*`. * * @param prefix - Path prefix or glob (e.g. "content/*.md"). * @returns Sorted list of matching object keys. */ listFiles(prefix: string): Promise; /** * Reads the content of a file from R2. * * @param path - Key within the bucket. * @returns File content as string; empty string if not found. */ readFile(path: string): Promise; /** * Opens a file as a ReadableStream from Cloudflare R2. * * @param path - Key within the bucket. * @returns ReadableStream of the file contents. * @throws Error if the object does not exist. */ openFileStream(path: string): Promise; /** * Writes data to the R2 bucket. * * @param path - Key to write. * @param data - Content to write. */ writeFile(path: string, data: string): Promise; /** * Checks if the specified file exists in the R2 bucket. * * @param path - Key to check. * @returns `true` if it exists, `false` otherwise. */ exists(path: string): Promise; /** * Deletes the specified file from the R2 bucket. * * @param path - Key to delete. */ removeFile(path: string): Promise; /** * Deletes the specified file from the R2 bucket. * * @param path - Key to delete. */ removeDir(path: string): Promise; }