import { Scope } from '@aws-blocks/core'; import type { ScopeParent } from '@aws-blocks/core'; import type { FileBucketOptions, PutOptions, PutUrlOptions, ScanOptions, FileContent, FileInfo, ExternalBucketRef, ExternalKmsKeyRef, FileDownloadClient, FileUploadClient, FileVersionInfo, GetOptionsFor, DeleteOptionsFor, GetUrlOptionsFor } from './types.js'; export type { FileBucketOptions, PutOptions, GetUrlOptions, PutUrlOptions, ScanOptions, FileContent, FileInfo, CorsRule, LifecycleRule, ExternalBucketRef, ExternalKmsKeyRef, ObjectLockOptions, FileDownloadClient, FileUploadClient, FileVersionInfo, FileDownloadDescriptor, FileUploadDescriptor, VersionedGetOptions, VersionedDeleteOptions, VersionedGetUrlOptions, GetOptionsFor, DeleteOptionsFor, GetUrlOptionsFor, } from './types.js'; import type { ChildLogger } from '@aws-blocks/bb-logger'; export { FileBucketErrors } from './errors.js'; /** * File storage backed by Amazon S3. * * **When to use:** You need to store, retrieve, or serve binary files — * user uploads, generated reports, images, videos, or static assets. * * **When NOT to use:** If you need structured key-value data with conditional * writes, use `KVStore`. If you need queryable records with indexes, use * `DistributedTable`. * * **Best practices:** * - Use path prefixes to organize files (e.g., `uploads/{userId}/`, `reports/`) * - Set `contentType` on `put()` to ensure correct MIME handling on download * - Use presigned URLs (`getUrl` / `putUrl`) for direct browser upload/download * - Use `getFileHandle` / `createUploadHandle` for ergonomic browser file transfers * - Prefer `scan({ prefix })` over unscoped `scan()` to limit enumeration cost * * **Scaling:** S3 scales automatically. No provisioned throughput. Costs are * per-request plus storage. Individual objects up to 5 TB. For objects larger * than ~100 MB, consider multipart upload. */ export declare class FileBucket extends Scope { private dataDir; private versioned; /** Mirrors the AWS runtime: presigned uploads are rejected on an `objectLock` bucket. */ private readonly objectLocked; /** @internal Logger for internal operations. Defaults to error-level when not provided. */ protected log: ChildLogger; constructor(scope: ScopeParent, id: string, options?: O); /** * Upload a file. * * Overwrites any existing file at the given path. * * @param path - The object key (e.g., `uploads/photo.jpg`). * @param body - The file content. * @param options - Optional metadata and content settings. * * @example * ```typescript * await bucket.put('reports/q1.pdf', pdfBuffer, { * contentType: 'application/pdf', * }); * ``` */ put(path: string, body: Buffer | string, options?: PutOptions): Promise; /** * Download a file. * * @param path - The object key. * @param options - Optional. On versioned buckets, pass `{ versionId }` to retrieve a specific version. * @returns The file content and metadata, or null if the file does not exist. * * @example * ```typescript * const file = await bucket.get('reports/q1.pdf'); * if (file) { * console.log(file.contentType); // 'application/pdf' * } * ``` */ get(path: string, options?: GetOptionsFor): Promise; /** * Delete a file. * * On non-versioned buckets, permanently removes the file. * On versioned buckets without `versionId`, places a delete marker (file appears deleted * but previous versions are preserved). With `versionId`, permanently removes that version. * * No-op if the file does not exist (matches S3 behavior). * * @param path - The object key. * @param options - Optional. On versioned buckets, pass `{ versionId }` to permanently delete a specific version. * * @example * ```typescript * await bucket.delete('uploads/old-photo.jpg'); * ``` */ delete(path: string, options?: DeleteOptionsFor): Promise; /** * Delete multiple files in a single operation. * * Uses S3 DeleteObjects for efficient bulk deletion (up to 1,000 keys * per request). Chunking is handled internally. * * @param paths - The object keys to delete. * * @example * ```typescript * await bucket.deleteBatch(['tmp/a.txt', 'tmp/b.txt', 'tmp/c.txt']); * ``` */ deleteBatch(paths: string[]): Promise; /** * Generate a presigned URL for downloading a file. * * @param path - The object key. * @param options - URL generation options. * @returns A presigned URL string. * * @example * ```typescript * const url = await bucket.getUrl('reports/q1.pdf', { expiresIn: 3600 }); * ``` */ getUrl(path: string, options?: GetUrlOptionsFor): Promise; /** * Generate a presigned URL for uploading a file. * * @param path - The object key. * @param options - URL generation options. * @returns A presigned URL string. * * @example * ```typescript * const url = await bucket.putUrl('uploads/photo.jpg', { * expiresIn: 600, * contentType: 'image/jpeg', * }); * ``` */ putUrl(path: string, options?: PutUrlOptions): Promise; /** * Get a file handle for browser-side download. * * Returns a Transferable descriptor that the client middleware hydrates * into an object with `.download()` and `.getUrl()` methods. Use this * instead of `getUrl()` when you want the client to download files * without manually managing presigned URLs. * * @param path - The object key. * @param options - URL generation options. * @returns A Transferable file download handle. * * @example * ```typescript * // Backend * async getReport(name: string) { * return bucket.getFileHandle('reports/' + name); * } * * // Frontend * const file = await api.getReport('q1.pdf'); * const blob = await file.download(); * ``` */ getFileHandle(path: string, options?: GetUrlOptionsFor): Promise; /** * Create an upload handle for browser-side file upload. * * Returns a Transferable descriptor that the client middleware hydrates * into an object with `.upload(body)` and `.getUrl()` methods. Use this * instead of `putUrl()` when you want the client to upload files * without manually managing presigned URLs. * * @param path - The object key. * @param options - URL generation options. * @returns A Transferable file upload handle. * * @example * ```typescript * // Backend * async getUploadSlot(name: string) { * return bucket.createUploadHandle('uploads/' + name, { * contentType: 'image/jpeg', * }); * } * * // Frontend * const slot = await api.getUploadSlot('photo.jpg'); * await slot.upload(fileBlob); * ``` */ createUploadHandle(path: string, options?: PutUrlOptions): Promise; /** * List files in the bucket. * * Returns an `AsyncIterable` that paginates internally. Use `prefix` * to scope the listing. Without a prefix, enumerates all files — * this is expensive on large buckets. * * @param options - Listing options. * @returns An async iterable of file info objects. * * @example * ```typescript * for await (const file of bucket.scan({ prefix: 'uploads/' })) { * console.log(file.path, file.size); * } * ``` */ scan(options?: ScanOptions): AsyncIterable; /** * List all versions of a file. Only available on versioned buckets. * * Returns versions newest-first. Includes the current version and all * previous versions. Does not include delete markers. * * @param path - The object key. * @returns An array of version metadata, newest first. * * @example * ```typescript * const versions = await bucket.listVersions('report.pdf'); * for (const v of versions) { * console.log(v.versionId, v.lastModified, v.isCurrent); * } * ``` */ listVersions(path: string): Promise; /** * Restore a previous version of a file, making it the current version. * * Creates a new version that is a copy of the specified old version. * On S3, this is implemented as a CopyObject from the old version to the same key. * * @param path - The object key. * @param versionId - The version to restore. * * @example * ```typescript * const versions = await bucket.listVersions('report.pdf'); * await bucket.restoreVersion('report.pdf', versions[1].versionId); * ``` */ restoreVersion(path: string, versionId: string): Promise; /** * Create a reference to an existing S3 bucket not managed by this scope. * * @param bucketName - The name of the existing S3 bucket. */ static fromExisting(bucketName: string): ExternalBucketRef; /** * Reference an existing customer-managed KMS key by ARN, to pass as the * `encryption` option. Encryption is applied at deploy time; the * mock ignores it. * * @param keyArn - The ARN of the existing KMS key. */ static fromKmsKey(keyArn: string): ExternalKmsKeyRef; private assertPresignedUploadSupported; private validateKey; private writeMeta; private readMeta; private readVersionMeta; private readMetaFile; private walkDir; private nextVersionId; } //# sourceMappingURL=index.mock.d.ts.map