@wzyjs/next 0.2.59 → 0.2.61

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.
@@ -1,20 +1,34 @@
1
- // @ts-nocheck
2
-
3
1
  // @ts-ignore
4
2
  import { message } from '@/components'
5
3
 
6
4
  // @ts-ignore
7
- import { api } from '@/api/react'
5
+ import { trpc as api } from '@/api/react'
6
+
7
+ import type { Prisma } from '@prisma/client'
8
+ import type { UseTRPCQueryOptions } from '@trpc/react-query/shared'
9
+
10
+ // 定义 Prisma 查询相关类型
11
+ type FindManyArgs = Prisma.HabitGroupFindManyArgs;
12
+ type FindUniqueArgs = Prisma.HabitGroupFindUniqueArgs;
13
+ type GetPayload<T extends FindManyArgs | FindUniqueArgs> = Prisma.HabitGroupGetPayload<T>;
14
+
15
+ // 定义 SelectSubset 类型
16
+ type SelectSubset<T extends FindManyArgs | FindUniqueArgs, A> = Prisma.SelectSubset<T, A>;
17
+ type UseOptions<T> = UseTRPCQueryOptions<T, T, Error>;
8
18
 
9
- interface Option {
19
+ // 定义 Option 接口
20
+ interface Option<
21
+ TList extends FindManyArgs = FindManyArgs,
22
+ TInfo extends FindUniqueArgs = FindUniqueArgs,
23
+ > {
10
24
  showTip?: boolean,
11
25
  list?: false | {
12
- query?: Parameters<typeof api.habitGroup.findMany.useQuery>[0],
13
- option?: Parameters<typeof api.habitGroup.findMany.useQuery>[1],
26
+ query?: SelectSubset<TList, FindManyArgs>,
27
+ option?: UseOptions<GetPayload<TList>[]>,
14
28
  },
15
29
  info?: false | {
16
- query?: Parameters<typeof api.habitGroup.findUnique.useQuery>[0],
17
- option?: Parameters<typeof api.habitGroup.findUnique.useQuery>[1],
30
+ query: SelectSubset<TInfo, FindUniqueArgs>,
31
+ option?: UseOptions<GetPayload<TInfo> | null>,
18
32
  },
19
33
  create?: Parameters<typeof api.habitGroup.create.useMutation>[0],
20
34
  update?: Parameters<typeof api.habitGroup.update.useMutation>[0],
@@ -22,20 +36,37 @@ interface Option {
22
36
  delete?: Parameters<typeof api.habitGroup.delete.useMutation>[0],
23
37
  }
24
38
 
25
- export const useHabitGroupCRUD = (option: Option = {}) => {
26
- const { list, info, create, update, remove, delete: deleteOption, showTip = true } = option
39
+ export const useHabitGroupCRUD = <
40
+ TList extends FindManyArgs = FindManyArgs,
41
+ TInfo extends FindUniqueArgs = FindUniqueArgs,
42
+ >(option: Option<TList, TInfo> = {}) => {
43
+ const {
44
+ list,
45
+ info,
46
+ create,
47
+ update,
48
+ remove,
49
+ delete: deleteOption,
50
+ showTip = true,
51
+ } = option
27
52
 
28
53
  const apiUtils = api.useUtils()
29
54
 
30
- const listState = api.habitGroup.findMany.useQuery(list ? list.query : {}, {
31
- enabled: typeof list === 'boolean' ? list : true,
32
- ...list?.option,
33
- })
55
+ const listState = api.habitGroup.findMany.useQuery(
56
+ list === false ? undefined : list?.query,
57
+ {
58
+ enabled: list !== false,
59
+ ...(list ? list.option : undefined),
60
+ },
61
+ )
34
62
 
35
- const infoState = api.habitGroup.findUnique.useQuery(info ? info.query : { where: { id: '' } }, {
36
- enabled: !!(info && info.query),
37
- ...info?.option,
38
- })
63
+ const infoState = api.habitGroup.findMany.useQuery(
64
+ info === false ? undefined : info?.query,
65
+ {
66
+ enabled: info !== false,
67
+ ...(info ? info.option : undefined),
68
+ },
69
+ )
39
70
 
40
71
  const onSuccess = (tip: string) => {
41
72
  message.destroy()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/next",
3
- "version": "0.2.59",
3
+ "version": "0.2.61",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "@zenstackhq/sdk": "^2.12.3"
19
19
  },
20
- "gitHead": "0a6dc9df2da5a0b573de1eb5fd24f09b262228a2",
20
+ "gitHead": "c7f7d2f29d99b35755eab9c160fff4fd92ed2415",
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  }