soda-tanstack-query 0.0.7 → 0.0.9

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.
@@ -24,13 +24,18 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
+ setUseQuery: ()=>setUseQuery,
27
28
  createUseQuery: ()=>createUseQuery
28
29
  });
29
30
  const react_query_namespaceObject = require("@tanstack/react-query");
31
+ let __useQuery = react_query_namespaceObject.useQuery;
32
+ function setUseQuery(useQuery) {
33
+ __useQuery = useQuery;
34
+ }
30
35
  function createUseQuery(params, client) {
31
36
  const { queryFn, queryKey, ...rest } = params;
32
- const useRequest = function(params2, options, client2 = client) {
33
- return (0, react_query_namespaceObject.useQuery)({
37
+ const useQuery = function(params2, options, client2 = client) {
38
+ return __useQuery({
34
39
  queryKey: [
35
40
  queryKey,
36
41
  params2
@@ -40,7 +45,7 @@ function createUseQuery(params, client) {
40
45
  ...options
41
46
  }, client2);
42
47
  };
43
- useRequest.refine = function(params2, client2) {
48
+ useQuery.refine = function(params2, client2) {
44
49
  params2 = "function" == typeof params2 ? params2(params, client) : params2;
45
50
  client2 = "function" == typeof client2 ? client2(params, client) : client2;
46
51
  return createUseQuery({
@@ -48,10 +53,13 @@ function createUseQuery(params, client) {
48
53
  ...params2
49
54
  }, client2 ?? client);
50
55
  };
56
+ return useQuery;
51
57
  }
52
58
  exports.createUseQuery = __webpack_exports__.createUseQuery;
59
+ exports.setUseQuery = __webpack_exports__.setUseQuery;
53
60
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
54
- "createUseQuery"
61
+ "createUseQuery",
62
+ "setUseQuery"
55
63
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
56
64
  Object.defineProperty(exports, '__esModule', {
57
65
  value: true
@@ -1,4 +1,4 @@
1
- import { DefinedInitialDataOptions, DefinedUseQueryResult, QueryClient, UndefinedInitialDataOptions, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
1
+ import { useQuery as _useQuery, DefinedInitialDataOptions, DefinedUseQueryResult, QueryClient, UndefinedInitialDataOptions, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
2
2
  import { Assign, IsParamRequired, StrictPartial } from "soda-type";
3
3
  /** 参数必须的 useQuery */
4
4
  interface _UseQueryWithParams<TFn extends (params: any) => any, TInitSelectData = Awaited<ReturnType<TFn>>, TParams = Parameters<TFn>[0], TResponse = Awaited<ReturnType<TFn>>> {
@@ -83,6 +83,7 @@ interface _CreateUseQueryParams<TFn extends (param: any) => any, TInitSelectData
83
83
  }
84
84
  export interface CreateUseQueryParams<TFn extends (param: any) => any, TInitSelectData = Awaited<ReturnType<TFn>>> extends _CreateUseQueryParams<TFn, TInitSelectData> {
85
85
  }
86
+ export declare function setUseQuery(useQuery: typeof _useQuery): void;
86
87
  export declare function createUseQuery<TFn extends (param: any) => any, TInitSelectData = Awaited<ReturnType<TFn>>>(params: CreateUseQueryDefinedInitialDataParams<TFn, TInitSelectData>, client?: QueryClient): UseQueryDefinedInitialData<TFn, TInitSelectData>;
87
88
  export declare function createUseQuery<TFn extends (param: any) => any, TInitSelectData = Awaited<ReturnType<TFn>>>(pararm: CreateUseQueryUndefinedInitialDataParams<TFn, TInitSelectData>, client?: QueryClient): UseQueryUndefinedInitialData<TFn, TInitSelectData>;
88
89
  export declare function createUseQuery<TFn extends (param: any) => any, TInitSelectData = Awaited<ReturnType<TFn>>>(pararm: CreateUseQueryParams<TFn, TInitSelectData>, client?: QueryClient): UseQuery<TFn, TInitSelectData>;
@@ -1,8 +1,12 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery as react_query_useQuery } from "@tanstack/react-query";
2
+ let __useQuery = react_query_useQuery;
3
+ function setUseQuery(useQuery) {
4
+ __useQuery = useQuery;
5
+ }
2
6
  function createUseQuery(params, client) {
3
7
  const { queryFn, queryKey, ...rest } = params;
4
- const useRequest = function(params2, options, client2 = client) {
5
- return useQuery({
8
+ const useQuery = function(params2, options, client2 = client) {
9
+ return __useQuery({
6
10
  queryKey: [
7
11
  queryKey,
8
12
  params2
@@ -12,7 +16,7 @@ function createUseQuery(params, client) {
12
16
  ...options
13
17
  }, client2);
14
18
  };
15
- useRequest.refine = function(params2, client2) {
19
+ useQuery.refine = function(params2, client2) {
16
20
  params2 = "function" == typeof params2 ? params2(params, client) : params2;
17
21
  client2 = "function" == typeof client2 ? client2(params, client) : client2;
18
22
  return createUseQuery({
@@ -20,5 +24,6 @@ function createUseQuery(params, client) {
20
24
  ...params2
21
25
  }, client2 ?? client);
22
26
  };
27
+ return useQuery;
23
28
  }
24
- export { createUseQuery };
29
+ export { createUseQuery, setUseQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-tanstack-query",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -35,11 +35,11 @@
35
35
  },
36
36
  "homepage": "https://github.com/1adybug/deepsea/tree/main/packages/soda-tanstack-query",
37
37
  "dependencies": {
38
- "@tanstack/react-query": "^5.90.19"
38
+ "@tanstack/react-query": "^5.90.21"
39
39
  },
40
40
  "devDependencies": {
41
- "typescript": ">=5.8.3",
42
- "soda-type": ""
41
+ "soda-type": "",
42
+ "typescript": ">=5.8.3"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@types/react": ">=19.2.7",
@@ -1,9 +1,9 @@
1
1
  import {
2
+ useQuery as _useQuery,
2
3
  DefinedInitialDataOptions,
3
4
  DefinedUseQueryResult,
4
5
  QueryClient,
5
6
  UndefinedInitialDataOptions,
6
- useQuery,
7
7
  UseQueryOptions,
8
8
  UseQueryResult,
9
9
  } from "@tanstack/react-query"
@@ -261,6 +261,12 @@ export interface CreateUseQueryParams<TFn extends (param: any) => any, TInitSele
261
261
  TInitSelectData
262
262
  > {}
263
263
 
264
+ let __useQuery = _useQuery
265
+
266
+ export function setUseQuery(useQuery: typeof _useQuery) {
267
+ __useQuery = useQuery
268
+ }
269
+
264
270
  // 根据是否传递初始化参数,选择不同的 createUseQuery,目前存在一个问题,UndefinedInitialDataOptions 和 UseQueryOptions 是完全一致的,所以匹配不到第三种可能,但这是 @tanstack/react-query 的问题
265
271
  export function createUseQuery<TFn extends (param: any) => any, TInitSelectData = Awaited<ReturnType<TFn>>>(
266
272
  params: CreateUseQueryDefinedInitialDataParams<TFn, TInitSelectData>,
@@ -281,8 +287,8 @@ export function createUseQuery<TFn extends (param: any) => any, TInitSelectData
281
287
  ): any {
282
288
  const { queryFn, queryKey, ...rest } = params
283
289
 
284
- const useRequest: any = function useRequest(params2: any, options?: any, client2: QueryClient | undefined = client) {
285
- return useQuery(
290
+ const useQuery: any = function useRequest(params2: any, options?: any, client2: QueryClient | undefined = client) {
291
+ return __useQuery(
286
292
  {
287
293
  queryKey: [queryKey, params2],
288
294
  queryFn: () => queryFn(params2),
@@ -293,11 +299,13 @@ export function createUseQuery<TFn extends (param: any) => any, TInitSelectData
293
299
  )
294
300
  }
295
301
 
296
- useRequest.refine = function refine(params2: any, client2?: any) {
302
+ useQuery.refine = function refine(params2: any, client2?: any) {
297
303
  params2 = typeof params2 === "function" ? params2(params, client) : params2
298
304
  client2 = typeof client2 === "function" ? client2(params, client) : client2
299
305
  return createUseQuery({ ...params, ...params2 }, client2 ?? client)
300
306
  }
307
+
308
+ return useQuery
301
309
  }
302
310
 
303
311
  export type GetHookFromParams<Params> =