Skip to content

Commit 2035319

Browse files
authored
fix: wrong return type of generated count hook (#347)
1 parent 83fd21e commit 2035319

File tree

14 files changed

+35
-15
lines changed

14 files changed

+35
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "1.0.0-alpha.100",
3+
"version": "1.0.0-alpha.101",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/language",
3-
"version": "1.0.0-alpha.100",
3+
"version": "1.0.0-alpha.101",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

packages/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/next",
3-
"version": "1.0.0-alpha.100",
3+
"version": "1.0.0-alpha.101",
44
"displayName": "ZenStack Next.js integration",
55
"description": "ZenStack Next.js integration",
66
"homepage": "https://zenstack.dev",

packages/plugins/openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/openapi",
33
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
4-
"version": "1.0.0-alpha.100",
4+
"version": "1.0.0-alpha.101",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

packages/plugins/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/react",
33
"displayName": "ZenStack plugin and runtime for ReactJS",
4-
"version": "1.0.0-alpha.100",
4+
"version": "1.0.0-alpha.101",
55
"description": "ZenStack plugin and runtime for ReactJS",
66
"main": "index.js",
77
"repository": {

packages/plugins/react/src/generator/react-query.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,24 @@ function generateModelHooks(project: Project, outDir: string, model: DataModel,
285285
}[OrderFields]`,
286286
];
287287

288+
const returnType = `{} extends InputErrors ?
289+
Array<Prisma.PickArray<Prisma.${model.name}GroupByOutputType, T['by']> &
290+
{
291+
[P in ((keyof T) & (keyof Prisma.${model.name}GroupByOutputType))]: P extends '_count'
292+
? T[P] extends boolean
293+
? number
294+
: Prisma.GetScalarType<T[P], Prisma.${model.name}GroupByOutputType[P]>
295+
: Prisma.GetScalarType<T[P], Prisma.${model.name}GroupByOutputType[P]>
296+
}
297+
> : InputErrors`;
298+
288299
generateQueryHook(
289300
sf,
290301
model.name,
291302
'groupBy',
292303
false,
293304
false,
294-
`{} extends InputErrors ? Prisma.Get${model.name}GroupByPayload<T> : InputErrors`,
305+
returnType,
295306
`Prisma.SubsetIntersection<T, Prisma.${model.name}GroupByArgs, OrderByArg> & InputErrors`,
296307
typeParameters
297308
);

packages/plugins/react/src/generator/swr.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,16 @@ function generateModelHooks(project: Project, outDir: string, model: DataModel,
378378
// groupBy
379379
if (mapping.groupBy) {
380380
methods.push('groupBy');
381-
const returnType = `{} extends InputErrors ? Prisma.Get${model.name}GroupByPayload<T> : InputErrors`;
381+
const returnType = `{} extends InputErrors ?
382+
Array<Prisma.PickArray<Prisma.${model.name}GroupByOutputType, T['by']> &
383+
{
384+
[P in ((keyof T) & (keyof Prisma.${model.name}GroupByOutputType))]: P extends '_count'
385+
? T[P] extends boolean
386+
? number
387+
: Prisma.GetScalarType<T[P], Prisma.${model.name}GroupByOutputType[P]>
388+
: Prisma.GetScalarType<T[P], Prisma.${model.name}GroupByOutputType[P]>
389+
}
390+
> : InputErrors`;
382391
useFunc
383392
.addFunction({
384393
name: 'groupBy',

packages/plugins/trpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/trpc",
33
"displayName": "ZenStack plugin for tRPC",
4-
"version": "1.0.0-alpha.100",
4+
"version": "1.0.0-alpha.101",
55
"description": "ZenStack plugin for tRPC",
66
"main": "index.js",
77
"repository": {

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/runtime",
33
"displayName": "ZenStack Runtime Library",
4-
"version": "1.0.0-alpha.100",
4+
"version": "1.0.0-alpha.101",
55
"description": "Runtime of ZenStack for both client-side and server-side environments.",
66
"repository": {
77
"type": "git",

packages/schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack Language Tools",
55
"description": "A toolkit for building secure CRUD apps with Next.js + Typescript",
6-
"version": "1.0.0-alpha.100",
6+
"version": "1.0.0-alpha.101",
77
"author": {
88
"name": "ZenStack Team"
99
},

0 commit comments

Comments
 (0)