-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat!: allow re-use of response json * feat!: safer typing * chore: fix imports * chore: remove old type * chore: remove unneeded casts * chore: npm audit fix * chore: fix dependabot error * feat!: actually fix the clone issue this time * chore: fix table-data-client type args BREAKING CHANGE: api client now returns Response instead of BugSplatResponse to allow cloning. BugSplatResponse `json` no longer returns type `any`.
- Loading branch information
Showing
22 changed files
with
248 additions
and
159 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,50 @@ | ||
export function createFakeResponseBody( | ||
status: number, | ||
json: any = {}, | ||
export function createFakeResponseBody<T>( | ||
status = 200, | ||
json = {} as T, | ||
ok = true, | ||
headers: any = [] | ||
) { | ||
return { | ||
headers = new Map() | ||
): FakeResponseBody<T> { | ||
return new FakeResponseBody( | ||
status, | ||
json, | ||
ok, | ||
json: async() => (json), | ||
headers: { get: () => headers } | ||
}; | ||
headers | ||
); | ||
} | ||
|
||
export class FakeResponseBody<T> { | ||
|
||
private _json: T; | ||
private _headers: Map<string, string>; | ||
|
||
get headers(): Map<string, string> { | ||
return this._headers; | ||
} | ||
|
||
constructor( | ||
public readonly status = 200, | ||
json = {} as T, | ||
public readonly ok = true, | ||
headers = new Map() as Map<string,string> | ||
) { | ||
this._json = json; | ||
this._headers = headers; | ||
} | ||
|
||
async json(): Promise<T> { | ||
return this._json; | ||
} | ||
|
||
async text(): Promise<string> { | ||
return JSON.stringify(this._json); | ||
} | ||
|
||
clone(): FakeResponseBody<T> { | ||
return new FakeResponseBody<T>( | ||
this.status, | ||
this._json, | ||
this.ok, | ||
this._headers | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export interface ApiClient { | ||
createFormData(): FormData; | ||
fetch(route: string, init?: RequestInit): Promise<BugSplatResponse>; | ||
fetch<T>(route: string, init?: RequestInit): Promise<BugSplatResponse<T>>; | ||
} | ||
|
||
export interface BugSplatResponse { | ||
export interface BugSplatResponse<T = unknown> { | ||
status: number; | ||
json: () => Promise<any>; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
json: () => Promise<T>; | ||
text: () => Promise<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/common/client/bugsplat-api-client/bugsplat-login-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface BugSplatLoginResponse { | ||
user: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.