hook-fetch 0.0.2-beta → 0.0.2

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/package.json CHANGED
@@ -1,7 +1,24 @@
1
1
  {
2
2
  "name": "hook-fetch",
3
3
  "description": "A lightweight and modern HTTP request library developed based on the native Fetch API of the browser, providing a user-friendly interface similar to Axios and powerful extensibility.",
4
- "version": "0.0.2-beta",
4
+ "keywords": [
5
+ "fetch",
6
+ "axios",
7
+ "request",
8
+ "http",
9
+ "https",
10
+ "typescript",
11
+ "hook-fetch",
12
+ "hook-fetch-plugin",
13
+ "hook-fetch-plugin-retry",
14
+ "hook-fetch-plugin-timeout",
15
+ "hook-fetch-plugin-error",
16
+ "hook-fetch-plugin-response",
17
+ "hook-fetch-plugin-request",
18
+ "hook-fetch-plugin-response-transform",
19
+ "hook-fetch-plugin-request-transform"
20
+ ],
21
+ "version": "0.0.2",
5
22
  "type": "module",
6
23
  "files": [
7
24
  "dist",
@@ -16,13 +33,18 @@
16
33
  "types": "./types/index.d.ts",
17
34
  "exports": {
18
35
  ".": {
19
- "require": "./cjs/index.js",
20
- "import": "./es/index.js",
21
- "types": "./es/index.d.ts"
36
+ "require": "./dist/cjs/index.js",
37
+ "import": "./dist/es/index.js",
38
+ "types": "./types/index.d.ts"
22
39
  },
23
40
  "./plugins": {
24
- "require": "./cjs/plugins/index.js",
25
- "import": "./es/plugins/index.js",
41
+ "require": "./dist/cjs/plugins/index.js",
42
+ "import": "./dist/es/plugins/index.js",
43
+ "types": "./types/plugins/index.d.ts"
44
+ },
45
+ "./src": {
46
+ "require": "./src/index.ts",
47
+ "import": "./src/index.ts",
26
48
  "types": "./types/plugins/index.d.ts"
27
49
  }
28
50
  },
@@ -39,20 +61,32 @@
39
61
  "dev": "vite",
40
62
  "build": "tsc && vite build",
41
63
  "ci:publish": "pnpm changeset publish -r",
42
- "test": "vitest"
64
+ "test": "vitest",
65
+ "lint-staged": "lint-staged"
43
66
  },
44
67
  "devDependencies": {
68
+ "@commitlint/cli": "^19.5.0",
69
+ "@commitlint/config-conventional": "^19.5.0",
70
+ "husky": "^9.1.7",
71
+ "cz-git": "^1.11.1",
72
+ "lint-staged": "^13.2.0",
45
73
  "@changesets/cli": "^2.28.1",
46
74
  "@types/qs": "^6.9.18",
47
75
  "terser": "^5.39.0",
48
76
  "typescript": "^5.7.3",
49
77
  "typescript-api-pro": "workspace:^",
50
78
  "vite": "^6.1.1",
79
+ "oxlint": "^0.16.3",
51
80
  "vite-plugin-dts": "^4.5.3",
52
81
  "vitest": "^3.0.8"
53
82
  },
54
83
  "dependencies": {
55
84
  "qs": "^6.14.0",
56
85
  "radash": "^12.1.0"
86
+ },
87
+ "config": {
88
+ "commitizen": {
89
+ "path": "node_modules/cz-git"
90
+ }
57
91
  }
58
92
  }
package/types/index.d.ts CHANGED
@@ -1,23 +1,41 @@
1
1
  import { AnyObject } from 'typescript-api-pro';
2
2
  import { BaseOptions, HookFetchPlugin, RequestUseOptions } from './types';
3
3
  import { HookFetch } from './utils';
4
- declare class Base {
4
+ type Generic<R extends AnyObject, K extends keyof R, T> = R & {
5
+ [P in K]: T;
6
+ };
7
+ declare class Base<R extends AnyObject = AnyObject, E = AnyObject, K extends keyof R = string> {
5
8
  #private;
6
9
  constructor({ timeout, baseURL, headers, plugins, withCredentials }: BaseOptions);
7
10
  use(plugin: HookFetchPlugin<any, any, any, any>): this;
8
- request<R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, { timeout, headers, method, params, data, qsArrayFormat, withCredentials, extra }?: RequestUseOptions<P, D, E>): HookFetch<R, E>;
9
- get<R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, 'params'>): HookFetch<R, E>;
10
- head<R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, 'params'>): HookFetch<R, E>;
11
- options<R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, 'params'>): HookFetch<R, E>;
12
- delete<R = AnyObject, P = AnyObject, E = AnyObject>(url: string, options?: RequestUseOptions<P, never, E>): HookFetch<R, E>;
13
- post<R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, 'data'>): HookFetch<R, E>;
14
- put<R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, 'data'>): HookFetch<R, E>;
15
- patch<R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, 'data'>): HookFetch<R, E>;
11
+ request<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, { timeout, headers, method, params, data, qsArrayFormat, withCredentials, extra }?: RequestUseOptions<P, D, E>): HookFetch<Generic<R, K, T>, E>;
12
+ get<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, 'params' | 'method'>): HookFetch<Generic<R, K, T>, E>;
13
+ head<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, 'params' | 'method'>): HookFetch<Generic<R, K, T>, E>;
14
+ options<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, 'params' | 'method'>): HookFetch<Generic<R, K, T>, E>;
15
+ delete<T = AnyObject, P = AnyObject>(url: string, options?: Omit<RequestUseOptions<P, never, E>, 'method'>): HookFetch<Generic<R, K, T>, E>;
16
+ post<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, 'data' | 'method'>): HookFetch<Generic<R, K, T>, E>;
17
+ put<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, 'data' | 'method'>): HookFetch<Generic<R, K, T>, E>;
18
+ patch<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, 'data' | 'method'>): HookFetch<Generic<R, K, T>, E>;
16
19
  abortAll(): void;
17
20
  }
18
21
  declare const useRequest: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, options?: RequestUseOptions<P, D, E>) => HookFetch<R, E>;
22
+ export declare const request: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, options?: RequestUseOptions<P, D, E>) => HookFetch<R, E>;
23
+ export declare const get: <R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, "params" | "method">) => HookFetch<R, E>;
24
+ export declare const head: <R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, "params" | "method">) => HookFetch<R, E>;
25
+ export declare const options: <R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: Omit<RequestUseOptions<P, never, E>, "params" | "method">) => HookFetch<R, E>;
26
+ export declare const del: <R = AnyObject, P = AnyObject, E = AnyObject>(url: string, options?: Omit<RequestUseOptions<P, never, E>, "method">) => HookFetch<R, E>;
27
+ export declare const post: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, "data" | "method">) => HookFetch<R, E>;
28
+ export declare const put: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, "data" | "method">) => HookFetch<R, E>;
29
+ export declare const patch: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: Omit<RequestUseOptions<P, D, E>, "data" | "method">) => HookFetch<R, E>;
19
30
  type ExportDefault = typeof useRequest & {
20
- create: (options: BaseOptions) => Base;
31
+ create: <R extends AnyObject = AnyObject, E = AnyObject, K extends keyof R = string>(options: BaseOptions) => (Base<R, E, K>['request'] & Base<R, E, K>);
32
+ get: typeof get;
33
+ head: typeof head;
34
+ options: typeof options;
35
+ delete: typeof del;
36
+ post: typeof post;
37
+ put: typeof put;
38
+ patch: typeof patch;
21
39
  };
22
- declare const _default: ExportDefault;
23
- export default _default;
40
+ declare const defaultFn: ExportDefault;
41
+ export default defaultFn;
package/types/types.d.ts CHANGED
@@ -11,9 +11,11 @@ export interface RequestConfig<P, D, E = AnyObject> extends Omit<RequestInit, 'b
11
11
  method: RequestMethod;
12
12
  qsArrayFormat?: QueryString.IStringifyOptions['arrayFormat'];
13
13
  }
14
+ export type FetchResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData' | 'bytes';
14
15
  export interface FetchPluginContext<T = unknown, E = unknown, P = unknown, D = unknown> {
15
16
  config: RequestConfig<P, D, E>;
16
17
  response: Response;
18
+ responseType: FetchResponseType;
17
19
  result?: T;
18
20
  controller: AbortController;
19
21
  }
package/types/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { default as QueryString } from 'qs';
2
2
  import { AnyObject } from 'typescript-api-pro';
3
- import { HookFetchPlugin, BaseRequestOptions, OnFinallyHandler, RequestConfig, RequestMethod, ResponseErrorOptions, StreamContext } from './types';
3
+ import { HookFetchPlugin, BaseRequestOptions, FetchPluginContext, RequestConfig, RequestMethod, ResponseErrorOptions, StreamContext } from './types';
4
4
  export declare const delay: (ms: number) => Promise<unknown>;
5
5
  export declare const timeoutCallback: (controller: AbortController) => void;
6
6
  export declare class ResponseError<E = unknown> extends Error {
@@ -15,9 +15,9 @@ export declare class ResponseError<E = unknown> extends Error {
15
15
  }
16
16
  export declare const parsePlugins: (plugins: HookFetchPlugin[]) => {
17
17
  beforeRequestPlugins: ((config: RequestConfig<unknown, unknown, unknown>) => Promise<RequestConfig<unknown, unknown, unknown>>)[];
18
- afterResponsePlugins: ((context: import('./types').FetchPluginContext<unknown, unknown, unknown, unknown>) => Promise<import('./types').FetchPluginContext<any>>)[];
18
+ afterResponsePlugins: ((context: FetchPluginContext<unknown, unknown, unknown, unknown>) => Promise<FetchPluginContext<any>>)[];
19
19
  errorPlugins: ((error: Error) => Promise<void | Error | ResponseError<unknown>>)[];
20
- finallyPlugins: OnFinallyHandler<unknown, unknown, unknown>[];
20
+ finallyPlugins: import('./types').OnFinallyHandler<unknown, unknown, unknown>[];
21
21
  transformStreamChunkPlugins: ((chunk: StreamContext<any>) => Promise<StreamContext>)[];
22
22
  };
23
23
  export declare const buildUrl: (url: string, params?: AnyObject, qsArrayFormat?: QueryString.IStringifyOptions["arrayFormat"]) => string;
@@ -26,14 +26,17 @@ export declare const getBody: (body: AnyObject, method: RequestMethod, headers?:
26
26
  export declare class HookFetch<T, E> implements PromiseLike<T> {
27
27
  #private;
28
28
  constructor(options: BaseRequestOptions<unknown, unknown, E>);
29
- then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
29
+ lazyFinally(onfinally?: (() => void) | null | undefined): Promise<T> | null;
30
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
30
31
  catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
31
32
  finally(onfinally?: (() => void) | null | undefined): Promise<T>;
32
33
  abort(): void;
33
- blob(): Promise<Blob>;
34
- text(): Promise<string>;
35
- arrayBuffer(): Promise<ArrayBuffer>;
36
- formData(): Promise<FormData>;
37
- bytes(): Promise<Uint8Array<ArrayBufferLike>>;
34
+ blob(): Promise<any>;
35
+ text(): Promise<any>;
36
+ arrayBuffer(): Promise<any>;
37
+ formData(): Promise<any>;
38
+ bytes(): Promise<any>;
38
39
  stream<T>(): AsyncGenerator<StreamContext<T> | StreamContext<null>, void, unknown>;
40
+ retry(): HookFetch<unknown, E>;
41
+ get response(): Promise<Response>;
39
42
  }