-
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!: remove HttpBody and Response classes
BREAKING CHANGE: removed HttpBody and Response. Now using the simpler DzResponse. Clients must implement the methods to consume and parse response data.
- Loading branch information
1 parent
81310de
commit 257f6f1
Showing
17 changed files
with
240 additions
and
586 deletions.
There are no files selected for viewing
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,54 @@ | ||
import { DzHeaders } from './http.headers' | ||
import { BodyType } from './types' | ||
|
||
interface DzResponseInit<R> { | ||
original: R | ||
headers: DzHeaders | ||
body: BodyType | ||
status: number | ||
url: string | ||
} | ||
|
||
export abstract class DzResponse<R = unknown, BLOB = unknown, FORM_DATA = unknown> { | ||
private readonly _original: R | ||
private readonly _body: BodyType | ||
readonly headers: DzHeaders | ||
readonly status: number | ||
readonly url: string | ||
|
||
protected constructor(init: DzResponseInit<R>) { | ||
this._original = init.original | ||
this._body = init.body | ||
this.headers = init.headers | ||
this.status = init.status | ||
this.url = init.url | ||
} | ||
|
||
get ok(): boolean { | ||
return DzResponse.isOK(this.status) | ||
} | ||
|
||
original(): R { | ||
return this._original | ||
} | ||
|
||
get body(): BodyType { | ||
return this._body | ||
} | ||
|
||
abstract get bodyUsed(): boolean | ||
|
||
abstract arrayBuffer(): Promise<ArrayBuffer> | ||
|
||
abstract json<T>(): Promise<T> | ||
|
||
abstract text(): Promise<string> | ||
|
||
abstract blob(): Promise<BLOB> | ||
|
||
abstract formData(): Promise<FORM_DATA> | ||
|
||
static isOK(statusCode: number): boolean { | ||
return statusCode >= 200 && statusCode <= 299 | ||
} | ||
} |
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
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
Oops, something went wrong.