import { B as BaseStorage, O as OperationOptions, C as ConditionalSupport } from "./storage.d-Cnjmzau5.js"; import { Readable } from 'node:stream'; /** * Pause / resume / abort handle threaded into {@link Files.upload} via {@link UploadOptions.control}. * * `pause()` applies backpressure to the body stream; `resume()` releases it. This is effective for * streaming bodies feeding streaming adapters (S3, GCS, Azure, FTP/SFTP). Buffered adapters * (memory, disk) read the whole body in one shot and cannot be paused mid-transfer. * `abort()` cancels the operation through the merged {@link OperationOptions.signal}; the * adapter's upload session is kept, so the upload can still be resumed. * * On adapters with `capabilities.resumable`, an upload with a control is written in parts and * {@link UploadControl.toJSON} describes the adapter's upload session. Persist the token and pass * `UploadControl.from(token)` to `files.upload()` in another process to continue from the bytes * the adapter confirmed. That process needs the same backend and metadata store. * @example * ```ts * const control = new UploadControl(); * const promise = files.upload("big.bin", stream, { size, control }); * pauseButton.onclick = () => control.pause(); * resumeButton.onclick = () => control.resume(); * cancelButton.onclick = () => control.abort(); * await promise; * ``` */ declare class UploadControl { /** Caller-facing key being uploaded; populated once the upload starts. */ key?: string; /** Upload session of a resumable upload, from {@link UploadControl.from} or recorded when it starts. */ private session?; private readonly controller; private internalState; private loadedBytes; /** Chunks held by the gate while paused; released in order on `resume()`. */ private heldChunks; constructor(initial?: { key?: string; loaded?: number; }); /** * Rehydrate a control from a {@link UploadControl.toJSON} token (object or JSON string). The * returned control is `idle` with its `loaded` counter pre-seeded. Passed to `files.upload()`, * a token that carries an upload session (version 2) resumes that upload; a version 1 token * only restores the progress display. */ static from(token: UploadControlToken | string): UploadControl; /** Abort signal merged into the upload operation. */ get signal(): AbortSignal; get state(): UploadControlState; /** Bytes observed leaving the facade so far. */ get loaded(): number; pause(): void; resume(): void; abort(reason?: unknown): void; /** * Serializable resume token. Once a resumable upload has started it carries the upload session * and the bytes the adapter confirmed; `JSON.stringify(control)` produces the same object. */ toJSON(): UploadControlToken; /** @deprecated Use {@link UploadControl.toJSON}. */ serialize(): UploadControlToken; private releaseHeldChunks; } /** * Web-standard and Node-native body types accepted by {@link Files.upload}. */ type FileBody = ArrayBuffer | ArrayBufferView | Blob | Buffer | NodeJS.ReadableStream | ReadableStream | string; /** * Byte range for {@link Files.download}. Both bounds are 0-based and `end` is * **inclusive**, mirroring the HTTP `Range: bytes=start-end` header. Omit `end` * to read from `start` to EOF (e.g. resume an interrupted download). */ interface DownloadRange { end?: number; start: number; } /** * Realtime upload progress report. `total` is omitted for streaming bodies of * unknown length. The optional `key` is set on the bulk array form so a single * callback can drive a multi-row UI. */ interface UploadProgress { key?: string; loaded: number; total?: number; } type UploadProgressCallback = (event: UploadProgress) => void; /** Lifecycle state of an {@link UploadControl}. */ type UploadControlState = "aborted" | "completed" | "failed" | "idle" | "paused" | "uploading"; /** * Serializable snapshot of an {@link UploadControl}, returned by {@link UploadControl.toJSON} and * accepted by {@link UploadControl.from}. Persist it (a database row, a file, `localStorage`) and * pass `UploadControl.from(token)` as `control` to {@link Files.upload} in a later process to * continue the upload without re-sending the bytes already stored. * * Version 1 tokens (written before resumable uploads) only carry `key` and `loaded`; a control * rebuilt from one starts the upload over. */ interface UploadControlToken { /** Name of the adapter holding the upload session (e.g. `"s3"`); resuming on another adapter is rejected. */ adapter?: string; /** Content type recorded when the upload started. */ contentType?: string; /** Caller-facing key being uploaded. */ key?: string; /** Bytes the adapter confirmed stored (version 1: bytes observed leaving the facade). */ loaded: number; /** Custom metadata recorded when the upload started. */ metadata?: Record; /** Total size of the object in bytes. */ size?: number; /** * Id of the adapter's upload record. The provider session (S3 `UploadId` and parts, GCS * resumable-session URI, Azure staged blocks, the partial file on disk) is kept in the * adapter's metadata store under this id and reloaded from there on resume. */ uploadId?: string; version: 1 | 2; } /** * Multipart tuning for {@link Files.upload}. `true` enables multipart with * adapter defaults; an object lets the caller tune the per-part size and the * number of parts uploaded in parallel. */ interface MultipartOptions { /** In-flight parts. Adapter-defined default. */ concurrency?: number; /** Per-part size in bytes. Adapter-defined default. */ partSize?: number; } interface UploadOptions { /** * Pre-computed content integrity checksum for end-to-end verification. Adapters that verify * checksums on write (e.g. DiskStorage, TUS) reject the upload when the stored bytes don't * match. Pair with {@link UploadOptions.checksumAlgorithm} to select the digest; defaults to * the adapter's preferred algorithm when omitted. Ignored by adapters without checksum support. */ checksum?: string; /** * Digest algorithm for {@link UploadOptions.checksum} (e.g. `"sha256"`, `"md5"`, `"crc32c"`). * Adapter-dependent; ignored when no `checksum` is supplied. */ checksumAlgorithm?: string; contentType?: string; /** * Pause / resume / abort handle for this upload. Pausing applies backpressure to the body * stream (effective for streaming bodies and streaming adapters; buffered adapters consume the * whole body at once and cannot be paused mid-flight); aborting cancels the operation via the * merged {@link OperationOptions.signal}. See {@link UploadControl}. */ control?: UploadControl; /** * Replace-if-match: store the body only when the object currently under the key has this ETag. * Evaluated natively by the adapter at commit time; a mismatch (or a missing object) rejects with * `PRECONDITION_FAILED` (412) and leaves the stored object untouched. Requires * `capabilities.conditional.replace`, otherwise the call rejects with `METHOD_NOT_ALLOWED` before * any I/O. Cannot be combined with {@link UploadOptions.ifNoneMatch}. */ ifMatch?: string; /** * `"*"`: create-only. Store the body only when nothing exists under the key yet; otherwise reject * with `PRECONDITION_FAILED` (412). Requires `capabilities.conditional.create`. */ ifNoneMatch?: "*"; metadata?: Record; /** * Enable multipart/chunked upload for large bodies. `true` uses the * adapter's defaults; pass an object to tune. Adapters that don't have a * multipart primitive ignore this option. */ multipart?: MultipartOptions | boolean; /** * Realtime progress reporter. For buffered bodies a coarse start/done pair * is emitted. For streaming bodies each chunk is reported as it leaves the * facade. Adapters that report progress natively (`reportsUploadProgress`) * supersede this with byte-accurate events. A throwing callback can never * fail the upload — exceptions are swallowed. */ onProgress?: UploadProgressCallback; /** * Byte offset of the first byte of `body` within the object, when resuming with a `control` * rebuilt from a token ({@link UploadControl.from}). Defaults to `0`: `body` is the full source * and the bytes the adapter already stored are read and skipped. Pass the offset when `body` * only holds the remainder (e.g. a file stream opened at `token.loaded`); it must not lie past * the stored offset. */ resumeOffset?: number; /** * Explicit byte length. Required for {@link NodeJS.ReadableStream} and Web `ReadableStream` * inputs because their length is not derivable from the value itself; ignored otherwise. */ size?: number; storageClass?: string; } interface SignedReadUrlOptions { expiresIn?: number; responseContentDisposition?: string; responseContentType?: string; } interface SignedUploadUrlOptions { contentLength?: number; contentType?: string; expiresIn?: number; } interface SignedUploadOptions extends SignedUploadUrlOptions { /** * Largest accepted body in bytes. Setting `maxSize` or `minSize` makes {@link Files.signedUpload} * sign a `POST` policy whose `content-length-range` the provider enforces; adapters without * presigned POST support (`capabilities.signedUploadPost === false`) reject the call with * `METHOD_NOT_ALLOWED` instead of signing an unbounded URL. */ maxSize?: number; /** Smallest accepted body in bytes. See {@link SignedUploadOptions.maxSize}. */ minSize?: number; } /** * Upload contract returned by {@link Files.signedUpload}, discriminated on `method`. For `PUT`, send * the raw body to `url` with `headers`. For `POST`, send `multipart/form-data` to `url` with every * entry of `fields` first, then the file as the last field, named `file`. */ type SignedUpload = { fields: Record; method: "POST"; url: string; } | { headers: Record; method: "PUT"; url: string; }; /** Exact-read / conditional-delete predicate. */ interface IfMatchOptions { /** * Proceed only when the stored object's ETag equals this value; otherwise reject with * `PRECONDITION_FAILED` (412). Requires the matching `capabilities.conditional` flag * (`read` for `download`/`head`, `delete` for `delete`). */ ifMatch?: string; } interface HeadOptions extends IfMatchOptions, OperationOptions {} interface DeleteOptions extends IfMatchOptions, OperationOptions {} interface CopyOptions extends OperationOptions { /** Copy only when the destination currently has this ETag (replace-if-match). */ ifMatch?: string; /** `"*"`: copy only when the destination does not exist yet (create-only). */ ifNoneMatch?: "*"; /** * Copy only when the source still has this ETag. Any of the three predicates requires * `capabilities.conditional.copy`; the adapter evaluates them in the same native request. */ sourceIfMatch?: string; storageClass?: string; } /** How {@link Files.search} interprets a string pattern. */ type SearchMatch = "exact" | "glob" | "regex" | "substring"; interface SearchOptions extends OperationOptions { /** Match case-insensitively (any mode). Disables the automatic prefix filter of a glob. */ caseInsensitive?: boolean; /** Stop after this many matches; the walk stops fetching pages once it is reached. */ limit?: number; /** * How a string `pattern` is read. `glob` (default) anchors to the whole key, `*` stays within a * path segment, `**` spans segments, and dotfiles match; `regex` is a regular expression * (`RegExp` patterns always are); `substring` is "key contains"; `exact` is "key equals". * @default "glob" */ match?: SearchMatch; /** Per-page size requested from the adapter while walking (see {@link Files.listAll}). */ pageSize?: number; /** * Only walk keys under this prefix. A glob or exact pattern with a literal head is scoped to that * head automatically; pass `prefix` to bound `regex` / `substring` / case-insensitive searches. */ prefix?: string; } interface ListOptions { /** * Collapse keys that share a path segment into S3-style common prefixes ("directories"). * When set, {@link Files.list} returns a {@link ListDirectoryResult} (`{ files, prefixes }`) * instead of a flat array: keys with no further `delimiter` after the listing prefix come back * as `files`, and everything below a shared boundary is folded into a single `prefixes` entry. * Pass `"/"` for conventional folder semantics. */ delimiter?: string; limit?: number; prefix?: string; } /** * Directory-style listing returned by {@link Files.list} when a `delimiter` is supplied. */ interface ListDirectoryResult { /** Objects that live directly under the listing prefix (no further delimiter). */ files: FileObject[]; /** Common prefixes ("subdirectories") one delimiter level below the listing prefix. */ prefixes: string[]; } interface ListAllOptions { /** Per-page size requested from the adapter. */ limit?: number; prefix?: string; } /** * Capability snapshot for the adapter behind a {@link Files} instance, surfaced so callers can * branch (or fail fast) instead of discovering an unsupported operation mid-flight. */ interface StorageCapabilities { /** The adapter honours an object `cacheControl` directive on write. */ cacheControl: boolean; /** * Which ETag predicates the adapter evaluates natively: create-only and replace-if-match * uploads, exact reads, conditional deletes, and conditional copies. A predicate whose flag is * `false` rejects with `METHOD_NOT_ALLOWED` before any I/O. */ conditional: ConditionalSupport; /** The adapter persists and returns user-supplied key/value metadata. */ metadata: boolean; /** The adapter honours byte-range downloads (`download({ range })`). */ range: boolean; /** This `Files` view rejects every mutating operation. */ readonly: boolean; /** * Uploads with a `control` are written in parts whose progress the adapter persists in its * metadata store, so `UploadControl.toJSON()` can be resumed by another process (see * {@link UploadControl.from}). `false`: the adapter stores objects in one request; a resume * token is rejected with `METHOD_NOT_ALLOWED`. */ resumable: boolean; /** {@link Files.signedUpload} can sign a size-limited `POST` policy (`maxSize` / `minSize`). */ signedUploadPost: boolean; /** Longest `expiresIn` (seconds) the adapter can sign for, when the provider has a hard ceiling. */ signedUrlMaxExpiresIn?: number; } interface DownloadOptions extends IfMatchOptions, OperationOptions { /** * Fetch a contiguous byte slice instead of the whole object. Throws * `METHOD_NOT_ALLOWED` when the underlying adapter has `supportsRange = * false`, so the bandwidth saving is never silently lost client-side. */ range?: DownloadRange; } /** * Provider-agnostic metadata-only view of an object. */ interface FileObject { contentType: string; etag?: string; key: string; lastModified?: Date | number | string; metadata?: Record; size?: number; } interface DownloadResult extends FileObject { body: Buffer; } /** * Streaming variant of {@link DownloadResult} returned by {@link Files.downloadStream}. The object * body is exposed as a Node {@link NodeJS.ReadableStream} instead of a fully-buffered `Buffer`, so * serving a large object never allocates the whole payload in memory. Backed by the adapter's * native `getStream()`. */ interface DownloadStreamResult extends FileObject { body: Readable; } /** * Caller-facing event for {@link FilesOptions.hooks}. Mirrors what runs through * the facade (the public `key`/`keys` and the operation type) without leaking * adapter internals. */ interface HookEvent { durationMs?: number; error?: Error; /** Source key for `copy`/`move`. */ from?: string; key?: string; keys?: string[]; /** Destination key for `copy`/`move`. */ to?: string; type: HookActionType; } type HookActionType = "copy" | "delete" | "download" | "exists" | "head" | "list" | "listAll" | "move" | "signedUploadUrl" | "transfer" | "upload" | "url"; /** * Lifecycle hooks observed by the Files facade. Every hook is fire-and-forget — * called, not awaited — and exceptions are swallowed so a hook can never fail * the operation it observes. */ interface FilesHooks { /** Called once per successful operation, with timing and result keys. */ onAction?: (event: HookEvent) => void; /** Called once per failed operation, with the error attached. */ onError?: (event: HookEvent & { error: Error; }) => void; /** * Called when the underlying adapter retries an operation. Receives the * attempt number (1-based) and the error that triggered the retry. */ onRetry?: (event: HookEvent & { attempt: number; error: Error; }) => void; } interface FilesOptions { adapter: TStorage; /** * Default {@link OperationOptions} (`signal`, `timeout`, `retries`) merged into every call. * Per-call overrides win. The `signal` is combined with any per-call `signal` via * `AbortSignal.any`, so either one aborts the operation. */ defaults?: OperationOptions; /** * Lifecycle hooks observed by every operation. Fire-and-forget — a throwing * hook is silently swallowed and never fails the call it observes. */ hooks?: FilesHooks; /** * Namespace every key under this prefix. Reads, writes, copies, listings, URLs, and signed * uploads all resolve keys as `${prefix}/${key}`; returned keys (including from `list()`) have * the prefix stripped back off. Leading/trailing slashes are normalized so `"/users/"` and * `"users"` behave identically. * * `list()` scopes results on a path boundary, so `prefix: "users"` never matches the sibling * `users-archive/`. */ prefix?: string; /** * When `true`, every mutating operation (`upload`, `delete`, `copy`, `move`, `signedUploadUrl`) * fails immediately with an `UploadError` whose `UploadErrorCode` is `"ReadOnly"` before the adapter is touched; reads * (`download`, `head`, `exists`, `list`, `listAll`, `url`) pass through. Derive a locked view of * an existing client with {@link Files.readonly} instead of threading the flag manually. * @default false */ readonly?: boolean; } /** * One item in a bulk upload call. */ interface BulkUploadItem extends UploadOptions { body: FileBody; key: string; } /** * Per-call options shared by every bulk method (`upload`, `download`, `head`, `exists`, `delete`). */ interface BulkOptions extends OperationOptions { /** * Maximum number of in-flight operations. * @default 8 */ concurrency?: number; /** * When `true`, stop dispatching new operations as soon as one fails. The already-issued * operations still complete. Defaults to `false`: every key is attempted and per-key failures * are collected in `errors`. * @default false */ stopOnError?: boolean; } interface BulkDownloadOptions extends BulkOptions { range?: DownloadRange; } interface BulkUploadOptions extends BulkOptions { multipart?: MultipartOptions | boolean; onProgress?: UploadProgressCallback; } interface BulkError { error: Error; key: string; } interface BulkUploadResult { errors?: BulkError[]; uploaded: FileObject[]; } interface BulkDownloadResult { downloaded: DownloadResult[]; errors?: BulkError[]; } interface BulkHeadResult { errors?: BulkError[]; files: FileObject[]; } interface BulkExistsResult { errors?: BulkError[]; existing: string[]; missing: string[]; } interface BulkDeleteResult { deleted: string[]; errors?: BulkError[]; } interface BulkMoveItem { from: string; to: string; } interface BulkMoveResult { errors?: BulkError[]; moved: FileObject[]; } /** * Per-key event reported to {@link TransferOptions.onProgress}. */ interface TransferProgress { /** 1-based index of the current key in walk order. */ done: number; error?: Error; key: string; status: "errored" | "skipped" | "transferred"; } interface TransferOptions extends OperationOptions { /** * In-flight key transfers. * @default 8 */ concurrency?: number; /** Per-page size requested from the source adapter while walking. */ limit?: number; /** Fire-and-forget progress reporter. Throws are swallowed. */ onProgress?: (event: TransferProgress) => void; /** * When `false`, skip keys that already exist at the destination. When `true`, always upload. * @default false */ overwrite?: boolean; /** Restrict the walk to this prefix on the source. */ prefix?: string; /** * When `true`, the first failing transfer rejects {@link transfer} instead of being * collected in `errors`. * @default false */ stopOnError?: boolean; /** Transform each source key into the destination key. Defaults to identity. */ transformKey?: (key: string) => string; } interface TransferResult { errors?: BulkError[]; skipped: string[]; transferred: string[]; } /** * Per-key event reported to {@link SyncOptions.onProgress}. */ interface SyncProgress { /** 1-based index of the current key in walk order. */ done: number; error?: Error; key: string; status: "deleted" | "errored" | "skipped" | "unchanged" | "updated" | "uploaded"; } interface SyncOptions extends OperationOptions { /** * In-flight key operations. * @default 8 */ concurrency?: number; /** * Compute the plan without writing anything. The returned `uploaded`/`updated`/`deleted` lists * describe what *would* happen; the destination is left untouched. * @default false */ dryRun?: boolean; /** Per-page size requested from the source adapter while walking. */ limit?: number; /** Fire-and-forget progress reporter. Throws are swallowed. */ onProgress?: (event: SyncProgress) => void; /** Restrict the sync to this prefix on both source and destination. */ prefix?: string; /** * Delete destination keys that no longer exist on the source (mirror semantics). Pruning runs * after the copy pass so a failed upload never triggers a delete of its counterpart. Cannot be * combined with {@link SyncOptions.transformKey} — `sync` rejects with a `TypeError`. * @default false */ prune?: boolean; /** * When `true`, the first failing operation rejects {@link sync} instead of being collected in * `errors`. Pruning is skipped when a copy-phase error stops the run. * @default false */ stopOnError?: boolean; /** Transform each source key into the destination key. Defaults to identity. */ transformKey?: (key: string) => string; } interface SyncResult { /** Destination keys removed because they were absent from the source (only when `prune`). */ deleted: string[]; errors?: BulkError[]; /** Source keys whose destination copy already matched and was left untouched. */ unchanged: string[]; /** Source keys re-uploaded because the destination copy differed. */ updated: string[]; /** Source keys newly created at the destination. */ uploaded: string[]; } declare class Files { readonly adapter: TStorage; private readonly defaults; private readonly hooks; private readonly prefix; private readonly readonlyMode; constructor(options: FilesOptions); /** * Adapter capability + mode snapshot. Read before relying on an optional operation * (`range` downloads, custom `metadata`, `cacheControl`) so callers can branch instead of * hitting a `MethodNotAllowed` mid-flight. `readonly` reflects this view, not the adapter. */ get capabilities(): StorageCapabilities; /** * Derive a read-only view sharing this instance's adapter, prefix, defaults, and hooks. Every * mutating call on the returned client fails with an `UploadError` whose `UploadErrorCode` is `"ReadOnly"` before the * adapter is touched. Cheaper and safer than handing a writable client to code that should only * read. * @example * ```ts * const ro = files.readonly(); * await ro.download("a.txt"); // ok * await ro.delete("a.txt"); // throws ReadOnly * ``` */ readonly(): Files; /** * Validate the ETag predicates of a call and fail closed with `METHOD_NOT_ALLOWED` when the adapter * cannot evaluate `kind` natively — a predicate is never silently dropped. */ private assertConditional; /** Destination predicate of an upload or copy: `ifMatch` (replace) or `ifNoneMatch: "*"` (create). */ private static writeCondition; /** Reject an `expiresIn` the adapter cannot sign for, before it is handed to the provider. */ private assertExpiresIn; /** Fail closed before any adapter mutation when this view is read-only. */ private assertWritable; /** * Escape hatch to the adapter's native client (S3Client, BlobServiceClient, ...). * Typed via the `TStorage` parameter, so pinning the adapter type at construction yields a * typed view of the native client. Returns `undefined` when the adapter has no native client * (e.g. DiskStorage). */ get raw(): TStorage["raw"]; /** Resolve a caller-supplied key into the underlying storage key. */ private resolveKey; /** * Strip the constructor prefix off a key returned by the adapter. Returns `null` when the key * is outside the prefix or is the bare prefix itself (used to filter `list()` results on a path * boundary and drop any synthetic directory entry the adapter may emit). */ private stripPrefix; /** * Merge constructor defaults with per-call options. When `hooks.onRetry` is configured, * fold a wrapped `onRetry` into the per-call retry config so the hook fires with * facade-level context (type, key, from/to) for each retry attempt the adapter performs. */ private mergeOptions; private emitAction; private emitError; private withHooks; /** * Upload a single object, or — when passed an array of {@link BulkUploadItem}s — bulk-upload * many in one call with bounded concurrency. */ upload(key: string, body: FileBody, options?: OperationOptions & UploadOptions): Promise; upload(items: BulkUploadItem[], options?: BulkUploadOptions): Promise; private uploadOne; /** * Write `stream` as a series of adapter writes of one part each. The adapter persists its * offset (and provider session) in its metadata store after every part, so when this process * dies another one can resume from the token `control.toJSON()` returned. Resumes `control`'s * session when it carries one, after checking it still exists and describes this upload. */ private writeInParts; /** * The stored state of upload `id`, for resuming it. Appending adapters (S3 parts, GCS sessions, * Azure blocks) answer a write without a body with the provider's view of the upload; the * others keep the offset in their metadata record. */ private loadUpload; private uploadMany; /** * Download a single object, or — when passed an array of keys — bulk-download many in one * call with bounded concurrency. */ download(key: string, options?: DownloadOptions): Promise; download(keys: string[], options?: BulkDownloadOptions): Promise; private assertRangeSupported; private downloadOne; private downloadMany; /** * Download a single object as a readable stream instead of a buffered {@link DownloadResult}. * Backed by the adapter's native `getStream()`, this never allocates the whole payload in memory, * making it the right choice for serving large objects without the `.raw` escape hatch. Object * metadata (size, content-type, etag, last-modified) is fetched alongside the stream. */ downloadStream(key: string, options?: OperationOptions): Promise; /** * Fetch metadata for a single object, or — when passed an array of keys — bulk-head many in * one call with bounded concurrency. */ head(key: string, options?: HeadOptions): Promise; head(keys: string[], options?: BulkOptions): Promise; private headOne; private headMany; /** * Resolves to `true`/`false` for a single key, or — when passed an array — splits the keys * into `existing` and `missing` arrays. Hard errors (auth, transport) are reported in * `errors`. Never throws for a missing object. */ exists(key: string, options?: OperationOptions): Promise; exists(keys: string[], options?: BulkOptions): Promise; private existsOne; private existsMany; /** * Delete a single object (resolves to `void`, throws on failure), or — when passed an array * of keys — delete many in one call. Adapters with a native bulk-delete primitive (S3's * `DeleteObjects`, Supabase's `remove`, UploadThing's `deleteFiles`) use it via * {@link BaseStorage.deleteBatch}; otherwise the keys are fanned out with bounded concurrency. */ delete(key: string, options?: DeleteOptions): Promise; delete(keys: string[], options?: BulkOptions): Promise; private deleteOne; private deleteMany; /** * Copy `source` to `destination` (both resolved under any constructor prefix). Returns the * destination object's metadata with the caller-facing (un-prefixed) key. */ copy(source: string, destination: string, options?: CopyOptions): Promise; /** * Rename `source` to `destination`. Uses the adapter's native rename where one exists * (DiskStorage atomic move, Cloudinary server-side rename) and falls back to * `copy` + `delete` otherwise. Moving a key onto itself is a no-op. Also accepts an array of * `{ from, to }` items for bounded-concurrency bulk moves; per-item failures land in `errors`. */ move(from: string, to: string, options?: OperationOptions & { storageClass?: string; }): Promise; move(items: BulkMoveItem[], options?: BulkOptions): Promise; private moveOne; private moveMany; /** * List objects in the bucket. Returned keys have any constructor prefix stripped off, and * keys outside the prefix namespace (e.g. `users-archive/` when prefix is `users`) are filtered * out. The optional `prefix` filter is interpreted *relative to the constructor prefix*. * * Pass `delimiter` for directory-style listing: keys are collapsed into S3-style common * prefixes and the call returns `{ files, prefixes }` instead of a flat array (see * {@link ListDirectoryResult}). Objects with no further delimiter after the listing prefix come * back as `files`; everything below a shared boundary folds into a single `prefixes` entry. * * **Caveat with constructor prefix**: `limit` is applied by the underlying adapter *before* * the path-boundary filter runs, so the returned array may contain fewer than `limit` items * even when more in-namespace objects exist. Use {@link Files.listAll} when you need every * in-namespace object. */ list(options?: Omit & OperationOptions): Promise; list(options: ListOptions & OperationOptions & { delimiter: string; }): Promise; /** * Native directory listing: push the `delimiter` down to an adapter that collapses common * prefixes server-side ({@link BaseStorage.supportsDelimiter}). Resolves the listing prefix * against the constructor prefix, then strips it back off the returned keys and prefixes so the * result matches the facade-synthesized shape. */ private listDirectoryNative; /** * Walk every object in the bucket. Yields one {@link FileObject} at a time as an async * iterable; pages internally so callers don't have to thread a cursor. Returned keys have any * constructor prefix stripped off and out-of-namespace keys are filtered out, just like * {@link Files.list}. * * `limit` is the initial page size (default 1000). Because `BaseStorage.list` has no cursor, * each further round re-lists with a doubled limit and yields only the new keys, until the * adapter returns fewer objects than requested. The built-in adapters page through their * provider internally up to `limit`, so every object is reached; a custom adapter whose full * page brings no new keys makes the walk throw instead of truncating silently. * @example * ```ts * for await (const file of files.listAll({ prefix: "avatars/" })) { * console.log(file.key, file.size); * } * ``` */ listAll(options?: ListAllOptions & OperationOptions): AsyncGenerator; /** * Find objects whose key matches `pattern`, walking every page like {@link Files.listAll}. A * streaming async iterable: it stays memory-bounded on large buckets, and leaving the loop (or * reaching `limit`) stops fetching pages. * * A string is a glob by default (`*` within a segment, `**` across segments, `?`, `[a-z]`, * `{a,b}`, `!negation`; anchored to the whole key; dotfiles match). Pass `match` for `regex`, * `substring` or `exact`, or a `RegExp` directly. Keys are matched without the constructor * prefix. A glob's (or exact pattern's) literal head becomes the walk's `prefix`, so only keys * under `uploads/2024/` are matched for `"uploads/2024/*.pdf"`. The adapters' `list` takes no * prefix, so the provider listing itself still covers the whole bucket: on large buckets, keep * keys under a constructor `prefix` or use `list({ prefix })` where the adapter supports it. * @throws {UploadError} BAD_REQUEST for an invalid regex, one that nests quantifiers (`(a+)+`), or an invalid `limit` * @example * ```ts * for await (const file of files.search("avatars/**\/*.png", { limit: 50 })) { * console.log(file.key); * } * ``` */ search(pattern: RegExp | string, options?: SearchOptions): AsyncGenerator; url(key: string, options?: OperationOptions & SignedReadUrlOptions): Promise; signedUploadUrl(key: string, options?: OperationOptions & SignedUploadUrlOptions): Promise; /** * Sign a direct browser upload of `key` and return the full contract instead of a bare URL. * * Without `maxSize` / `minSize` this is a presigned `PUT` (`{ method: "PUT", url, headers }`), * the same URL {@link Files.signedUploadUrl} returns, plus the headers the client must send. With * either limit it is a presigned `POST` policy (`{ method: "POST", url, fields }`) carrying a * `content-length-range` condition, so the provider itself rejects a body outside the range — a * PUT URL cannot do that. Adapters without POST policy support * (`capabilities.signedUploadPost === false`) reject a size limit with `METHOD_NOT_ALLOWED` * rather than sign an unbounded upload. * @example * ```ts * const upload = await files.signedUpload("avatars/1.png", { contentType: "image/png", maxSize: 5 * 1024 * 1024 }); * * if (upload.method === "POST") { * const form = new FormData(); * * for (const [name, value] of Object.entries(upload.fields)) form.append(name, value); * form.append("file", blob); * await fetch(upload.url, { body: form, method: "POST" }); * } * ``` */ signedUpload(key: string, options?: OperationOptions & SignedUploadOptions): Promise; } export { SearchOptions as A, BulkDeleteResult as B, CopyOptions as C, DeleteOptions as D, SignedReadUrlOptions as E, Files as F, SignedUpload as G, HeadOptions as H, IfMatchOptions as I, SignedUploadOptions as J, SignedUploadUrlOptions as K, ListAllOptions as L, MultipartOptions as M, StorageCapabilities as N, SyncProgress as O, TransferProgress as P, UploadControlState as Q, UploadControlToken as R, SyncOptions as S, TransferOptions as T, UploadControl as U, UploadOptions as V, UploadProgress as W, UploadProgressCallback as X, SyncResult as a, TransferResult as b, BulkDownloadOptions as c, BulkDownloadResult as d, BulkError as e, BulkExistsResult as f, BulkHeadResult as g, BulkMoveItem as h, BulkMoveResult as i, BulkOptions as j, BulkUploadItem as k, BulkUploadOptions as l, BulkUploadResult as m, DownloadOptions as n, DownloadRange as o, DownloadResult as p, DownloadStreamResult as q, FileBody as r, FileObject as s, FilesHooks as t, FilesOptions as u, HookActionType as v, HookEvent as w, ListDirectoryResult as x, ListOptions as y, SearchMatch as z };