react-toolkits 2.32.8 → 2.32.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.32.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 19be7a6: refactor: update mergeHooks function to improve hook execution order
8
+
9
+ ## 2.32.9
10
+
11
+ ### Patch Changes
12
+
13
+ - 13ae33d: refactor: remove useKy.ts and update imports across components
14
+
3
15
  ## 2.32.8
4
16
 
5
17
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ButtonProps, SelectProps, FormInstance, DrawerProps, Button, FormProps, ModalProps } from 'antd';
2
2
  import { FC, PropsWithChildren, Key, ReactNode, ReactElement, CSSProperties, Ref, DetailedHTMLProps, ImgHTMLAttributes, ComponentProps } from 'react';
3
- import { Hooks, Options, KyInstance } from 'ky';
3
+ import { Options, KyInstance, Hooks } from 'ky';
4
4
  import { ParagraphProps } from 'antd/es/typography/Paragraph';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { useLocation, PathPattern } from 'react-router';
@@ -12,60 +12,65 @@ import { StateCreator } from 'zustand';
12
12
  import * as _tanstack_react_query from '@tanstack/react-query';
13
13
  import { StateStorage } from 'zustand/middleware';
14
14
 
15
+ /** HTTP 响应错误,包含响应和数据 */
16
+ declare class HttpResponseError extends Error {
17
+ response?: Response;
18
+ data?: unknown;
19
+ constructor(message: string, response?: Response, data?: unknown);
20
+ }
15
21
  /** 响应类型 */
16
22
  type ResponseType = 'json' | 'blob' | 'text' | 'arrayBuffer' | 'formData';
17
23
  /** 通用请求选项接口 */
18
24
  interface RequestOptions extends Options {
19
25
  /** 响应类型 */
20
26
  responseType?: ResponseType;
21
- /** 是否使用全局模式 */
27
+ /** 是否使用全局模式,为 true 时 app-id header 设置为 global */
22
28
  isGlobalMode?: boolean;
23
29
  }
24
- /** KyClient 构造函数配置 */
25
- interface KyClientOptions {
26
- /** 基础 URL */
27
- baseURL?: string;
28
- /** 自定义 hooks(拦截器) */
29
- hooks?: Partial<Hooks>;
30
- }
31
- /** HTTP客户端方法接口 */
30
+ /** HTTP 客户端方法接口 */
32
31
  interface KyMethods {
33
32
  get: <T = unknown>(url: string, options?: RequestOptions) => Promise<T>;
34
33
  post: <T = unknown>(url: string, data?: unknown, options?: RequestOptions) => Promise<T>;
35
34
  put: <T = unknown>(url: string, data?: unknown, options?: RequestOptions) => Promise<T>;
36
35
  delete: <T = unknown>(url: string, options?: RequestOptions) => Promise<T>;
37
36
  patch: <T = unknown>(url: string, data?: unknown, options?: RequestOptions) => Promise<T>;
38
- options: <T = unknown>(url: string, options?: RequestOptions) => Promise<T>;
39
- head: <T = unknown>(url: string, options?: RequestOptions) => Promise<T>;
37
+ /** 通用请求方法 */
40
38
  request: <T = unknown>(options: RequestOptions & {
41
39
  url: string;
40
+ method?: string;
42
41
  }) => Promise<T>;
43
42
  instance: KyInstance;
44
43
  }
45
44
  /** useKy 配置选项 */
46
45
  interface UseKyOptions {
47
- /** 自定义 hooks(拦截器) */
46
+ /** 自定义 hooks(拦截器),在默认 hooks 之前执行 */
48
47
  hooks?: Partial<Hooks>;
49
48
  }
50
49
  /**
51
- * Ky HTTP 客户端类
50
+ * HTTP 客户端 Hook
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * const client = useKy()
55
+ *
56
+ * // GET 请求
57
+ * const data = await client.get<User[]>('/api/users')
58
+ *
59
+ * // POST 请求
60
+ * const result = await client.post<User>('/api/users', { name: 'John' })
61
+ *
62
+ * // 全局模式(app-id: global)
63
+ * const games = await client.get('/api/games', { isGlobalMode: true })
64
+ *
65
+ * // 自定义 hooks
66
+ * const client = useKy({
67
+ * hooks: {
68
+ * beforeRequest: [(request) => { console.log(request.url) }]
69
+ * }
70
+ * })
71
+ * ```
52
72
  */
53
- declare class KyClient implements KyMethods {
54
- private readonly _instance;
55
- constructor(options?: KyClientOptions);
56
- get instance(): KyInstance;
57
- get: <T = unknown>(url: string, options?: RequestOptions) => Promise<T>;
58
- post: <T = unknown>(url: string, data?: unknown, options?: RequestOptions) => Promise<T>;
59
- put: <T = unknown>(url: string, data?: unknown, options?: RequestOptions) => Promise<T>;
60
- delete: <T = unknown>(url: string, options?: RequestOptions) => Promise<T>;
61
- patch: <T = unknown>(url: string, data?: unknown, options?: RequestOptions) => Promise<T>;
62
- options: <T = unknown>(url: string, requestOptions?: RequestOptions) => Promise<T>;
63
- head: <T = unknown>(url: string, requestOptions?: RequestOptions) => Promise<T>;
64
- request: <T = unknown>(requestOptions: RequestOptions & {
65
- url: string;
66
- }) => Promise<T>;
67
- private makeRequest;
68
- }
73
+ declare function useKy(options?: UseKyOptions): KyMethods;
69
74
 
70
75
  interface AuthButtonProps extends ButtonProps {
71
76
  /** 权限码,支持单个或多个 */
@@ -1492,4 +1497,4 @@ declare function useAuth(code?: string | string[], config?: RequestOptions): {
1492
1497
  declare function useMenuList(): _tanstack_react_query.UseQueryResult<MenuListItem[], Error>;
1493
1498
  declare const useGames: () => _tanstack_react_query.UseQueryResult<Game[], Error>;
1494
1499
 
1495
- export { APP_ID_HEADER, AuthButton, type AuthButtonProps, AuthMode, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, type GameSelectConfig, type GameSelectProps, type HeaderExtra, type HeaderExtraConfig, Highlight, type HighlightProps, InfiniteList, type InfiniteListDataAdapter, type InfiniteListPayload, type InfiniteListProps, type InfiniteListRef, type InfiniteListRequestConfig, type InfiniteListRequestConfigType, type JsonResponse, KeepAlive, type KeepAliveCacheItem, KeepAliveOutlet, type KeepAliveOutletProps, type KeepAliveProps, KeepAliveProvider, type KeepAliveProviderProps, KyClient, type KyClientOptions, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, type RecursivePartial, type RequestOptions, RequireAuth, type RequireAuthProps, RequireGame, type ResponseType, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitsProvider, type ToolkitsProviderProps, type UseDrawerOperation, type UseDrawerProps, type UseFormDrawerProps, type UseFormDrawerReturn, type UseFormModalProps, type UseFormModalReturn, type UseKeepAliveReturn, type UseKyOptions, type UseModalOperation, type UseModalProps, UserDropdown, type VisibilityState, WILDCARD, createVisibilityStoreConfig, generateId, _default$1 as menuRoutes, mixedStorage, _default as permissionRoutes, useAuth, useDrawer, useDrawerStore, useFormDrawer, useFormModal, useGames, useInfiniteListStore, useKeepAlive, useKeepAliveContext, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitsStore };
1500
+ export { APP_ID_HEADER, AuthButton, type AuthButtonProps, AuthMode, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, type GameSelectConfig, type GameSelectProps, type HeaderExtra, type HeaderExtraConfig, Highlight, type HighlightProps, HttpResponseError, InfiniteList, type InfiniteListDataAdapter, type InfiniteListPayload, type InfiniteListProps, type InfiniteListRef, type InfiniteListRequestConfig, type InfiniteListRequestConfigType, type JsonResponse, KeepAlive, type KeepAliveCacheItem, KeepAliveOutlet, type KeepAliveOutletProps, type KeepAliveProps, KeepAliveProvider, type KeepAliveProviderProps, type KyMethods, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, type RecursivePartial, type RequestOptions, RequireAuth, type RequireAuthProps, RequireGame, type ResponseType, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitsProvider, type ToolkitsProviderProps, type UseDrawerOperation, type UseDrawerProps, type UseFormDrawerProps, type UseFormDrawerReturn, type UseFormModalProps, type UseFormModalReturn, type UseKeepAliveReturn, type UseKyOptions, type UseModalOperation, type UseModalProps, UserDropdown, type VisibilityState, WILDCARD, createVisibilityStoreConfig, generateId, _default$1 as menuRoutes, mixedStorage, _default as permissionRoutes, useAuth, useDrawer, useDrawerStore, useFormDrawer, useFormModal, useGames, useInfiniteListStore, useKeepAlive, useKeepAliveContext, useKy, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitsStore };