import { AnyFileRoute, EndpointArg, FileRouter, GenerateUploaderOptions, NewPresignedUrl, RouteRegistry } from "../dist/types-Bs3w2d_3.js";
import * as Micro from "effect/Micro";
import { FetchContext, FetchError, MaybePromise, UploadAbortedError, UploadAbortedError as UploadAbortedError$1, UploadPausedError, generateClientDropzoneAccept, generateMimeTypes, generatePermittedFileTypes } from "@uploadthing/shared";
import { LazyArg } from "effect/Function";
import * as effect_Types0 from "effect/Types";
//#region src/_internal/random-hex.d.ts
type TraceHeaders = {
b3: string;
traceparent: string;
};
//#endregion
//#region src/_internal/client-future.d.ts
declare const XHRError_base: new = {}>(args: effect_Types0.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Micro.YieldableError & {
readonly _tag: "XHRError";
} & Readonly;
/**
* Error indicating the XHR request failed
* @public
*/
declare class XHRError extends XHRError_base<{
message: string;
xhr: unknown;
}> {}
/**
* Error indicating the network request failed
* @public
*/
type NetworkError = XHRError | FetchError;
declare const UTStorageError_base: new = {}>(args: effect_Types0.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Micro.YieldableError & {
readonly _tag: "UTStorageError";
} & Readonly;
/**
* Error indicating the upload was rejected during upload to the storage provider
* @public
*/
declare class UTStorageError extends UTStorageError_base<{
message: string;
response: unknown;
}> {}
declare const UTServerError_base: new = {}>(args: effect_Types0.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Micro.YieldableError & {
readonly _tag: "UTServerError";
} & Readonly;
/**
* Error indicating the request to your UploadThing server failed
* @public
*/
declare class UTServerError extends UTServerError_base<{
message: string;
cause: unknown;
/**
* Matches the shape returned by your error formatter
*/
data: TErrorShape;
}> {}
/**
* Error indicating the upload failed
* @public
*/
type UploadThingClientError = UploadAbortedError$1 | NetworkError | UTStorageError | UTServerError;
/**
* A file that has not started uploading yet.
* Can either be pending for the presigned request to resolve,
* or pending for the browser to schedule the network request.
* @public
*/
interface PendingFile extends File {
status: "pending";
/**
* How many bytes of the file has been uploaded
* @example 0
*/
sent: number;
/**
* The key of the file. Null before the presigned request resolves.
*/
key: string | null;
/**
* The customId of the file. Null before the presigned request resolves, then present if your file route sets it
*/
customId: string | null;
}
/**
* A file that is currently uploading.
* @public
*/
interface UploadingFile extends File {
status: "uploading";
/**
* How many bytes of the file has been uploaded
* @example 2500
*/
sent: number;
/**
* The key of the file.
*/
key: string;
/**
* The customId of the file, if your file route sets it
*/
customId: string | null;
}
/**
* A file that failed to upload.
* @public
*/
interface FailedFile extends File {
status: "failed";
/**
* How many bytes of the file were uploaded before the upload failed.
* @example 2500
*/
sent: number;
/**
* The key of the file.
*/
key: string;
/**
* The customId of the file, if your file route sets it
*/
customId: string | null;
/**
* The error that occurred during the upload.
*/
reason: UploadThingClientError;
}
/**
* A file that has been uploaded successfully.
* @public
*/
interface UploadedFile extends File {
status: "uploaded";
/**
* How many bytes of the file has been uploaded.
* @example 10000
*/
sent: number;
/**
* The key of the file.
*/
key: string;
/**
* The customId of the file, if your file route sets it
*/
customId: string | null;
/**
* The url of the file.
* @example "https://APP_ID.ufs.sh/f/KEY"
*/
url: string;
/**
* The data returned by the serverside `onUploadComplete` callback.
* @example { uploadedBy: "user_123" }
*/
data: TRoute["$types"]["output"];
/**
* The hash ( <> checksum ) of the file.
*/
hash: string;
}
/**
* A web file with additional state properties
* @public
*/
type AnyFile = PendingFile | UploadingFile | FailedFile | UploadedFile;
/**
* Predicate function to check if a file is pending
* @public
*/
declare function isPendingFile(file: AnyFile): file is PendingFile;
/**
* Predicate function to check if a file is uploading
* @public
*/
declare function isUploadingFile(file: AnyFile): file is UploadingFile;
/**
* Predicate function to check if a file is failed
* @public
*/
declare function isFailedFile(file: AnyFile): file is FailedFile;
/**
* Predicate function to check if a file is uploaded
* @public
*/
declare function isUploadedFile(file: AnyFile): file is UploadedFile;
/**
* @internal
*/
declare function makePendingFile(file: File): PendingFile;
/**
* Modifies a pending or uploading file to a failed file in place
* @internal
*/
declare function transitionToFailed(file: PendingFile | UploadingFile, reason: UploadThingClientError): FailedFile;
/**
* Event emitted when the presigned URLs have been retrieved from your server
* @public
*/
interface PresignedReceivedEvent {
type: "presigned-received";
/**
* All files that are being uploaded as part of this action.
*/
files: AnyFile[];
}
/**
* Event emitted when a file starts uploading
* @public
*/
interface UploadStartedEvent {
type: "upload-started";
/**
* The file that started uploading.
*/
file: UploadingFile;
/**
* All files that are being uploaded as part of this action.
*/
files: AnyFile[];
}
/**
* Event emitted when a file is uploading and received a progress update
* @public
*/
interface UploadProgressEvent {
type: "upload-progress";
/**
* The file that is currently uploading and received a progress update.
*/
file: UploadingFile;
/**
* All files that are being uploaded as part of this action.
*/
files: AnyFile[];
}
/**
* Event emitted when a file has finished uploading
* @public
*/
interface UploadCompletedEvent {
type: "upload-completed";
/**
* The file that finished uploading.
*/
file: UploadedFile;
/**
* All files that are being uploaded as part of this action.
*/
files: AnyFile[];
}
/**
* Event emitted when a file failed to upload
* @public
*/
interface UploadFailedEvent {
type: "upload-failed";
/**
* The file that failed to upload.
*/
file: FailedFile;
/**
* All files that are being uploaded as part of this action.
*/
files: AnyFile[];
}
interface UploadAbortedEvent {
type: "upload-aborted";
files: AnyFile[];
}
/**
* Event emitted throughout the upload process
* @public
*/
type UploadEvent = PresignedReceivedEvent | UploadStartedEvent | UploadProgressEvent | UploadCompletedEvent | UploadFailedEvent | UploadAbortedEvent;
interface UploadFileOptions {
file: PendingFile;
files: AnyFile[];
input: TRoute["$types"]["input"];
onEvent: (event: UploadEvent) => void;
traceHeaders: TraceHeaders;
XHRImpl: new () => XMLHttpRequest;
}
/**
* Upload a file to the storage provider
* Throughout the upload, the file's status and progress will be updated
* @remarks This function never rejects
* @internal
*/
declare function uploadFile(url: string, {
file,
files,
XHRImpl,
...options
}: UploadFileOptions): Micro.Micro | FailedFile, never, FetchContext>;
interface RequestPresignedUrlsOptions {
/**
* The URL to your UploadThing server endpoint
* @example URL { https://www.example.com/api/uploadthing }
*/
url: URL;
/**
* The slug to your UploadThing FileRoute
* @example "imageUploader"
*/
endpoint: TEndpoint;
/**
* The files to request presigned URLs for
*/
files: File[];
/**
* The route input for the endpoint
*/
input?: TRouter[TEndpoint]["$types"]["input"];
/**
* Custom headers to send with the request
* @example { Authorization: "Bearer 123" }
*/
headers?: HeadersInit | LazyArg> | undefined;
/**
* Custom trace headers to send with the request
*/
traceHeaders: TraceHeaders;
/**
* The uploadthing package that is making this request, used to identify the client in the server logs
* @example "@uploadthing/react"
*/
package?: string | undefined;
}
/**
* Request presigned URLs from your server for a set of files
* @internal
*/
declare function requestPresignedUrls(options: RequestPresignedUrlsOptions): Micro.Micro, UTServerError, FetchContext>;
interface UploadFilesOptions {
url: URL;
files: File[];
input?: TRoute["$types"]["input"];
onEvent: (event: UploadEvent) => void;
headers?: HeadersInit | LazyArg> | undefined;
package?: string | undefined;
signal?: AbortSignal | undefined;
}
/**
* Upload a set of files to the storage provider
* @internal
*/
declare function uploadFiles(endpoint: TEndpoint, options: UploadFilesOptions): Micro.Micro<(FailedFile | UploadedFile)[], UTServerError, FetchContext>;
//#endregion
//#region src/client-future.d.ts
declare const version: string;
/**
* Generate a typed uploader for a given FileRouter
* @public
* @remarks This API is not covered by semver
*/
declare const future_genUploader: (initOpts?: GenerateUploaderOptions) => {
uploadFiles: (slug: EndpointArg, opts: Omit, keyof GenerateUploaderOptions>) => Promise<(FailedFile | UploadedFile)[]>;
createUpload: (slug: EndpointArg, options: Omit, keyof GenerateUploaderOptions>) => Promise<{
pauseUpload: (file?: File) => void;
abortUpload: (file?: File) => void;
resumeUpload: (file?: File) => void;
done: | void = void>(file?: T) => Promise ? UploadedFile | FailedFile : (UploadedFile | FailedFile)[]>;
}>;
/**
* Identity object that can be used instead of raw strings
* that allows "Go to definition" in your IDE to bring you
* to the backend definition of a route.
*/
routeRegistry: RouteRegistry;
};
//#endregion
export { AnyFile, FailedFile, NetworkError, PendingFile, PresignedReceivedEvent, RequestPresignedUrlsOptions, UTServerError, UTStorageError, UploadAbortedError, UploadAbortedEvent, UploadCompletedEvent, UploadEvent, UploadFailedEvent, UploadFileOptions, UploadFilesOptions, UploadPausedError, UploadProgressEvent, UploadStartedEvent, UploadThingClientError, UploadedFile, UploadingFile, XHRError, future_genUploader, generateClientDropzoneAccept, generateMimeTypes, generatePermittedFileTypes, isFailedFile, isPendingFile, isUploadedFile, isUploadingFile, makePendingFile, requestPresignedUrls, transitionToFailed, uploadFile, uploadFiles, version };
//# sourceMappingURL=index.d.ts.map