Skip to content

Commit

Permalink
chore: make initOpts optional (#1150)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Feb 13, 2025
1 parent 511dc21 commit f9c0259
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-boxes-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"uploadthing": patch
---

chore: make `genUploader(initOpts)` optional to match docs
14 changes: 7 additions & 7 deletions packages/uploadthing/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const isValidFileSize = (
* @public
*/
export const genUploader = <TRouter extends FileRouter>(
initOpts: GenerateUploaderOptions,
initOpts?: GenerateUploaderOptions,
) => {
const routeRegistry = createIdentityProxy<RouteRegistry<TRouter>>();

Expand All @@ -108,11 +108,11 @@ export const genUploader = <TRouter extends FileRouter>(

const utReporter = createUTReporter({
endpoint: String(endpoint),
package: initOpts.package,
url: resolveMaybeUrlArg(initOpts.url),
package: initOpts?.package ?? "uploadthing/client",
url: resolveMaybeUrlArg(initOpts?.url),
headers: opts.headers,
});
const fetchFn: FetchEsque = initOpts.fetch ?? window.fetch;
const fetchFn: FetchEsque = initOpts?.fetch ?? window.fetch;

const presigneds = await Micro.runPromise(
utReporter("upload", {
Expand Down Expand Up @@ -256,13 +256,13 @@ export const genUploader = <TRouter extends FileRouter>(
>,
) => {
const endpoint = typeof slug === "function" ? slug(routeRegistry) : slug;
const fetchFn: FetchEsque = initOpts.fetch ?? window.fetch;
const fetchFn: FetchEsque = initOpts?.fetch ?? window.fetch;

return uploadFilesInternal<TRouter, TEndpoint>(endpoint, {
...opts,
skipPolling: {} as never, // Remove in a future version, it's type right not is an ErrorMessage<T> to help migrations.
url: resolveMaybeUrlArg(initOpts.url),
package: initOpts.package,
url: resolveMaybeUrlArg(initOpts?.url),
package: initOpts?.package ?? "uploadthing/client",
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
input: (opts as any).input as inferEndpointInput<TRouter[TEndpoint]>,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/uploadthing/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export type GenerateUploaderOptions = {
*
* This is used to identify the client in the server logs
*/
package: string;
package?: string;
};

export type EndpointArg<
Expand Down

0 comments on commit f9c0259

Please sign in to comment.