Skip to content

Commit

Permalink
Merge pull request #932 from hey-api/fix/mutation-types
Browse files Browse the repository at this point in the history
fix: cherry pick keys in mutation page param type
  • Loading branch information
mrlubos authored Aug 14, 2024
2 parents 21c2c05 + cdf01e8 commit ef209e3
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-turtles-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: cherry pick keys in mutation page param type
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const createQueryKeyType = ({ file }: { file: Files[keyof Files] }) => {
compiler.typeIntersectNode({
types: [
compiler.typeReferenceNode({
typeName: `Pick<TOptions, '${getClientBaseUrlKey()}' | 'body' | 'headers' | 'path' | 'query'>`,
typeName: `Pick<${TOptionsType}, '${getClientBaseUrlKey()}' | 'body' | 'headers' | 'path' | 'query'>`,
}),
compiler.typeInterfaceNode({ properties }),
],
Expand Down Expand Up @@ -697,7 +697,7 @@ export const handler: PluginDefinition['handler'] = ({
const isRequired = isOperationParameterRequired(operation.parameters);

const typeQueryKey = `${queryKeyName}<${typeData}>`;
const typePageObjectParam = `${typeQueryKey}[0]`;
const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`;
const typePageParam = `${paginationField.base} | ${typePageObjectParam}`;

const expression = compiler.arrowFunction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ export const callWithParametersOptions = (options: Options<CallWithParametersDat
]
}); };

export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | QueryKey<Options<CallWithParametersData>>[0]>(
export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<CallWithParametersData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
cursor: pageParam
}
Expand Down Expand Up @@ -311,12 +311,12 @@ export const getCallWithOptionalParamOptions = (options: Options<GetCallWithOpti
]
}); };

export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | QueryKey<Options<GetCallWithOptionalParamData>>[0]>(
export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<GetCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
page: pageParam
}
Expand Down Expand Up @@ -363,12 +363,12 @@ export const postCallWithOptionalParamOptions = (options: Options<PostCallWithOp
]
}); };

export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | QueryKey<Options<PostCallWithOptionalParamData>>[0]>(
export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<PostCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
body: {
offset: pageParam
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ export const callWithParametersOptions = (options: Options<CallWithParametersDat
]
}); };

export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | QueryKey<Options<CallWithParametersData>>[0]>(
export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<CallWithParametersData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
cursor: pageParam
}
Expand Down Expand Up @@ -311,12 +311,12 @@ export const getCallWithOptionalParamOptions = (options: Options<GetCallWithOpti
]
}); };

export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | QueryKey<Options<GetCallWithOptionalParamData>>[0]>(
export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<GetCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
page: pageParam
}
Expand Down Expand Up @@ -363,12 +363,12 @@ export const postCallWithOptionalParamOptions = (options: Options<PostCallWithOp
]
}); };

export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | QueryKey<Options<PostCallWithOptionalParamData>>[0]>(
export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<PostCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
body: {
offset: pageParam
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ export const callWithParametersOptions = (options: Options<CallWithParametersDat
]
}); };

export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | QueryKey<Options<CallWithParametersData>>[0]>(
export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<CallWithParametersData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
cursor: pageParam
}
Expand Down Expand Up @@ -311,12 +311,12 @@ export const getCallWithOptionalParamOptions = (options: Options<GetCallWithOpti
]
}); };

export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | QueryKey<Options<GetCallWithOptionalParamData>>[0]>(
export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<GetCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
page: pageParam
}
Expand Down Expand Up @@ -363,12 +363,12 @@ export const postCallWithOptionalParamOptions = (options: Options<PostCallWithOp
]
}); };

export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | QueryKey<Options<PostCallWithOptionalParamData>>[0]>(
export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<PostCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
body: {
offset: pageParam
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ export const callWithParametersOptions = (options: Options<CallWithParametersDat
]
}); };

export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | QueryKey<Options<CallWithParametersData>>[0]>(
export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<CallWithParametersData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
cursor: pageParam
}
Expand Down Expand Up @@ -311,12 +311,12 @@ export const getCallWithOptionalParamOptions = (options: Options<GetCallWithOpti
]
}); };

export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | QueryKey<Options<GetCallWithOptionalParamData>>[0]>(
export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, AxiosError<DefaultError>, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<GetCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
page: pageParam
}
Expand Down Expand Up @@ -363,12 +363,12 @@ export const postCallWithOptionalParamOptions = (options: Options<PostCallWithOp
]
}); };

export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | QueryKey<Options<PostCallWithOptionalParamData>>[0]>(
export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, AxiosError<PostCallWithOptionalParamError>, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<PostCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
body: {
offset: pageParam
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ export const callWithParametersOptions = (options: Options<CallWithParametersDat
]
}); };

export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, DefaultError, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | QueryKey<Options<CallWithParametersData>>[0]>(
export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, DefaultError, InfiniteData<void>, QueryKey<Options<CallWithParametersData>>, string | Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<CallWithParametersData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<CallWithParametersData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
cursor: pageParam
}
Expand Down Expand Up @@ -310,12 +310,12 @@ export const getCallWithOptionalParamOptions = (options: Options<GetCallWithOpti
]
}); };

export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, DefaultError, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | QueryKey<Options<GetCallWithOptionalParamData>>[0]>(
export const getCallWithOptionalParamInfiniteOptions = (options: Options<GetCallWithOptionalParamData>) => { return infiniteQueryOptions<void, DefaultError, InfiniteData<void>, QueryKey<Options<GetCallWithOptionalParamData>>, number | Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<GetCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<GetCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
query: {
page: pageParam
}
Expand Down Expand Up @@ -362,12 +362,12 @@ export const postCallWithOptionalParamOptions = (options: Options<PostCallWithOp
]
}); };

export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, PostCallWithOptionalParamError, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | QueryKey<Options<PostCallWithOptionalParamData>>[0]>(
export const postCallWithOptionalParamInfiniteOptions = (options: Options<PostCallWithOptionalParamData>) => { return infiniteQueryOptions<PostCallWithOptionalParamResponse, PostCallWithOptionalParamError, InfiniteData<PostCallWithOptionalParamResponse>, QueryKey<Options<PostCallWithOptionalParamData>>, number | Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
queryFn: async ({ pageParam, queryKey }) => {
// @ts-ignore
const page: QueryKey<Options<PostCallWithOptionalParamData>>[0] = typeof pageParam === "object" ? pageParam : {
const page: Pick<QueryKey<Options<PostCallWithOptionalParamData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === "object" ? pageParam : {
body: {
offset: pageParam
}
Expand Down
Loading

0 comments on commit ef209e3

Please sign in to comment.