diff --git a/packages/expo/src/document-picker.ts b/packages/expo/src/document-picker.ts index 99d61df5cf..ea05538739 100644 --- a/packages/expo/src/document-picker.ts +++ b/packages/expo/src/document-picker.ts @@ -36,7 +36,7 @@ export const GENERATE_useDocumentUploader = < }) => { const useDocumentUploader = ( endpoint: TEndpoint, - opts?: UseUploadthingProps, + opts?: UseUploadthingProps, ) => { const { routeConfig, startUpload, isUploading } = __useUploadThingInternal( initOpts.url, diff --git a/packages/expo/src/image-picker.ts b/packages/expo/src/image-picker.ts index 33475bf15e..e88603e5ee 100644 --- a/packages/expo/src/image-picker.ts +++ b/packages/expo/src/image-picker.ts @@ -28,7 +28,7 @@ export const GENERATE_useImageUploader = < }) => { const useImageUploader = ( endpoint: TEndpoint, - opts?: UseUploadthingProps, + opts?: UseUploadthingProps, ) => { const { routeConfig, startUpload, isUploading } = __useUploadThingInternal( initOpts.url, diff --git a/packages/react/src/types.ts b/packages/react/src/types.ts index 9465a7e3d4..e215624d2a 100644 --- a/packages/react/src/types.ts +++ b/packages/react/src/types.ts @@ -6,6 +6,7 @@ import type { UploadThingError, } from "@uploadthing/shared"; import type { + AnyFileRoute, ClientUploadedFileData, EndpointArg, FileRouter, @@ -28,9 +29,8 @@ export interface GenerateTypedHelpersOptions { } export type UseUploadthingProps< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, - TServerOutput = inferEndpointOutput, + TFileRoute extends AnyFileRoute, + TServerOutput = inferEndpointOutput, > = { /** * Called when the upload is submitted and the server is about to be queried for presigned URLs @@ -74,7 +74,7 @@ export type UseUploadthingProps< * Called if the upload fails */ onUploadError?: - | ((e: UploadThingError>) => MaybePromise) + | ((e: UploadThingError>) => MaybePromise) | undefined; /** * Set custom headers that'll get sent with requests @@ -94,7 +94,7 @@ export type UploadthingComponentProps< TRouter extends FileRouter, TEndpoint extends keyof TRouter, > = Omit< - UseUploadthingProps, + UseUploadthingProps, /** * Signal is omitted, component has its own AbortController * If you need to control the interruption with more granularity, diff --git a/packages/react/src/useUploadThing.ts b/packages/react/src/useUploadThing.ts index fa53cc8582..4615e287bd 100644 --- a/packages/react/src/useUploadThing.ts +++ b/packages/react/src/useUploadThing.ts @@ -55,7 +55,7 @@ export function __useUploadThingInternal< >( url: URL, endpoint: EndpointArg, - opts?: UseUploadthingProps, + opts?: UseUploadthingProps, ) { const { uploadFiles, routeRegistry } = genUploader({ url, @@ -115,9 +115,9 @@ export function __useUploadThingInternal< */ if (e instanceof UploadAbortedError) throw e; - let error: UploadThingError>; + let error: UploadThingError>; if (e instanceof UploadThingError) { - error = e as UploadThingError>; + error = e as UploadThingError>; } else { error = INTERNAL_DO_NOT_USE__fatalClientError(e as Error); console.error( @@ -161,7 +161,7 @@ export const generateReactHelpers = ( function useUploadThing( endpoint: EndpointArg, - opts?: UseUploadthingProps, + opts?: UseUploadthingProps, ) { return __useUploadThingInternal(url, endpoint, opts); } diff --git a/packages/solid/src/create-uploadthing.ts b/packages/solid/src/create-uploadthing.ts index 859bc2c53d..7bd00fafd1 100644 --- a/packages/solid/src/create-uploadthing.ts +++ b/packages/solid/src/create-uploadthing.ts @@ -44,7 +44,7 @@ export const INTERNAL_createUploadThingGen = < const createUploadThing = ( endpoint: EndpointArg, - opts?: CreateUploadthingProps, + opts?: CreateUploadthingProps, ) => { const [isUploading, setUploading] = createSignal(false); let uploadProgress = 0; @@ -99,9 +99,9 @@ export const INTERNAL_createUploadThingGen = < */ if (e instanceof UploadAbortedError) throw e; - let error: UploadThingError>; + let error: UploadThingError>; if (e instanceof UploadThingError) { - error = e as UploadThingError>; + error = e as UploadThingError>; } else { error = INTERNAL_DO_NOT_USE__fatalClientError(e as Error); console.error( diff --git a/packages/solid/src/types.ts b/packages/solid/src/types.ts index 4c8e4ba2d9..1f7ebe580b 100644 --- a/packages/solid/src/types.ts +++ b/packages/solid/src/types.ts @@ -6,6 +6,7 @@ import type { UploadThingError, } from "@uploadthing/shared"; import type { + AnyFileRoute, ClientUploadedFileData, EndpointArg, FileRouter, @@ -28,9 +29,8 @@ export interface GenerateTypedHelpersOptions { } export type CreateUploadthingProps< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, - TServerOutput = inferEndpointOutput, + TFileRoute extends AnyFileRoute, + TServerOutput = inferEndpointOutput, > = { /** * Called when the upload is submitted and the server is about to be queried for presigned URLs @@ -74,7 +74,7 @@ export type CreateUploadthingProps< * Called if the upload fails */ onUploadError?: - | ((e: UploadThingError>) => MaybePromise) + | ((e: UploadThingError>) => MaybePromise) | undefined; /** * Set custom headers that'll get sent with requests @@ -94,16 +94,15 @@ export type CreateUploadthingProps< * @deprecated Use `CreateUploadthingProps` instead */ export type UseUploadThingProps< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, - TServerOutput = inferEndpointOutput, -> = CreateUploadthingProps; + TFileRoute extends AnyFileRoute, + TServerOutput = inferEndpointOutput, +> = CreateUploadthingProps; export type UploadthingComponentProps< TRouter extends FileRouter, TEndpoint extends keyof TRouter, > = Omit< - CreateUploadthingProps, + CreateUploadthingProps, /** * Signal is omitted, component has its own AbortController * If you need to control the interruption with more granularity, diff --git a/packages/svelte/src/lib/create-uploadthing.ts b/packages/svelte/src/lib/create-uploadthing.ts index 7b7489798e..b282599f17 100644 --- a/packages/svelte/src/lib/create-uploadthing.ts +++ b/packages/svelte/src/lib/create-uploadthing.ts @@ -48,7 +48,7 @@ export const INTERNAL_createUploadThingGen = < const useUploadThing = ( endpoint: EndpointArg, - opts?: UseUploadthingProps, + opts?: UseUploadthingProps, ) => { const isUploading = writable(false); let uploadProgress = 0; @@ -103,9 +103,9 @@ export const INTERNAL_createUploadThingGen = < */ if (e instanceof UploadAbortedError) throw e; - let error: UploadThingError>; + let error: UploadThingError>; if (e instanceof UploadThingError) { - error = e as UploadThingError>; + error = e as UploadThingError>; } else { error = INTERNAL_DO_NOT_USE__fatalClientError(e as Error); console.error( diff --git a/packages/svelte/src/lib/types.ts b/packages/svelte/src/lib/types.ts index fe59cae3dd..76b84febff 100644 --- a/packages/svelte/src/lib/types.ts +++ b/packages/svelte/src/lib/types.ts @@ -6,6 +6,7 @@ import type { UploadThingError, } from "@uploadthing/shared"; import type { + AnyFileRoute, ClientUploadedFileData, EndpointArg, FileRouter, @@ -28,9 +29,8 @@ export interface GenerateTypedHelpersOptions { } export type UseUploadthingProps< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, - TServerOutput = inferEndpointOutput, + TFileRoute extends AnyFileRoute, + TServerOutput = inferEndpointOutput, > = { /** * Called when the upload is submitted and the server is about to be queried for presigned URLs @@ -74,7 +74,7 @@ export type UseUploadthingProps< * Called if the upload fails */ onUploadError?: - | ((e: UploadThingError>) => MaybePromise) + | ((e: UploadThingError>) => MaybePromise) | undefined; /** * Set custom headers that'll get sent with requests @@ -94,7 +94,7 @@ export type UploadthingComponentProps< TRouter extends FileRouter, TEndpoint extends keyof TRouter, > = Omit< - UseUploadthingProps, + UseUploadthingProps, /** * Signal is omitted, component has its own AbortController * If you need to control the interruption with more granularity, diff --git a/packages/uploadthing/src/client.ts b/packages/uploadthing/src/client.ts index 5f286306ae..ca7834bf7d 100644 --- a/packages/uploadthing/src/client.ts +++ b/packages/uploadthing/src/client.ts @@ -92,7 +92,7 @@ export const genUploader = ( >( slug: EndpointArg, opts: Omit< - CreateUploadOptions, + CreateUploadOptions, keyof GenerateUploaderOptions >, ) => { @@ -249,7 +249,7 @@ export const genUploader = ( const typedUploadFiles = ( slug: EndpointArg, opts: Omit< - UploadFilesOptions, + UploadFilesOptions, keyof GenerateUploaderOptions >, ) => { diff --git a/packages/uploadthing/src/internal/error-formatter.ts b/packages/uploadthing/src/internal/error-formatter.ts index 91e1913d27..b3aa168a0e 100644 --- a/packages/uploadthing/src/internal/error-formatter.ts +++ b/packages/uploadthing/src/internal/error-formatter.ts @@ -8,13 +8,12 @@ export function defaultErrorFormatter(error: UploadThingError) { }; } -export function formatError( +export function formatError( error: UploadThingError, - router: TRouter, -): inferErrorShape { + router: FileRouter, +): inferErrorShape { const errorFormatter = router[Object.keys(router)[0]]?.errorFormatter ?? defaultErrorFormatter; - // eslint-disable-next-line @typescript-eslint/no-unsafe-return return errorFormatter(error); } diff --git a/packages/uploadthing/src/internal/handler.ts b/packages/uploadthing/src/internal/handler.ts index baedd3ead4..15960b6136 100644 --- a/packages/uploadthing/src/internal/handler.ts +++ b/packages/uploadthing/src/internal/handler.ts @@ -45,7 +45,7 @@ import { UploadThingHook, } from "./shared-schemas"; import { UTFiles } from "./types"; -import type { AnyUploader, MiddlewareFnArgs, UTEvents } from "./types"; +import type { AnyFileRoute, MiddlewareFnArgs, UTEvents } from "./types"; export class MiddlewareArguments extends Context.Tag( "uploadthing/MiddlewareArguments", @@ -228,7 +228,7 @@ export const createRequestHandler = ( ); }).pipe(Effect.withLogSpan("createRequestHandler")); -const handleErrorRequest = (opts: { uploadable: AnyUploader }) => +const handleErrorRequest = (opts: { uploadable: AnyFileRoute }) => Effect.gen(function* () { const { uploadable } = opts; const request = yield* HttpServerRequest.HttpServerRequest; @@ -289,7 +289,7 @@ const handleErrorRequest = (opts: { uploadable: AnyUploader }) => }).pipe(Effect.withLogSpan("handleErrorRequest")); const handleCallbackRequest = (opts: { - uploadable: AnyUploader; + uploadable: AnyFileRoute; fePackage: string; beAdapter: string; }) => @@ -381,7 +381,7 @@ const handleCallbackRequest = (opts: { const runRouteMiddleware = (opts: { json: typeof UploadActionPayload.Type; - uploadable: AnyUploader; + uploadable: AnyFileRoute; }) => Effect.gen(function* () { const middlewareArgs = yield* MiddlewareArguments; @@ -441,7 +441,7 @@ const runRouteMiddleware = (opts: { }).pipe(Effect.withLogSpan("runRouteMiddleware")); const handleUploadAction = (opts: { - uploadable: AnyUploader; + uploadable: AnyFileRoute; fePackage: string; beAdapter: string; slug: string; diff --git a/packages/uploadthing/src/internal/types.ts b/packages/uploadthing/src/internal/types.ts index b337fb3d8a..58f4aa40ed 100644 --- a/packages/uploadthing/src/internal/types.ts +++ b/packages/uploadthing/src/internal/types.ts @@ -141,7 +141,7 @@ export interface UploadBuilder { >, TOutput >, - ) => Uploader<{ + ) => FileRoute<{ input: TParams["_input"]["in"] extends UnsetMarker ? void : TParams["_input"]["in"]; @@ -158,7 +158,7 @@ export type AnyBuiltUploaderTypes = { errorShape: any; }; -export interface Uploader { +export interface FileRoute { $types: TTypes; routerConfig: FileRouterInputConfig; routeOptions: RouteOptions; @@ -168,7 +168,7 @@ export interface Uploader { errorFormatter: (err: UploadThingError) => any; onUploadComplete: UploadCompleteFn; } -export type AnyUploader = Uploader; +export type AnyFileRoute = FileRoute; /** * Map actionType to the required payload for that action diff --git a/packages/uploadthing/src/internal/upload-builder.ts b/packages/uploadthing/src/internal/upload-builder.ts index c775f89b3d..4f490949a2 100644 --- a/packages/uploadthing/src/internal/upload-builder.ts +++ b/packages/uploadthing/src/internal/upload-builder.ts @@ -8,11 +8,10 @@ import type { import { defaultErrorFormatter } from "./error-formatter"; import type { AnyBuiltUploaderTypes, - AnyUploader, + AnyFileRoute, MiddlewareFnArgs, UnsetMarker, UploadBuilder, - Uploader, } from "./types"; function internalCreateBuilder< @@ -20,7 +19,7 @@ function internalCreateBuilder< TRouteOptions extends RouteOptions, TErrorShape extends Json = { message: string }, >( - initDef: Partial = {}, + initDef: Partial = {}, ): UploadBuilder<{ _routeOptions: TRouteOptions; _input: { in: UnsetMarker; out: UnsetMarker }; @@ -30,7 +29,7 @@ function internalCreateBuilder< _errorFn: UnsetMarker; _output: UnsetMarker; }> { - const _def: AnyUploader = { + const _def: AnyFileRoute = { $types: {} as AnyBuiltUploaderTypes, // Default router config routerConfig: { @@ -77,7 +76,7 @@ function internalCreateBuilder< return { ..._def, onUploadComplete: userUploadComplete, - } as Uploader; + } as AnyFileRoute; }, onUploadError(userOnUploadError) { return internalCreateBuilder({ diff --git a/packages/uploadthing/src/internal/upload.browser.ts b/packages/uploadthing/src/internal/upload.browser.ts index 9a19425c4a..1d9d53f083 100644 --- a/packages/uploadthing/src/internal/upload.browser.ts +++ b/packages/uploadthing/src/internal/upload.browser.ts @@ -116,7 +116,7 @@ export const uploadFilesInternal = < TServerOutput = inferEndpointOutput, >( endpoint: TEndpoint, - opts: UploadFilesOptions, + opts: UploadFilesOptions, ): Micro.Micro< ClientUploadedFileData[], UploadThingError | FetchError diff --git a/packages/uploadthing/src/types.ts b/packages/uploadthing/src/types.ts index 13438d282e..d755d2077d 100644 --- a/packages/uploadthing/src/types.ts +++ b/packages/uploadthing/src/types.ts @@ -9,7 +9,7 @@ import type { } from "@uploadthing/shared"; import type { LogFormat } from "./internal/logger"; -import type { AnyUploader } from "./internal/types"; +import type { AnyFileRoute } from "./internal/types"; export * from "./sdk/types"; @@ -26,18 +26,19 @@ export type { NewPresignedUrl, } from "./internal/shared-schemas"; -export type FileRouter = Record; +export type { AnyFileRoute }; +export type FileRouter = Record; -export type inferEndpointInput = - TUploader["$types"]["input"]; +export type inferEndpointInput = + TFileRoute["$types"]["input"]; -export type inferEndpointOutput = - TUploader["$types"]["output"] extends void | undefined +export type inferEndpointOutput = + TFileRoute["$types"]["output"] extends void | undefined ? null - : TUploader["$types"]["output"]; + : TFileRoute["$types"]["output"]; -export type inferErrorShape = - TRouter[keyof TRouter]["$types"]["errorShape"]; +export type inferErrorShape = + TFileRoute["$types"]["errorShape"]; export type RouteHandlerConfig = { logLevel?: LogLevel.Literal; @@ -85,10 +86,7 @@ export type RouteHandlerOptions = { config?: RouteHandlerConfig; }; -export type UploadFilesOptions< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, -> = { +export type UploadFilesOptions = { /** * The files to upload */ @@ -156,14 +154,11 @@ export type UploadFilesOptions< */ package: string; } & ExtendObjectIf< - inferEndpointInput, - { input: inferEndpointInput } + inferEndpointInput, + { input: inferEndpointInput } >; -export type CreateUploadOptions< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, -> = { +export type CreateUploadOptions = { /** * The files to upload */ @@ -193,8 +188,8 @@ export type CreateUploadOptions< */ headers?: HeadersInit | (() => MaybePromise) | undefined; } & ExtendObjectIf< - inferEndpointInput, - { input: inferEndpointInput } + inferEndpointInput, + { input: inferEndpointInput } >; export type GenerateUploaderOptions = { diff --git a/packages/vue/src/components/button.tsx b/packages/vue/src/components/button.tsx index 14666fa84f..b563db26c7 100644 --- a/packages/vue/src/components/button.tsx +++ b/packages/vue/src/components/button.tsx @@ -88,7 +88,7 @@ export const generateUploadButton = ( const uploadProgress = ref(0); const files = ref([]); - const useUploadthingProps: UseUploadthingProps = + const useUploadthingProps: UseUploadthingProps = reactive({ signal: acRef.value.signal, headers: $props.headers, diff --git a/packages/vue/src/components/dropzone.tsx b/packages/vue/src/components/dropzone.tsx index 2fa98623d9..a35ab54f1f 100644 --- a/packages/vue/src/components/dropzone.tsx +++ b/packages/vue/src/components/dropzone.tsx @@ -115,7 +115,7 @@ export const generateUploadDropzone = ( const files = ref([]); const uploadProgress = ref(0); - const useUploadthingProps: UseUploadthingProps = + const useUploadthingProps: UseUploadthingProps = reactive({ signal: acRef.value.signal, headers: $props.headers, diff --git a/packages/vue/src/types.ts b/packages/vue/src/types.ts index 2af9727089..4e490711ce 100644 --- a/packages/vue/src/types.ts +++ b/packages/vue/src/types.ts @@ -6,6 +6,7 @@ import type { UploadThingError, } from "@uploadthing/shared"; import type { + AnyFileRoute, ClientUploadedFileData, EndpointArg, FileRouter, @@ -28,9 +29,8 @@ export interface GenerateTypedHelpersOptions { } export type UseUploadthingProps< - TRouter extends FileRouter, - TEndpoint extends keyof TRouter, - TServerOutput = inferEndpointOutput, + TFileRoute extends AnyFileRoute, + TServerOutput = inferEndpointOutput, > = { /** * Called when the upload is submitted and the server is about to be queried for presigned URLs @@ -74,7 +74,7 @@ export type UseUploadthingProps< * Called if the upload fails */ onUploadError?: - | ((e: UploadThingError>) => MaybePromise) + | ((e: UploadThingError>) => MaybePromise) | undefined; /** * Set custom headers that'll get sent with requests @@ -94,7 +94,7 @@ export type UploadthingComponentProps< TRouter extends FileRouter, TEndpoint extends keyof TRouter, > = Omit< - UseUploadthingProps, + UseUploadthingProps, /** * Signal is omitted, component has its own AbortController * If you need to control the interruption with more granularity, diff --git a/packages/vue/src/useUploadThing.ts b/packages/vue/src/useUploadThing.ts index 949ce66af4..b00c800da3 100644 --- a/packages/vue/src/useUploadThing.ts +++ b/packages/vue/src/useUploadThing.ts @@ -55,7 +55,7 @@ export const INTERNAL_uploadthingHookGen = < const useUploadThing = ( endpoint: EndpointArg, - opts?: UseUploadthingProps, + opts?: UseUploadthingProps, ) => { const isUploading = ref(false); const uploadProgress = ref(0); @@ -110,9 +110,9 @@ export const INTERNAL_uploadthingHookGen = < */ if (e instanceof UploadAbortedError) throw e; - let error: UploadThingError>; + let error: UploadThingError>; if (e instanceof UploadThingError) { - error = e as UploadThingError>; + error = e as UploadThingError>; } else { error = INTERNAL_DO_NOT_USE__fatalClientError(e as Error); console.error(