Skip to content

Commit 3e09a3a

Browse files
authored
fix: add CheckSelect type into code for Prisma version backward compatibility (#619)
1 parent c5b70b7 commit 3e09a3a

File tree

16 files changed

+74
-19
lines changed

16 files changed

+74
-19
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-beta.15",
3+
"version": "1.0.0-beta.16",
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-beta.15",
3+
"version": "1.0.0-beta.16",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
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-beta.15",
4+
"version": "1.0.0-beta.16",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

packages/plugins/prisma-types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,22 @@ export type TupleToUnion<K extends readonly any[]> = _TupleToUnion<K>;
1010
export type MaybeTupleToUnion<T> = T extends any[] ? TupleToUnion<T> : T;
1111

1212
export type PickEnumerable<T, K extends Enumerable<keyof T> | keyof T> = Pick<T, MaybeTupleToUnion<K>>;
13+
14+
type SelectAndInclude = {
15+
select: any;
16+
include: any;
17+
};
18+
type HasSelect = {
19+
select: any;
20+
};
21+
type HasInclude = {
22+
include: any;
23+
};
24+
25+
export type CheckSelect<T, S, U> = T extends SelectAndInclude
26+
? 'Please either choose `select` or `include`'
27+
: T extends HasSelect
28+
? U
29+
: T extends HasInclude
30+
? U
31+
: S;

packages/plugins/swr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/swr",
33
"displayName": "ZenStack plugin for generating SWR hooks",
4-
"version": "1.0.0-beta.15",
4+
"version": "1.0.0-beta.16",
55
"description": "ZenStack plugin for generating SWR hooks",
66
"main": "index.js",
77
"repository": {

packages/plugins/swr/src/generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function generateModelHooks(project: Project, outDir: string, model: DataModel,
5959
});
6060
sf.addStatements([
6161
`import { useContext } from 'react';`,
62-
`import { RequestHandlerContext, type RequestOptions, type PickEnumerable } from '@zenstackhq/swr/runtime';`,
62+
`import { RequestHandlerContext, type RequestOptions, type PickEnumerable, type CheckSelect } from '@zenstackhq/swr/runtime';`,
6363
`import * as request from '@zenstackhq/swr/runtime';`,
6464
]);
6565

@@ -82,7 +82,7 @@ function generateModelHooks(project: Project, outDir: string, model: DataModel,
8282
if (mapping.create || (mapping as any).createOne) {
8383
const argsType = `Prisma.${model.name}CreateArgs`;
8484
const inputType = `Prisma.SelectSubset<T, ${argsType}>`;
85-
const returnType = `Prisma.CheckSelect<T, ${model.name}, Prisma.${model.name}GetPayload<T>>`;
85+
const returnType = `CheckSelect<T, ${model.name}, Prisma.${model.name}GetPayload<T>>`;
8686
mutationFuncs.push(
8787
generateMutation(useMutation, model, 'post', 'create', argsType, inputType, returnType, true)
8888
);

packages/plugins/tanstack-query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/tanstack-query",
33
"displayName": "ZenStack plugin for generating tanstack-query hooks",
4-
"version": "1.0.0-beta.15",
4+
"version": "1.0.0-beta.16",
55
"description": "ZenStack plugin for generating tanstack-query hooks",
66
"main": "index.js",
77
"exports": {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function generateMutationHook(
107107

108108
const argsType = `Prisma.${model}${capOperation}Args`;
109109
const inputType = `Prisma.SelectSubset<T, ${argsType}>`;
110-
let returnType = overrideReturnType ?? `Prisma.CheckSelect<T, ${model}, Prisma.${model}GetPayload<T>>`;
110+
let returnType = overrideReturnType ?? `CheckSelect<T, ${model}, Prisma.${model}GetPayload<T>>`;
111111
if (checkReadBack) {
112112
returnType = `(${returnType} | undefined )`;
113113
}
@@ -414,7 +414,7 @@ function makeGetContext(target: TargetFramework) {
414414
function makeBaseImports(target: TargetFramework) {
415415
const shared = [
416416
`import { query, postMutation, putMutation, deleteMutation } from '@zenstackhq/tanstack-query/runtime/${target}';`,
417-
`import type { PickEnumerable } from '@zenstackhq/tanstack-query/runtime';`,
417+
`import type { PickEnumerable, CheckSelect } from '@zenstackhq/tanstack-query/runtime';`,
418418
];
419419
switch (target) {
420420
case 'react':

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-beta.15",
4+
"version": "1.0.0-beta.16",
55
"description": "ZenStack plugin for tRPC",
66
"main": "index.js",
77
"repository": {

packages/plugins/trpc/src/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function createAppRouter(
9595
{
9696
namedImports: ['PrismaClient'],
9797
moduleSpecifier: prismaImport,
98+
isTypeOnly: true,
9899
},
99100
{
100101
namedImports: ['createRouterFactory', 'AnyRouter'],

0 commit comments

Comments
 (0)