Skip to content

Commit

Permalink
@uppy/companion-client: do not allow boolean RequestOptions (#5198)
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi authored and aduh95 committed May 30, 2024
1 parent c3eb589 commit e11493f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
3 changes: 3 additions & 0 deletions docs/guides/migration-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ These cover all the major Uppy versions and how to migrate to them.
class you don’t need to do anything.
- Remove deprecated options `serverUrl` and `serverPattern` (they were merely
defined in Typescript, not in use).
- `RequestClient` methods `get`, `post`, `delete` no longer accepts a boolean as
the third argument. Instead, pass `{ skipPostResponse: true | false }`. This
won’t affect you unless you’ve been using `RequestClient`.

## Migrate from Robodog to Uppy plugins

Expand Down
19 changes: 3 additions & 16 deletions packages/@uppy/companion-client/src/RequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export type Opts = {
companionKeysParams?: Record<string, string>
}

type _RequestOptions =
| boolean // TODO: remove this on the next major
| RequestOptions

// Remove the trailing slash so we can always safely append /xyz.
function stripSlash(url: string) {
return url.replace(/\/$/, '')
Expand Down Expand Up @@ -195,33 +191,24 @@ export default class RequestClient<M extends Meta, B extends Body> {

async get<PostBody>(
path: string,
options?: _RequestOptions,
options?: RequestOptions,
): Promise<PostBody> {
// TODO: remove boolean support for options that was added for backward compatibility.
// eslint-disable-next-line no-param-reassign
if (typeof options === 'boolean') options = { skipPostResponse: options }
return this.request({ ...options, path })
}

async post<PostBody>(
path: string,
data: Record<string, unknown>,
options?: _RequestOptions,
options?: RequestOptions,
): Promise<PostBody> {
// TODO: remove boolean support for options that was added for backward compatibility.
// eslint-disable-next-line no-param-reassign
if (typeof options === 'boolean') options = { skipPostResponse: options }
return this.request<PostBody>({ ...options, path, method: 'POST', data })
}

async delete<T>(
path: string,
data?: Record<string, unknown>,
options?: _RequestOptions,
options?: RequestOptions,
): Promise<T> {
// TODO: remove boolean support for options that was added for backward compatibility.
// eslint-disable-next-line no-param-reassign
if (typeof options === 'boolean') options = { skipPostResponse: options }
return this.request({ ...options, path, method: 'DELETE', data })
}

Expand Down

0 comments on commit e11493f

Please sign in to comment.