hook-fetch 2.0.7 → 2.1.0

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/README.en.md CHANGED
@@ -264,7 +264,7 @@ interface BaseResponseVO {
264
264
  message: string;
265
265
  }
266
266
 
267
- const request = hookFetch.create<BaseResponseVO>({
267
+ const request = hookFetch.create<BaseResponseVO, 'data'>({
268
268
  baseURL: 'https://example.com',
269
269
  headers: {
270
270
  'Content-Type': 'application/json',
package/README.md CHANGED
@@ -375,7 +375,7 @@ interface BaseResponseVO {
375
375
  message: string;
376
376
  }
377
377
 
378
- const request = hookFetch.create<BaseResponseVO>({
378
+ const request = hookFetch.create<BaseResponseVO, 'data'>({
379
379
  baseURL: 'https://example.com',
380
380
  headers: {
381
381
  'Content-Type': 'application/json',
@@ -392,7 +392,7 @@ interface User {
392
392
 
393
393
  // 在请求中使用类型
394
394
  const res = await request.get<User>('/users/1').json();
395
- console.log(res.data); // TypeScript提供完整类型提示
395
+ console.log(res.data); // TypeScript 提供完整类型提示
396
396
  ```
397
397
 
398
398
  ## 完整API
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "hook-fetch-plugin-response-transform",
19
19
  "hook-fetch-plugin-request-transform"
20
20
  ],
21
- "version": "2.0.7",
21
+ "version": "2.1.0",
22
22
  "scripts": {
23
23
  "dev": "vite",
24
24
  "build:rolldown": "rolldown -c ./rolldown.config.ts",
@@ -23,7 +23,8 @@ declare class HookFetchRequest<T, E> implements PromiseLike<T> {
23
23
  }
24
24
  //#endregion
25
25
  //#region src/base.d.ts
26
- declare class HookFetch<R extends AnyObject = AnyObject, K extends keyof R = 'data', E = AnyObject> {
26
+ type GenericWithNull<T, R extends AnyObject | null, K extends keyof R> = R extends null ? T : Generic<Exclude<R, null>, K, T>;
27
+ declare class HookFetch<R extends AnyObject | null = null, K extends keyof R = never, E = AnyObject> {
27
28
  #private;
28
29
  constructor({
29
30
  timeout,
@@ -42,15 +43,15 @@ declare class HookFetch<R extends AnyObject = AnyObject, K extends keyof R = 'da
42
43
  qsArrayFormat,
43
44
  withCredentials,
44
45
  extra
45
- }?: RequestOptions<P, D, E>): HookFetchRequest<Generic<R, K, T>, E>;
46
- get<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: GetOptions<P, E>): HookFetchRequest<Generic<R, K, T>, E>;
47
- head<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: HeadOptions<P, E>): HookFetchRequest<Generic<R, K, T>, E>;
48
- options<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, params?: P, options?: OptionsOptions<P, D, E>): HookFetchRequest<Generic<R, K, T>, E>;
49
- delete<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, options?: DeleteOptions<P, D, E>): HookFetchRequest<Generic<R, K, T>, E>;
50
- post<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
51
- upload<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
52
- put<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
53
- patch<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
46
+ }?: RequestOptions<P, D, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
47
+ get<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: GetOptions<P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
48
+ head<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: HeadOptions<P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
49
+ options<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, params?: P, options?: OptionsOptions<P, D, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
50
+ delete<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, options?: DeleteOptions<P, D, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
51
+ post<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
52
+ upload<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
53
+ put<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
54
+ patch<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
54
55
  abortAll(): void;
55
56
  }
56
57
  declare const useRequest: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, options?: RequestOptions<P, D, E>) => HookFetchRequest<R, E>;
@@ -64,7 +65,7 @@ declare const upload: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObjec
64
65
  declare const put: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>) => HookFetchRequest<R, E>;
65
66
  declare const patch: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>) => HookFetchRequest<R, E>;
66
67
  type ExportDefault = typeof useRequest & {
67
- create: <R extends AnyObject = AnyObject, K extends keyof R = 'data', E = AnyObject>(options: BaseOptions) => (HookFetch<R, K, E>['request'] & HookFetch<R, K, E>);
68
+ create: <R extends AnyObject | null = null, K extends keyof R = never, E = AnyObject>(options: BaseOptions) => (HookFetch<R, K, E>['request'] & HookFetch<R, K, E>);
68
69
  get: typeof get;
69
70
  head: typeof head;
70
71
  options: typeof options;
package/types/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { AfterResponseHandler, BaseOptions, BaseRequestOptions, BeforeRequestHandler, BeforeStreamHandler, DeleteOptions, FetchPluginContext, FetchResponseType, GetOptions, HeadOptions, HookFetchPlugin, OnErrorHandler, OnFinallyHandler, OptionProps, OptionsOptions, PatchOptions, PostOptions, PutOptions, RequestConfig, RequestMethod, RequestMethodWithBody, RequestMethodWithParams, RequestOptions, RequestUseOptions, RequestWithBodyFnOptions, RequestWithBodyOptions, RequestWithParamsFnOptions, RequestWithParamsOptions, ResponseError, ResponseErrorOptions, StreamContext, TransformStreamChunkHandler } from "./types-CAGBd7wv.js";
2
- import { ContentType, Method, StatusCode, del, get, head, hookFetch, options, patch, post, put, request, upload } from "./index-9UX4E7wG.js";
2
+ import { ContentType, Method, StatusCode, del, get, head, hookFetch, options, patch, post, put, request, upload } from "./index-n7kSnbyZ.js";
3
3
  export { AfterResponseHandler, BaseOptions, BaseRequestOptions, BeforeRequestHandler, BeforeStreamHandler, ContentType, DeleteOptions, FetchPluginContext, FetchResponseType, GetOptions, HeadOptions, HookFetchPlugin, Method, OnErrorHandler, OnFinallyHandler, OptionProps, OptionsOptions, PatchOptions, PostOptions, PutOptions, RequestConfig, RequestMethod, RequestMethodWithBody, RequestMethodWithParams, RequestOptions, RequestUseOptions, RequestWithBodyFnOptions, RequestWithBodyOptions, RequestWithParamsFnOptions, RequestWithParamsOptions, ResponseError, ResponseErrorOptions, StatusCode, StreamContext, TransformStreamChunkHandler, hookFetch as default, del, get, head, options, patch, post, put, request, upload };
@@ -1,5 +1,5 @@
1
1
  import { ResponseError, StreamContext } from "../types-CAGBd7wv.js";
2
- import { HookFetchRequest } from "../index-9UX4E7wG.js";
2
+ import { HookFetchRequest } from "../index-n7kSnbyZ.js";
3
3
  import * as react0 from "react";
4
4
 
5
5
  //#region src/react/index.d.ts
@@ -1,5 +1,5 @@
1
1
  import { ResponseError, StreamContext } from "../types-CAGBd7wv.js";
2
- import { HookFetchRequest } from "../index-9UX4E7wG.js";
2
+ import { HookFetchRequest } from "../index-n7kSnbyZ.js";
3
3
  import * as vue0 from "vue";
4
4
 
5
5
  //#region src/vue/index.d.ts