@wzyjs/next 0.2.60 → 0.2.62

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/dist/Base.zmodel CHANGED
@@ -36,7 +36,7 @@ plugin trpc {
36
36
  importCreateRouter = "@/api/trpc/trpc"
37
37
  importProcedure = "@/api/trpc/procedures"
38
38
  zodSchemasImport = '@/api/generated/zod'
39
- generateModelActions = 'findMany, findUnique, create, update, delete, deleteMany'
39
+ generateModelActions = 'findMany, findUnique, create, update, updateMany, delete, deleteMany, count'
40
40
  }
41
41
 
42
42
  plugin crud_tags {
@@ -1,40 +1,68 @@
1
- // @ts-nocheck
1
+ import React, { useState } from 'react'
2
2
 
3
3
  // @ts-ignore
4
4
  import { message } from '@/components'
5
5
 
6
6
  // @ts-ignore
7
- import { api } from '@/api/react'
7
+ import { trpc as api } from '@/api/react'
8
8
 
9
- interface Option {
10
- showTip?: boolean,
9
+ import type { Prisma } from '@prisma/client'
10
+ import type { UseTRPCQueryOptions } from '@trpc/react-query/shared'
11
+
12
+ // 定义 Prisma 查询相关类型
13
+ type FindManyArgs = Prisma.HabitGroupFindManyArgs;
14
+ type FindUniqueArgs = Prisma.HabitGroupFindUniqueArgs;
15
+ type GetPayload<T extends FindManyArgs | FindUniqueArgs> = Prisma.HabitGroupGetPayload<T>;
16
+
17
+ // 定义 SelectSubset 类型
18
+ type SelectSubset<T extends FindManyArgs | FindUniqueArgs, A> = Prisma.SelectSubset<T, A>;
19
+ type UseOptions<T> = UseTRPCQueryOptions<T, T, Error>;
20
+
21
+ // 定义 Option 接口
22
+ interface Option<TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs> {
23
+ showTip?: boolean
11
24
  list?: false | {
12
- query?: Parameters<typeof api.habitGroup.findMany.useQuery>[0],
13
- option?: Parameters<typeof api.habitGroup.findMany.useQuery>[1],
14
- },
15
- info?: false | {
16
- query?: Parameters<typeof api.habitGroup.findUnique.useQuery>[0],
17
- option?: Parameters<typeof api.habitGroup.findUnique.useQuery>[1],
18
- },
19
- create?: Parameters<typeof api.habitGroup.create.useMutation>[0],
20
- update?: Parameters<typeof api.habitGroup.update.useMutation>[0],
21
- remove?: Parameters<typeof api.habitGroup.update.useMutation>[0],
22
- delete?: Parameters<typeof api.habitGroup.delete.useMutation>[0],
25
+ query?: SelectSubset<TList, FindManyArgs>
26
+ option?: UseOptions<GetPayload<TList>[]>
27
+ }
28
+ info?: {
29
+ query: SelectSubset<TInfo, FindUniqueArgs>
30
+ option?: UseOptions<GetPayload<TInfo> | null>
31
+ }
32
+ create?: Parameters<typeof api.habitGroup.create.useMutation>[0]
33
+ update?: Parameters<typeof api.habitGroup.update.useMutation>[0]
34
+ remove?: Parameters<typeof api.habitGroup.update.useMutation>[0]
35
+ delete?: Parameters<typeof api.habitGroup.delete.useMutation>[0]
36
+ }
37
+
38
+ const r = (q: any) => {
39
+ if (!q) {
40
+ return
41
+ }
42
+ const query = JSON.parse(JSON.stringify(q))
43
+ delete query?.skip
44
+ delete query?.take
45
+ return query
23
46
  }
24
47
 
25
- export const useHabitGroupCRUD = (option: Option = {}) => {
48
+ export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs>(option: Option<TList, TInfo> = {}) => {
26
49
  const { list, info, create, update, remove, delete: deleteOption, showTip = true } = option
27
50
 
28
51
  const apiUtils = api.useUtils()
29
52
 
30
- const listState = api.habitGroup.findMany.useQuery(list ? list.query : {}, {
31
- enabled: typeof list === 'boolean' ? list : true,
32
- ...list?.option,
53
+ const listState = api.habitGroup.findMany.useQuery(list === false ? undefined : list?.query, {
54
+ enabled: list !== false,
55
+ ...(list ? list.option : undefined),
56
+ })
57
+
58
+ const countState = api.habitGroup.count.useQuery(list === false ? {} as any : r(list?.query), {
59
+ enabled: list !== false,
60
+ ...(list ? list.option : undefined),
33
61
  })
34
62
 
35
- const infoState = api.habitGroup.findUnique.useQuery(info ? info.query : { where: { id: '' } }, {
36
- enabled: !!(info && info.query),
37
- ...info?.option,
63
+ const infoState = api.habitGroup.findUnique.useQuery(info?.query || {} as any, {
64
+ enabled: !!info,
65
+ ...(info ? info.option : undefined),
38
66
  })
39
67
 
40
68
  const onSuccess = (tip: string) => {
@@ -44,6 +72,7 @@ export const useHabitGroupCRUD = (option: Option = {}) => {
44
72
  }
45
73
  if (list) {
46
74
  listState.refetch()
75
+ countState.refetch()
47
76
  }
48
77
  }
49
78
 
@@ -58,7 +87,7 @@ export const useHabitGroupCRUD = (option: Option = {}) => {
58
87
  })
59
88
 
60
89
  const createState = {
61
- ...baseCreateState as unknown as typeof baseCreateState,
90
+ ...(baseCreateState as unknown as typeof baseCreateState),
62
91
  mutate: (data: Parameters<typeof baseCreateState.mutate>[0]['data']) => {
63
92
  return baseCreateState.mutate({ data })
64
93
  },
@@ -78,7 +107,7 @@ export const useHabitGroupCRUD = (option: Option = {}) => {
78
107
  })
79
108
 
80
109
  const updateState = {
81
- ...baseUpdateState as unknown as typeof baseUpdateState,
110
+ ...(baseUpdateState as unknown as typeof baseUpdateState),
82
111
  mutate: (id: string, data: Parameters<typeof baseUpdateState.mutate>[0]['data']) => {
83
112
  return baseUpdateState.mutate({
84
113
  where: { id },
@@ -104,7 +133,7 @@ export const useHabitGroupCRUD = (option: Option = {}) => {
104
133
  })
105
134
 
106
135
  const removeState = {
107
- ...baseRemoveState as unknown as typeof baseRemoveState,
136
+ ...(baseRemoveState as unknown as typeof baseRemoveState),
108
137
  mutate: (id: string) => {
109
138
  return baseRemoveState.mutate({
110
139
  where: { id },
@@ -130,7 +159,7 @@ export const useHabitGroupCRUD = (option: Option = {}) => {
130
159
  })
131
160
 
132
161
  const deleteState = {
133
- ...baseDeleteState as unknown as typeof baseDeleteState,
162
+ ...(baseDeleteState as unknown as typeof baseDeleteState),
134
163
  mutate: (id: string) => {
135
164
  return baseDeleteState.mutate({
136
165
  where: { id },
@@ -143,13 +172,17 @@ export const useHabitGroupCRUD = (option: Option = {}) => {
143
172
  },
144
173
  }
145
174
 
175
+ const [query, setQuery] = useState()
176
+
146
177
  return {
147
178
  listState,
179
+ countState,
148
180
  infoState,
149
181
  createState,
150
182
  removeState,
151
183
  updateState,
152
184
  deleteState,
185
+
153
186
  apiUtils,
154
187
  }
155
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/next",
3
- "version": "0.2.60",
3
+ "version": "0.2.62",
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": "81b5a3fc804541ed989d13f40098effd6540bfa5",
20
+ "gitHead": "d9493fc26e494769edcb3aab4d193e5d7ab68bc1",
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  }