import type { Bucket, PutOptions } from "@upstash/blob"; import type { Command } from "commander"; import type { BucketResolver } from "./buckets.js"; export type Location = { type: "local"; path: string; } | { type: "blob"; bucket: string; key: string; }; export type BlobLocation = Extract; export declare function parseLocation(value: string): Location; /** For arguments that can only be in a bucket, where `my-bucket/key` means `blob://my-bucket/key`. */ export declare function parseBlobLocation(value: string): BlobLocation; /** A whole bucket: `my-bucket`, or `blob://my-bucket`, by name or id. */ export declare function parseBucket(value: string): string; export declare function formatLocation(location: Location): string; /** How aws s3 treats the source of a recursive command: as a directory, whether or not it ends in a slash. */ export declare function dirPrefix(key: string): string; interface FilterFlag { exclude: boolean; pattern: string; order: number; } export interface Filter { exclude: boolean; match: RegExp; } /** fnmatch, as aws s3 uses it: `*` also crosses slashes. */ export declare function globToRegExp(glob: string): RegExp; export declare function filtersOf(options: { exclude?: FilterFlag[]; include?: FilterFlag[]; }): Filter[]; /** Everything is included until a filter matches; the last matching filter decides. */ export declare function isIncluded(path: string, filters: Filter[]): boolean; export interface CommonOptions { token?: string; dryrun?: boolean; dryRun?: boolean; quiet?: boolean; concurrency: number; exclude?: FilterFlag[]; include?: FilterFlag[]; } export interface ObjectOptions { followSymlinks?: boolean; contentType?: string; cacheControl?: string; metadata?: Record; } export declare function addCommonOptions(command: Command): Command; export declare function addObjectOptions(command: Command): Command; export declare function isDryRun(options: { dryrun?: boolean; dryRun?: boolean; }): boolean; export interface Entry { /** Path below the listed directory or prefix, with forward slashes. */ rel: string; size: number; /** Local mtime or the object's LastModified, in milliseconds. */ mtime: number; location: Location; /** Reached through a symbolic link to a directory, so deleting it deletes a file outside the walked tree. */ linked?: boolean; } /** * Every object below `prefix`. Zero-byte "folder" markers ending in "/" are skipped, as aws s3 skips * them everywhere except deletes; `forDelete` keeps them, the marker at the prefix itself included. */ export declare function listBlobs(bucket: Bucket, location: BlobLocation, prefix: string, forDelete?: boolean): Promise; /** What a cp, mv or sync reads: one file or object, or everything below a directory or prefix. */ export declare function listSource(location: Location, recursive: boolean, resolver: BucketResolver, followSymlinks?: boolean): Promise; /** What a sync compares against; a missing local directory is simply empty. */ export declare function listDestination(location: Location, resolver: BucketResolver): Promise; export declare function isLocalDirectory(path: string): Promise; export type Action = "upload" | "download" | "copy" | "delete"; export interface Operation { action: Action; source: Location; destination?: Location; size: number; /** Delete the source once the transfer succeeds. */ move?: boolean; } export interface Failure { source: string; destination?: string; error: string; } export declare function transferAction(source: Location, destination: Location): Exclude; /** * Where one entry lands. A blob key ending in "/" or empty, a local directory, and every recursive * command take the source's relative path; otherwise the destination names the object or file. */ export declare function destinationFor(entry: Entry, destination: Location, into: boolean): Location; /** Where `rel` lands below a local directory, as the directory walk would report it. */ export declare function localRel(rel: string): string; /** macOS and Windows disks ignore case, and macOS also Unicode normalization. */ export declare const foldsCase: boolean; /** Identifies a local file, folding case and Unicode form where the disk does or where a wrong guess loses data. */ export declare function localFileKey(path: string, fold?: boolean): string; /** The path with symbolic links resolved as far as it exists, so aliases of one file compare equal. */ export declare function realLocalPath(path: string): Promise; /** * Two keys can land on one local file: `a//b` and `a/b`, `A.txt` and `a.txt` on a case-insensitive * disk, or `real/x` and `link/x` through a symbolic link. Only the first may write it, so an mv * cannot delete the other's source. */ export declare function claimLocal(claimed: Set, destination: Location, fold?: boolean): Promise; /** * When `inner` is a prefix nested inside `outer` in the same bucket, returns it. With the * destination inside, the source listing skips those keys: `mv blob://b/ blob://b/archive/` must * not move its own output. With the source inside, copies onto keys below it are refused. */ export declare function nestedPrefix(outer: Location, inner: Location, resolver: BucketResolver): Promise; /** Refuses a copy onto a key below `sourcePrefix`, which is another object of the same transfer. */ export declare function checkOverwritesSource(destination: Location, sourcePrefix: string | undefined): void; export declare function describe(operation: Operation): string; export interface TransferSettings extends ObjectOptions { resolver: BucketResolver; concurrency: number; signal: AbortSignal; progress: (line: string) => void; } export interface TransferSummary { completed: number; bytes: number; failed: Failure[]; remaining: number; } export interface UploadFile { source: string; key: string; size: number; contentType: string; } /** Streams one local file to the bucket, retrying transient failures from the start of the file. */ export declare function putFile(bucket: Pick, file: UploadFile, signal?: AbortSignal, options?: Pick): Promise; /** Transfers run concurrently and keep going past failures, as aws s3 does; deletes run after, in batches. */ export declare function runOperations(operations: Operation[], settings: TransferSettings): Promise; /** * Shared tail of cp, mv, rm and sync: print the plan on --dryrun, otherwise run it with Ctrl+C * stopping new work, then print the JSON summary and fail if anything did. */ export declare function executePlan(operations: Operation[], failures: Failure[], options: CommonOptions & ObjectOptions, resolver: BucketResolver, extra?: Record): Promise; export {}; //# sourceMappingURL=transfer.d.ts.map