-
-
Notifications
You must be signed in to change notification settings - Fork 123
merge dev to main (v2.6.0) #1732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ab261ae
8b56d7d
1395892
1ea8e55
7880bad
f2a3686
57652a1
cb68815
738bba6
64198a3
b8d8902
23c87eb
e72fbd1
1a8b6b4
9fb8d5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ plugins { | |
} | ||
|
||
group = "dev.zenstack" | ||
version = "2.5.1" | ||
version = "2.6.0" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ function getPrismaOperationTypes(model: string, operation: string) { | |
|
||
let argsType: string; | ||
let resultType: string; | ||
const argsOptional = ['findMany', 'findFirst', 'findFirstOrThrow', 'createMany', 'deleteMany', 'count'].includes( | ||
operation | ||
); | ||
|
||
switch (operation) { | ||
case 'findUnique': | ||
|
@@ -178,7 +181,7 @@ function getPrismaOperationTypes(model: string, operation: string) { | |
throw new PluginError(name, `Unsupported operation: "${operation}"`); | ||
} | ||
|
||
return { genericBase, argsType, resultType }; | ||
return { genericBase, argsType, resultType, argsOptional }; | ||
} | ||
|
||
/** | ||
|
@@ -192,22 +195,23 @@ export function generateRouterTyping( | |
version: string | ||
) { | ||
const procType = getProcedureTypeByOpName(baseOpType); | ||
const { genericBase, argsType, resultType } = getPrismaOperationTypes(modelName, opType); | ||
const { genericBase, argsType, argsOptional, resultType } = getPrismaOperationTypes(modelName, opType); | ||
const errorType = `TRPCClientErrorLike<AppRouter>`; | ||
const inputOptional = argsOptional ? '?' : ''; | ||
Comment on lines
+198
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure Optional Input Handling for Mutations Currently, Apply this diff to include optional input handling in mutations: if (procType === 'query') {
// Existing code for queries
} else if (procType === 'mutation') {
+ const inputOptional = argsOptional ? '?' : '';
writer.writeLine(\`
useMutation: <T extends \${genericBase}>(opts?: UseTRPCMutationOptions<
\${genericBase},
\${errorType},
\${resultType},
Context
>,) =>
Omit<UseTRPCMutationResult<\${resultType}, \${errorType}, \${argsType}, Context>, 'mutateAsync'> & {
mutateAsync:
+ <T extends \${genericBase}>(variables\${inputOptional}: T, opts?: UseTRPCMutationOptions<T, \${errorType}, \${resultType}, Context>) => Promise<\${resultType}>
};
\`);
}
|
||
|
||
writer.block(() => { | ||
if (procType === 'query') { | ||
if (version === 'v10') { | ||
writer.writeLine(` | ||
useQuery: <T extends ${genericBase}, TData = ${resultType}>( | ||
input: ${argsType}, | ||
input${inputOptional}: ${argsType}, | ||
opts?: UseTRPCQueryOptions<string, T, ${resultType}, TData, Error> | ||
) => UseTRPCQueryResult< | ||
TData, | ||
${errorType} | ||
>; | ||
useInfiniteQuery: <T extends ${genericBase}>( | ||
input: Omit<${argsType}, 'cursor'>, | ||
input${inputOptional}: Omit<${argsType}, 'cursor'>, | ||
opts?: UseTRPCInfiniteQueryOptions<string, T, ${resultType}, Error> | ||
) => UseTRPCInfiniteQueryResult< | ||
${resultType}, | ||
|
@@ -217,26 +221,26 @@ export function generateRouterTyping( | |
} else { | ||
writer.writeLine(` | ||
useQuery: <T extends ${genericBase}, TData = ${resultType}>( | ||
input: ${argsType}, | ||
input${inputOptional}: ${argsType}, | ||
opts?: UseTRPCQueryOptions<${resultType}, TData, Error> | ||
) => UseTRPCQueryResult< | ||
TData, | ||
${errorType} | ||
>; | ||
useInfiniteQuery: <T extends ${genericBase}>( | ||
input: Omit<${argsType}, 'cursor'>, | ||
input${inputOptional}: Omit<${argsType}, 'cursor'>, | ||
opts?: UseTRPCInfiniteQueryOptions<T, ${resultType}, Error> | ||
) => UseTRPCInfiniteQueryResult< | ||
${resultType}, | ||
${errorType}, | ||
T | ||
>; | ||
useSuspenseQuery: <T extends ${genericBase}, TData = ${resultType}>( | ||
input: ${argsType}, | ||
input${inputOptional}: ${argsType}, | ||
opts?: UseTRPCSuspenseQueryOptions<${resultType}, TData, Error> | ||
) => UseTRPCSuspenseQueryResult<TData, ${errorType}>; | ||
useSuspenseInfiniteQuery: <T extends ${genericBase}>( | ||
input: Omit<${argsType}, 'cursor'>, | ||
input${inputOptional}: Omit<${argsType}, 'cursor'>, | ||
opts?: UseTRPCSuspenseInfiniteQueryOptions<T, ${resultType}, Error> | ||
) => UseTRPCSuspenseInfiniteQueryResult<${resultType}, ${errorType}, T>; | ||
`); | ||
|
@@ -298,10 +302,10 @@ export const getInputSchemaByOpName = (opName: string, modelName: string) => { | |
inputType = `$Schema.${capModelName}InputSchema.findUnique`; | ||
break; | ||
case 'findFirst': | ||
inputType = `$Schema.${capModelName}InputSchema.findFirst`; | ||
inputType = `$Schema.${capModelName}InputSchema.findFirst.optional()`; | ||
break; | ||
case 'findMany': | ||
inputType = `$Schema.${capModelName}InputSchema.findMany`; | ||
inputType = `$Schema.${capModelName}InputSchema.findMany.optional()`; | ||
break; | ||
case 'findRaw': | ||
inputType = `$Schema.${capModelName}InputSchema.findRawObject`; | ||
|
@@ -310,7 +314,7 @@ export const getInputSchemaByOpName = (opName: string, modelName: string) => { | |
inputType = `$Schema.${capModelName}InputSchema.create`; | ||
break; | ||
case 'createMany': | ||
inputType = `$Schema.${capModelName}InputSchema.createMany`; | ||
inputType = `$Schema.${capModelName}InputSchema.createMany.optional()`; | ||
break; | ||
case 'deleteOne': | ||
inputType = `$Schema.${capModelName}InputSchema.delete`; | ||
|
@@ -319,7 +323,7 @@ export const getInputSchemaByOpName = (opName: string, modelName: string) => { | |
inputType = `$Schema.${capModelName}InputSchema.update`; | ||
break; | ||
case 'deleteMany': | ||
inputType = `$Schema.${capModelName}InputSchema.deleteMany`; | ||
inputType = `$Schema.${capModelName}InputSchema.deleteMany.optional()`; | ||
break; | ||
case 'updateMany': | ||
inputType = `$Schema.${capModelName}InputSchema.updateMany`; | ||
|
@@ -337,7 +341,7 @@ export const getInputSchemaByOpName = (opName: string, modelName: string) => { | |
inputType = `$Schema.${capModelName}InputSchema.groupBy`; | ||
break; | ||
case 'count': | ||
inputType = `$Schema.${capModelName}InputSchema.count`; | ||
inputType = `$Schema.${capModelName}InputSchema.count.optional()`; | ||
break; | ||
default: | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider Including 'aggregate' and 'groupBy' in Optional Arguments
The
argsOptional
array currently includes operations that can be invoked without arguments. However, both'aggregate'
and'groupBy'
operations can also be called without any parameters. Consider adding them to the list to ensure consistent handling of optional arguments.Apply this diff to include
'aggregate'
and'groupBy'
: