@wzyjs/next 0.2.61 → 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,3 +1,5 @@
1
+ import React, { useState } from 'react'
2
+
1
3
  // @ts-ignore
2
4
  import { message } from '@/components'
3
5
 
@@ -17,56 +19,51 @@ type SelectSubset<T extends FindManyArgs | FindUniqueArgs, A> = Prisma.SelectSub
17
19
  type UseOptions<T> = UseTRPCQueryOptions<T, T, Error>;
18
20
 
19
21
  // 定义 Option 接口
20
- interface Option<
21
- TList extends FindManyArgs = FindManyArgs,
22
- TInfo extends FindUniqueArgs = FindUniqueArgs,
23
- > {
24
- showTip?: boolean,
22
+ interface Option<TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs> {
23
+ showTip?: boolean
25
24
  list?: false | {
26
- query?: SelectSubset<TList, FindManyArgs>,
27
- option?: UseOptions<GetPayload<TList>[]>,
28
- },
29
- info?: false | {
30
- query: SelectSubset<TInfo, FindUniqueArgs>,
31
- option?: UseOptions<GetPayload<TInfo> | null>,
32
- },
33
- create?: Parameters<typeof api.habitGroup.create.useMutation>[0],
34
- update?: Parameters<typeof api.habitGroup.update.useMutation>[0],
35
- remove?: Parameters<typeof api.habitGroup.update.useMutation>[0],
36
- 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]
37
36
  }
38
37
 
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
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
46
+ }
47
+
48
+ export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs>(option: Option<TList, TInfo> = {}) => {
49
+ const { list, info, create, update, remove, delete: deleteOption, showTip = true } = option
52
50
 
53
51
  const apiUtils = api.useUtils()
54
52
 
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
- )
53
+ const listState = api.habitGroup.findMany.useQuery(list === false ? undefined : list?.query, {
54
+ enabled: list !== false,
55
+ ...(list ? list.option : undefined),
56
+ })
62
57
 
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
- )
58
+ const countState = api.habitGroup.count.useQuery(list === false ? {} as any : r(list?.query), {
59
+ enabled: list !== false,
60
+ ...(list ? list.option : undefined),
61
+ })
62
+
63
+ const infoState = api.habitGroup.findUnique.useQuery(info?.query || {} as any, {
64
+ enabled: !!info,
65
+ ...(info ? info.option : undefined),
66
+ })
70
67
 
71
68
  const onSuccess = (tip: string) => {
72
69
  message.destroy()
@@ -75,6 +72,7 @@ export const useHabitGroupCRUD = <
75
72
  }
76
73
  if (list) {
77
74
  listState.refetch()
75
+ countState.refetch()
78
76
  }
79
77
  }
80
78
 
@@ -89,7 +87,7 @@ export const useHabitGroupCRUD = <
89
87
  })
90
88
 
91
89
  const createState = {
92
- ...baseCreateState as unknown as typeof baseCreateState,
90
+ ...(baseCreateState as unknown as typeof baseCreateState),
93
91
  mutate: (data: Parameters<typeof baseCreateState.mutate>[0]['data']) => {
94
92
  return baseCreateState.mutate({ data })
95
93
  },
@@ -109,7 +107,7 @@ export const useHabitGroupCRUD = <
109
107
  })
110
108
 
111
109
  const updateState = {
112
- ...baseUpdateState as unknown as typeof baseUpdateState,
110
+ ...(baseUpdateState as unknown as typeof baseUpdateState),
113
111
  mutate: (id: string, data: Parameters<typeof baseUpdateState.mutate>[0]['data']) => {
114
112
  return baseUpdateState.mutate({
115
113
  where: { id },
@@ -135,7 +133,7 @@ export const useHabitGroupCRUD = <
135
133
  })
136
134
 
137
135
  const removeState = {
138
- ...baseRemoveState as unknown as typeof baseRemoveState,
136
+ ...(baseRemoveState as unknown as typeof baseRemoveState),
139
137
  mutate: (id: string) => {
140
138
  return baseRemoveState.mutate({
141
139
  where: { id },
@@ -161,7 +159,7 @@ export const useHabitGroupCRUD = <
161
159
  })
162
160
 
163
161
  const deleteState = {
164
- ...baseDeleteState as unknown as typeof baseDeleteState,
162
+ ...(baseDeleteState as unknown as typeof baseDeleteState),
165
163
  mutate: (id: string) => {
166
164
  return baseDeleteState.mutate({
167
165
  where: { id },
@@ -174,13 +172,17 @@ export const useHabitGroupCRUD = <
174
172
  },
175
173
  }
176
174
 
175
+ const [query, setQuery] = useState()
176
+
177
177
  return {
178
178
  listState,
179
+ countState,
179
180
  infoState,
180
181
  createState,
181
182
  removeState,
182
183
  updateState,
183
184
  deleteState,
185
+
184
186
  apiUtils,
185
187
  }
186
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/next",
3
- "version": "0.2.61",
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": "c7f7d2f29d99b35755eab9c160fff4fd92ed2415",
20
+ "gitHead": "d9493fc26e494769edcb3aab4d193e5d7ab68bc1",
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  }