hook-fetch 2.0.5 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/types.d.ts DELETED
@@ -1,92 +0,0 @@
1
- import { default as QueryString } from 'qs';
2
- import { AnyObject } from 'typescript-api-pro';
3
- import { ResponseError } from './utils';
4
- export type FetchResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData' | 'bytes';
5
- export type RequestMethodWithParams = 'GET' | 'HEAD';
6
- export type RequestMethodWithBody = 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS';
7
- export type RequestMethod = RequestMethodWithParams | RequestMethodWithBody;
8
- export interface RequestConfig<P, D, E = AnyObject> extends Omit<RequestInit, 'body' | 'signal' | 'credentials' | 'method'> {
9
- url: string;
10
- baseURL: string;
11
- params?: P;
12
- data?: D;
13
- withCredentials?: boolean;
14
- extra?: E;
15
- method: RequestMethod;
16
- qsArrayFormat?: QueryString.IStringifyOptions['arrayFormat'];
17
- }
18
- export type BaseRequestOptions<P, D, E = AnyObject> = Partial<{
19
- plugins: Array<HookFetchPlugin>;
20
- timeout: number;
21
- params: P;
22
- data: D;
23
- controller: AbortController;
24
- extra: E;
25
- qsArrayFormat: QueryString.IStringifyOptions['arrayFormat'];
26
- withCredentials: boolean;
27
- method: RequestMethod;
28
- }> & Omit<RequestInit, 'body' | 'method'> & {
29
- url: string;
30
- baseURL: string;
31
- };
32
- export interface FetchPluginContext<T = unknown, E = unknown, P = unknown, D = unknown> {
33
- config: RequestConfig<P, D, E>;
34
- response: Response;
35
- responseType: FetchResponseType;
36
- result?: T;
37
- controller: AbortController;
38
- }
39
- export interface StreamContext<T = unknown> {
40
- result: T;
41
- source: Uint8Array<ArrayBufferLike>;
42
- error: unknown | null;
43
- }
44
- type BeforeRequestHandler<E = unknown, P = unknown, D = unknown> = (config: RequestConfig<P, D, E>) => RequestConfig<P, D, E> | Promise<RequestConfig<P, D, E>>;
45
- type AfterResponseHandler<T = unknown, E = unknown, P = unknown, D = unknown> = (context: FetchPluginContext<T>, config: RequestConfig<P, D, E>) => FetchPluginContext<T> | Promise<FetchPluginContext<T>>;
46
- type BeforeStreamHandler<E = unknown, P = unknown, D = unknown> = (body: ReadableStream<any>, config: RequestConfig<P, D, E>) => ReadableStream<any> | Promise<ReadableStream<any>>;
47
- type TransformStreamChunkHandler<E = unknown, P = unknown, D = unknown> = (chunk: StreamContext<any>, config: RequestConfig<P, D, E>) => StreamContext | Promise<StreamContext>;
48
- export type OnFinallyHandler<E = unknown, P = unknown, D = unknown> = (res: Pick<FetchPluginContext<unknown, E, P, D>, 'config' | 'response'>) => void | Promise<void>;
49
- export type HookFetchPlugin<T = unknown, E = unknown, P = unknown, D = unknown> = {
50
- /** 插件名称 */
51
- name: string;
52
- /** 优先级 */
53
- priority?: number;
54
- beforeRequest?: BeforeRequestHandler<E, P, D>;
55
- afterResponse?: AfterResponseHandler<T, E, P, D>;
56
- beforeStream?: BeforeStreamHandler<E, P, D>;
57
- transformStreamChunk?: TransformStreamChunkHandler<E, P, D>;
58
- onError?: (error: ResponseError, config: RequestConfig<P, D, E>) => Promise<Error | void | ResponseError<E>>;
59
- onFinally?: OnFinallyHandler<E, P, D>;
60
- };
61
- export interface OptionProps {
62
- baseURL: string;
63
- timeout: number;
64
- headers: HeadersInit;
65
- plugins: Array<HookFetchPlugin<any, any, any, any>>;
66
- withCredentials: boolean;
67
- }
68
- export type BaseOptions = Partial<OptionProps>;
69
- export type RequestOptions<P = AnyObject, D = AnyObject, E = AnyObject> = Omit<BaseRequestOptions<P, D, E>, 'url' | 'plugins' | 'baseURL' | 'controller'>;
70
- /**
71
- * 已废除, 请改用 RequestOptions
72
- *
73
- * Deprecated, please use RequestOptions instead
74
- */
75
- export type RequestUseOptions<P = AnyObject, D = AnyObject, E = AnyObject> = RequestOptions<P, D, E>;
76
- export type RequestWithBodyOptions<D = AnyObject, P = AnyObject, E = AnyObject> = Omit<RequestOptions<P, D, E>, 'data'>;
77
- export type RequestWithParamsOptions<P = AnyObject, E = AnyObject> = Omit<RequestOptions<P, null, E>, 'params' | 'data'>;
78
- export type RequestWithBodyFnOptions<D = AnyObject, P = AnyObject, E = AnyObject> = Omit<RequestOptions<P, D, E>, 'data' | 'method'>;
79
- export type RequestWithParamsFnOptions<P = AnyObject, E = AnyObject> = Omit<RequestOptions<P, null, E>, 'params' | 'data' | 'method'>;
80
- export type PostOptions<D = AnyObject, P = AnyObject, E = AnyObject> = RequestWithBodyFnOptions<D, P, E>;
81
- export type PutOptions<D = AnyObject, P = AnyObject, E = AnyObject> = RequestWithBodyFnOptions<D, P, E>;
82
- export type PatchOptions<D = AnyObject, P = AnyObject, E = AnyObject> = RequestWithBodyFnOptions<D, P, E>;
83
- export type GetOptions<P = AnyObject, E = AnyObject> = RequestWithParamsFnOptions<P, E>;
84
- export type HeadOptions<P = AnyObject, E = AnyObject> = RequestWithParamsFnOptions<P, E>;
85
- /**
86
- * OPTIONS 方法请求的可选参数类型
87
- *
88
- * OPTIONS method request optional parameter types
89
- */
90
- export type OptionsOptions<P = AnyObject, D = AnyObject, E = AnyObject> = RequestUseOptions<P, D, E>;
91
- export type DeleteOptions<P = AnyObject, D = AnyObject, E = AnyObject> = RequestUseOptions<P, D, E>;
92
- export {};
package/types/umd.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { default as hookFetch } from './base';
2
- export * from './base';
3
- export * from './enum';
4
- export * from './types';
5
- export * from './error';
6
- export * from './plugins';
7
- export default hookFetch;
package/types/utils.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import { default as QueryString } from 'qs';
2
- import { AnyObject } from 'typescript-api-pro';
3
- import { ResponseErrorOptions } from './error';
4
- import { BaseRequestOptions, RequestConfig, RequestMethod, StreamContext } from './types';
5
- export declare const delay: (ms: number) => Promise<unknown>;
6
- export declare const timeoutCallback: (controller: AbortController) => void;
7
- export declare class ResponseError<E = unknown> extends Error {
8
- #private;
9
- constructor({ message, status, statusText, response, config, name }: ResponseErrorOptions<E>);
10
- get message(): string;
11
- get status(): number | undefined;
12
- get statusText(): string | undefined;
13
- get response(): Response | undefined;
14
- get config(): RequestConfig<unknown, unknown, E> | undefined;
15
- get name(): string;
16
- }
17
- export declare const buildUrl: (url: string, params?: AnyObject, qsArrayFormat?: QueryString.IStringifyOptions["arrayFormat"]) => string;
18
- export declare const mergeHeaders: (_baseHeaders?: HeadersInit | Headers, _newHeaders?: HeadersInit | Headers) => Headers;
19
- export declare const getBody: (body: AnyObject, method: RequestMethod, headers?: HeadersInit, qsArrayFormat?: QueryString.IStringifyOptions["arrayFormat"]) => BodyInit | null;
20
- export declare class HookFetchRequest<T, E> implements PromiseLike<T> {
21
- #private;
22
- constructor(options: BaseRequestOptions<unknown, unknown, E>);
23
- json(): Promise<any>;
24
- then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
25
- catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
26
- finally(onfinally?: (() => void) | null | undefined): void;
27
- abort(): void;
28
- blob(): Promise<any>;
29
- text(): Promise<any>;
30
- arrayBuffer(): Promise<any>;
31
- formData(): Promise<any>;
32
- bytes(): Promise<any>;
33
- stream<T>(): AsyncGenerator<StreamContext<T> | StreamContext<null>, ResponseError<unknown> | undefined, unknown>;
34
- retry(): HookFetchRequest<unknown, E>;
35
- get response(): Promise<Response>;
36
- }
37
- export declare const isGenerator: (v: any) => boolean;
38
- export declare const isAsyncGenerator: (v: any) => boolean;
File without changes