import type { AdapterCapabilities, SearchMatch, SignedUpload } from "../../index.js"; import type { JsonValue } from "../json.js"; /** * The coarse, authorize-facing verbs. A bulk wire op (`head-many`) authorizes * under its single verb (`head`); the byte paths (`download`, `upload`) keep * their own verb so an app can allow reads but deny writes in one predicate. */ export type FilesOperation = "head" | "exists" | "list" | "search" | "url" | "capabilities" | "download" | "upload" | "delete" | "copy" | "move" | "signedUploadUrl" | "versions" | "restoreVersion" | "trashed" | "restoreTrashed" | "purge"; /** Every JSON op the gateway dispatches on (POST `{ op, ... }`). */ export type WireOp = "head" | "head-many" | "exists" | "exists-many" | "delete" | "delete-many" | "copy" | "move" | "url" | "list" | "search" | "capabilities" | "signed-upload-url" | "presign" | "complete" | "versions" | "restore-version" | "trashed" | "restore-trashed" | "purge"; /** A serialized `FileInfo` — metadata only, the body is never inlined. */ export interface WireFileInfo { key: string; size: number; contentType: string; lastModified?: number; etag?: string; metadata?: Record; } /** A serialized `FilesError` — what `filesErrorReplacer` emits (no `cause`). */ export interface WireFilesError { code: string; message: string; aborted: boolean; timedOut: boolean; /** Why the gateway refused it, when it did — e.g. `size` or `rejected` on a `complete` entry. */ reason?: WireErrorReason; } /** One per-key failure from a bulk op, mirroring `BulkError`. */ export interface WireBulkError { key: string; error: WireFilesError; } export type JsonRequest = { op: "head"; key: string; } | { op: "head-many"; keys: string[]; concurrency?: number; stopOnError?: boolean; } | { op: "exists"; key: string; } | { op: "exists-many"; keys: string[]; concurrency?: number; stopOnError?: boolean; } | { op: "delete"; key: string; } | { op: "delete-many"; keys: string[]; concurrency?: number; stopOnError?: boolean; } | { op: "copy"; from: string; to: string; } | { op: "move"; from: string; to: string; } | { op: "url"; key: string; expiresIn?: number; responseContentDisposition?: string; } | { op: "list"; prefix?: string; cursor?: string; limit?: number; delimiter?: string; } | { op: "search"; pattern: string; isRegex?: boolean; flags?: string; match?: SearchMatch; prefix?: string; limit?: number; maxResults?: number; caseInsensitive?: boolean; } | { op: "capabilities"; } | { op: "signed-upload-url"; key: string; expiresIn: number; contentType?: string; maxSize?: number; minSize?: number; } | { op: "presign"; files: ClientFileInfo[]; expiresIn?: number; } | { op: "complete"; completions: { id: string; key: string; }[]; } | { op: "versions"; key: string; } | { op: "restore-version"; key: string; versionId?: string; } | { op: "trashed"; } | { op: "restore-trashed"; key: string; } | { op: "purge"; key?: string; }; /** Client-reported file info for keyless presign — used for keygen/validation only. */ export interface ClientFileInfo { name: string; /** * The file's byte size, when the client knows it. The upload token binds it * (capped by `maxUploadSize`), so the bytes that land may not exceed it; * omit it only when the size is genuinely unknown. */ size?: number; /** A single media type (`image/png`), or `""` for none. */ type: string; } /** The presign target the client drives — a real `SignedUpload`, or a proxy PUT back at us. */ export type UploadTarget = SignedUpload; export interface PresignedUpload { /** HMAC token binding `{ key, constraints, exp }` — the client echoes it back on `complete`. */ id: string; key: string; target: UploadTarget; } export interface HeadResponse { file: WireFileInfo; } export interface HeadManyResponse { results: WireFileInfo[]; errors?: WireBulkError[]; } export interface ExistsResponse { exists: boolean; } export interface ExistsManyResponse { existing: string[]; missing: string[]; errors?: WireBulkError[]; } export interface OkResponse { ok: true; } export interface DeleteManyResponse { results: string[]; errors?: WireBulkError[]; } export interface UrlResponse { url: string; } export interface ListResponse { items: WireFileInfo[]; prefixes?: string[]; cursor?: string; } export interface SearchResponse { matches: WireFileInfo[]; /** * More matches may exist: the walk stopped at the result cap or at the * gateway's scan budget (`maxSearchScan`) before reaching the end. */ truncated: boolean; } export interface CapabilitiesResponse { capabilities: AdapterCapabilities; } export interface SignedUploadUrlResponse { signed: SignedUpload; } export interface PresignResponse { uploads: PresignedUpload[]; } /** A completed upload: its metadata, plus whatever the gateway's `onUploadComplete` returned. */ export interface WireUploadedFile extends WireFileInfo { data?: JsonValue; } export interface CompleteResponse { files: WireUploadedFile[]; errors?: WireBulkError[]; } /** The keyed `PUT ?op=upload&key=` response. */ export interface ExplicitUploadResponse { ok: true; file: WireUploadedFile; } /** * A saved version on the wire (from `versioning()`). The internal version * storage key is intentionally omitted — the client addresses a version by * `versionId` against the original key, never by its `.versions/` path. */ export interface WireFileVersion { versionId: string; size: number; lastModified: number; etag?: string; } /** * A trashed object on the wire (from `softDelete()`). Carries the original * (unscoped) `key`; the internal `.trash/` storage key is omitted. */ export interface WireTrashedFile { key: string; size: number; lastModified?: number; etag?: string; } export interface VersionsResponse { versions: WireFileVersion[]; } export interface TrashedResponse { trashed: WireTrashedFile[]; } export type WireErrorCode = "Unauthorized" | "Forbidden" | "NotFound" | "Conflict" | "ReadOnly" | "Validation" | "Unsupported" | "Provider"; export type WireErrorReason = "type" | "size" | "key" | "count" | "origin" | "forbidden" | "capability" | "range" /** `onUploadComplete` threw `UploadRejectedError`. */ | "rejected"; export interface WireError { error: { code: WireErrorCode; reason?: WireErrorReason; message: string; }; } /** * The base64 JSON `X-Files-Meta` header on a proxied `download` — the * metadata with no HTTP-header home. `size` is the whole object's byte size, * sent on a full (`200`) response only: compression middleware can drop * `Content-Length`, so the client reads the size from here when it's present. */ export interface WireDownloadMeta { key: string; etag?: string; lastModified?: number; metadata?: Record; size?: number; } /** The query-string actions for the two byte paths. */ export declare const DOWNLOAD_ACTION = "download"; export declare const UPLOAD_ACTION = "upload"; export declare const PROXY_ACTION = "proxy"; /** Default endpoint the client and demos assume. */ export declare const DEFAULT_ENDPOINT = "/api/files"; /** * The `data` a router's `onUploadComplete` hands back to the client, for * `createFilesClient<…>()` / `useFiles<…>()`. A type-only import of the * router keeps server code out of the client bundle: * * ```ts * import type { router } from "./server"; * const files = useFiles>(); * ``` * * It reads the router's phantom `~uploadData` field structurally, so the * client's own types never reach into the gateway's modules. */ export type InferUploadData = T extends { readonly "~uploadData"?: infer TData; } ? Awaited : never; //# sourceMappingURL=protocol.d.ts.map