@wzyjs/next 0.2.60 → 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
|
-
|
|
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?:
|
|
13
|
-
option?:
|
|
26
|
+
query?: SelectSubset<TList, FindManyArgs>,
|
|
27
|
+
option?: UseOptions<GetPayload<TList>[]>,
|
|
14
28
|
},
|
|
15
29
|
info?: false | {
|
|
16
|
-
query
|
|
17
|
-
option?:
|
|
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 =
|
|
26
|
-
|
|
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(
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
36
|
-
|
|
37
|
-
|
|
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.
|
|
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": "
|
|
20
|
+
"gitHead": "c7f7d2f29d99b35755eab9c160fff4fd92ed2415",
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
}
|