generated from un-ts/lib-boilerplate
-
-
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: add extractDataFromResponse util for better data from response
- Loading branch information
Showing
4 changed files
with
156 additions
and
71 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"license": "MIT", | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=14.0.0" | ||
}, | ||
"main": "./lib/index.cjs", | ||
"module": "./lib/index.js", | ||
|
@@ -24,7 +24,7 @@ | |
"!**/*.tsbuildinfo" | ||
], | ||
"scripts": { | ||
"build": "yarn test && concurrently 'yarn:build:*'", | ||
"build": "yarn test && concurrently -r 'yarn:build:*'", | ||
"build:r": "r -f cjs", | ||
"build:tsc": "tsc -p src", | ||
"dev": "vitest", | ||
|
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,65 @@ | ||
export type Nullable<T> = T | null | undefined | ||
export type Nil = null | undefined | void | ||
|
||
export type Nilable<T> = Nil | T | ||
|
||
export type Readonlyable<T> = Readonly<T> | T | ||
|
||
export type AnyArray<T = unknown> = Readonlyable<T[]> | ||
|
||
export type Arrayable<T, R extends boolean = false> = [R] extends [never] | ||
? T | T[] | ||
: R extends true | ||
? Readonly<T> | readonly T[] | ||
: R extends false | ||
? AnyArray<T> | Readonlyable<T> | ||
: never | ||
|
||
export type ValueOf<T> = T[keyof T] | ||
|
||
export type URLSearchParametersInit = ConstructorParameters< | ||
export type URLSearchParamsInit = ConstructorParameters< | ||
typeof URLSearchParams | ||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
>[0] | ||
|
||
export type URLSearchParametersOptions = | ||
| Record<string, Nullable<number | string>> | ||
| URLSearchParametersInit | ||
export type URLSearchParamsOptions = | ||
| Record<string, Nilable<Arrayable<number | string>>> | ||
| URLSearchParamsInit | ||
| object | ||
|
||
export const ApiMethod = { | ||
GET: 'GET', | ||
POST: 'POST', | ||
PATCH: 'PATCH', | ||
PUT: 'PUT', | ||
DELETE: 'DELETE', | ||
} as const | ||
|
||
export type ApiMethod = ValueOf<typeof ApiMethod> | ||
|
||
export interface FetchApiBaseOptions | ||
extends Omit<RequestInit, 'body' | 'method'> { | ||
method?: ApiMethod | ||
body?: BodyInit | object | ||
query?: URLSearchParamsOptions | ||
json?: boolean | ||
} | ||
|
||
export type ResponseType = 'arrayBuffer' | 'blob' | 'json' | 'text' | null | ||
|
||
export interface FetchApiOptions extends FetchApiBaseOptions { | ||
type?: ResponseType | ||
} | ||
|
||
export interface InterceptorRequest extends FetchApiOptions { | ||
url: string | ||
} | ||
|
||
export type ApiInterceptor = ( | ||
request: InterceptorRequest, | ||
next: (request: InterceptorRequest) => PromiseLike<Response>, | ||
) => PromiseLike<Response> | Response | ||
|
||
export interface ResponseError<T = never> extends Error { | ||
data?: T | null | ||
response?: Response | null | ||
} |
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