@wzyjs/next 0.2.61 → 0.2.63
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
|
@@ -7,7 +7,7 @@ generator json {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
datasource db {
|
|
10
|
-
provider = "
|
|
10
|
+
provider = "postgresql"
|
|
11
11
|
url = env("DATABASE_URL")
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -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 {
|
|
@@ -17,56 +17,58 @@ type SelectSubset<T extends FindManyArgs | FindUniqueArgs, A> = Prisma.SelectSub
|
|
|
17
17
|
type UseOptions<T> = UseTRPCQueryOptions<T, T, Error>;
|
|
18
18
|
|
|
19
19
|
// 定义 Option 接口
|
|
20
|
-
interface Option<
|
|
21
|
-
|
|
22
|
-
TInfo extends FindUniqueArgs = FindUniqueArgs,
|
|
23
|
-
> {
|
|
24
|
-
showTip?: boolean,
|
|
20
|
+
interface Option<TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs> {
|
|
21
|
+
showTip?: boolean
|
|
25
22
|
list?: false | {
|
|
26
|
-
query?: SelectSubset<TList, FindManyArgs
|
|
27
|
-
option?: UseOptions<GetPayload<TList>[]
|
|
28
|
-
}
|
|
29
|
-
info?:
|
|
30
|
-
query: SelectSubset<TInfo, FindUniqueArgs
|
|
31
|
-
option?: UseOptions<GetPayload<TInfo> | null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
query?: SelectSubset<TList, FindManyArgs>
|
|
24
|
+
option?: UseOptions<GetPayload<TList>[]>
|
|
25
|
+
}
|
|
26
|
+
info?: {
|
|
27
|
+
query: SelectSubset<TInfo, FindUniqueArgs>
|
|
28
|
+
option?: UseOptions<GetPayload<TInfo> | null>
|
|
29
|
+
}
|
|
30
|
+
allTags?: true
|
|
31
|
+
create?: Parameters<typeof api.habitGroup.create.useMutation>[0]
|
|
32
|
+
update?: Parameters<typeof api.habitGroup.update.useMutation>[0]
|
|
33
|
+
remove?: Parameters<typeof api.habitGroup.update.useMutation>[0]
|
|
34
|
+
delete?: Parameters<typeof api.habitGroup.delete.useMutation>[0]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const r = (q: any) => {
|
|
38
|
+
if (!q) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
const query = JSON.parse(JSON.stringify(q))
|
|
42
|
+
delete query?.skip
|
|
43
|
+
delete query?.take
|
|
44
|
+
delete query?.include
|
|
45
|
+
delete query?.select
|
|
46
|
+
return query
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
export const useHabitGroupCRUD = <
|
|
40
|
-
|
|
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
|
|
49
|
+
export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs>(option: Option<TList, TInfo> = {}) => {
|
|
50
|
+
const { list, info, create, update, remove, allTags, delete: deleteOption, showTip = true } = option
|
|
52
51
|
|
|
53
52
|
const apiUtils = api.useUtils()
|
|
54
53
|
|
|
55
|
-
const listState = api.habitGroup.findMany.useQuery(
|
|
56
|
-
list
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
...(list ? list.option : undefined),
|
|
60
|
-
},
|
|
61
|
-
)
|
|
54
|
+
const listState = api.habitGroup.findMany.useQuery(list === false ? undefined : list?.query, {
|
|
55
|
+
enabled: list !== false,
|
|
56
|
+
...(list ? list.option : undefined),
|
|
57
|
+
})
|
|
62
58
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
const countState = api.habitGroup.count.useQuery(list === false ? {} as any : r(list?.query), {
|
|
60
|
+
enabled: list !== false,
|
|
61
|
+
...(list ? list.option : undefined),
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const infoState = api.habitGroup.findUnique.useQuery(info?.query || {} as any, {
|
|
65
|
+
enabled: !!info,
|
|
66
|
+
...(info ? info.option : undefined),
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const allTagsState = api.habitGroup.getAllTags.useQuery(undefined, {
|
|
70
|
+
enabled: allTags,
|
|
71
|
+
})
|
|
70
72
|
|
|
71
73
|
const onSuccess = (tip: string) => {
|
|
72
74
|
message.destroy()
|
|
@@ -75,6 +77,7 @@ export const useHabitGroupCRUD = <
|
|
|
75
77
|
}
|
|
76
78
|
if (list) {
|
|
77
79
|
listState.refetch()
|
|
80
|
+
countState.refetch()
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
@@ -89,7 +92,7 @@ export const useHabitGroupCRUD = <
|
|
|
89
92
|
})
|
|
90
93
|
|
|
91
94
|
const createState = {
|
|
92
|
-
...baseCreateState as unknown as typeof baseCreateState,
|
|
95
|
+
...(baseCreateState as unknown as typeof baseCreateState),
|
|
93
96
|
mutate: (data: Parameters<typeof baseCreateState.mutate>[0]['data']) => {
|
|
94
97
|
return baseCreateState.mutate({ data })
|
|
95
98
|
},
|
|
@@ -109,7 +112,7 @@ export const useHabitGroupCRUD = <
|
|
|
109
112
|
})
|
|
110
113
|
|
|
111
114
|
const updateState = {
|
|
112
|
-
...baseUpdateState as unknown as typeof baseUpdateState,
|
|
115
|
+
...(baseUpdateState as unknown as typeof baseUpdateState),
|
|
113
116
|
mutate: (id: string, data: Parameters<typeof baseUpdateState.mutate>[0]['data']) => {
|
|
114
117
|
return baseUpdateState.mutate({
|
|
115
118
|
where: { id },
|
|
@@ -135,7 +138,7 @@ export const useHabitGroupCRUD = <
|
|
|
135
138
|
})
|
|
136
139
|
|
|
137
140
|
const removeState = {
|
|
138
|
-
...baseRemoveState as unknown as typeof baseRemoveState,
|
|
141
|
+
...(baseRemoveState as unknown as typeof baseRemoveState),
|
|
139
142
|
mutate: (id: string) => {
|
|
140
143
|
return baseRemoveState.mutate({
|
|
141
144
|
where: { id },
|
|
@@ -161,7 +164,7 @@ export const useHabitGroupCRUD = <
|
|
|
161
164
|
})
|
|
162
165
|
|
|
163
166
|
const deleteState = {
|
|
164
|
-
...baseDeleteState as unknown as typeof baseDeleteState,
|
|
167
|
+
...(baseDeleteState as unknown as typeof baseDeleteState),
|
|
165
168
|
mutate: (id: string) => {
|
|
166
169
|
return baseDeleteState.mutate({
|
|
167
170
|
where: { id },
|
|
@@ -176,11 +179,17 @@ export const useHabitGroupCRUD = <
|
|
|
176
179
|
|
|
177
180
|
return {
|
|
178
181
|
listState,
|
|
182
|
+
countState,
|
|
183
|
+
|
|
179
184
|
infoState,
|
|
185
|
+
|
|
186
|
+
allTagsState,
|
|
187
|
+
|
|
180
188
|
createState,
|
|
181
|
-
removeState,
|
|
182
189
|
updateState,
|
|
190
|
+
removeState,
|
|
183
191
|
deleteState,
|
|
192
|
+
|
|
184
193
|
apiUtils,
|
|
185
194
|
}
|
|
186
195
|
}
|
|
@@ -43,9 +43,10 @@ var generateTags = function (model, outputPath) { return __awaiter(void 0, void
|
|
|
43
43
|
var dataModels, modelsWithTags, _i, modelsWithTags_1, dataModel, modelName, routerFilePath, fileContent, getAllTagsInterface, lastCommaIndex, closingBraceIndex, beforeInsertion, afterInsertion, newContent;
|
|
44
44
|
return __generator(this, function (_a) {
|
|
45
45
|
dataModels = model.declarations.filter(function (item) { return item.$type === 'DataModel'; });
|
|
46
|
-
modelsWithTags = dataModels
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
modelsWithTags = dataModels;
|
|
47
|
+
// .filter(dataModel => {
|
|
48
|
+
// return dataModel.fields.some(field => field.name === 'tags')
|
|
49
|
+
// })
|
|
49
50
|
if (modelsWithTags.length === 0) {
|
|
50
51
|
return [2 /*return*/];
|
|
51
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/next",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.63",
|
|
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": "973e4aacd8b71a5a2004cd5ceaf3a0645992cb75",
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
}
|