generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9355259
commit 7fc909a
Showing
14 changed files
with
145 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
import type { UpdatePetMutationResponse, UpdatePetMutationRequest, AddPetMutationResponse, AddPetMutationRequest, FindPetsByStatusQueryResponse, FindPetsByTagsQueryResponse, GetPetByIdQueryResponse, UpdatePetWithFormMutationResponse, DeletePetMutationResponse, UploadFileMutationResponse, UploadFileMutationRequest, GetInventoryQueryResponse, PlaceOrderMutationResponse, PlaceOrderMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatchMutationRequest, GetOrderByIdQueryResponse, DeleteOrderMutationResponse, CreateUserMutationResponse, CreateUserMutationRequest, CreateUsersWithListInputMutationResponse, CreateUsersWithListInputMutationRequest, LoginUserQueryResponse, LogoutUserQueryResponse, GetUserByNameQueryResponse, UpdateUserMutationResponse, UpdateUserMutationRequest, DeleteUserMutationResponse } from "./index"; | ||
import type { UseMutationOptions } from "@tanstack/react-query"; | ||
import type { | ||
UpdatePetMutationResponse, | ||
UpdatePetMutationRequest, | ||
AddPetMutationResponse, | ||
AddPetMutationRequest, | ||
FindPetsByStatusQueryResponse, | ||
FindPetsByTagsQueryResponse, | ||
GetPetByIdQueryResponse, | ||
UpdatePetWithFormMutationResponse, | ||
DeletePetMutationResponse, | ||
UploadFileMutationResponse, | ||
UploadFileMutationRequest, | ||
GetInventoryQueryResponse, | ||
PlaceOrderMutationResponse, | ||
PlaceOrderMutationRequest, | ||
PlaceOrderPatchMutationResponse, | ||
PlaceOrderPatchMutationRequest, | ||
GetOrderByIdQueryResponse, | ||
DeleteOrderMutationResponse, | ||
CreateUserMutationResponse, | ||
CreateUserMutationRequest, | ||
CreateUsersWithListInputMutationResponse, | ||
CreateUsersWithListInputMutationRequest, | ||
LoginUserQueryResponse, | ||
LogoutUserQueryResponse, | ||
GetUserByNameQueryResponse, | ||
UpdateUserMutationResponse, | ||
UpdateUserMutationRequest, | ||
DeleteUserMutationResponse, | ||
} from './index' | ||
import type { UseMutationOptions } from '@tanstack/react-query' | ||
|
||
export type Invalidations = { | ||
"useUpdatePetHook": UseMutationOptions<UpdatePetMutationResponse, unknown, UpdatePetMutationRequest>["onSuccess"]; | ||
"useAddPetHook": UseMutationOptions<AddPetMutationResponse, unknown, AddPetMutationRequest>["onSuccess"]; | ||
"useFindPetsByStatusHook": UseMutationOptions<FindPetsByStatusQueryResponse, unknown, void>["onSuccess"]; | ||
"useFindPetsByTagsHook": UseMutationOptions<FindPetsByTagsQueryResponse, unknown, void>["onSuccess"]; | ||
"useGetPetByIdHook": UseMutationOptions<GetPetByIdQueryResponse, unknown, void>["onSuccess"]; | ||
"useUpdatePetWithFormHook": UseMutationOptions<UpdatePetWithFormMutationResponse, unknown, void>["onSuccess"]; | ||
"useDeletePetHook": UseMutationOptions<DeletePetMutationResponse, unknown, void>["onSuccess"]; | ||
"useUploadFileHook": UseMutationOptions<UploadFileMutationResponse, unknown, UploadFileMutationRequest>["onSuccess"]; | ||
"useGetInventoryHook": UseMutationOptions<GetInventoryQueryResponse, unknown, void>["onSuccess"]; | ||
"usePlaceOrderHook": UseMutationOptions<PlaceOrderMutationResponse, unknown, PlaceOrderMutationRequest>["onSuccess"]; | ||
"usePlaceOrderPatchHook": UseMutationOptions<PlaceOrderPatchMutationResponse, unknown, PlaceOrderPatchMutationRequest>["onSuccess"]; | ||
"useGetOrderByIdHook": UseMutationOptions<GetOrderByIdQueryResponse, unknown, void>["onSuccess"]; | ||
"useDeleteOrderHook": UseMutationOptions<DeleteOrderMutationResponse, unknown, void>["onSuccess"]; | ||
"useCreateUserHook": UseMutationOptions<CreateUserMutationResponse, unknown, CreateUserMutationRequest>["onSuccess"]; | ||
"useCreateUsersWithListInputHook": UseMutationOptions<CreateUsersWithListInputMutationResponse, unknown, CreateUsersWithListInputMutationRequest>["onSuccess"]; | ||
"useLoginUserHook": UseMutationOptions<LoginUserQueryResponse, unknown, void>["onSuccess"]; | ||
"useLogoutUserHook": UseMutationOptions<LogoutUserQueryResponse, unknown, void>["onSuccess"]; | ||
"useGetUserByNameHook": UseMutationOptions<GetUserByNameQueryResponse, unknown, void>["onSuccess"]; | ||
"useUpdateUserHook": UseMutationOptions<UpdateUserMutationResponse, unknown, UpdateUserMutationRequest>["onSuccess"]; | ||
"useDeleteUserHook": UseMutationOptions<DeleteUserMutationResponse, unknown, void>["onSuccess"]; | ||
}; | ||
export type Invalidations = { | ||
'useUpdatePetHook': UseMutationOptions<UpdatePetMutationResponse, unknown, UpdatePetMutationRequest>['onSuccess'] | ||
'useAddPetHook': UseMutationOptions<AddPetMutationResponse, unknown, AddPetMutationRequest>['onSuccess'] | ||
'useFindPetsByStatusHook': UseMutationOptions<FindPetsByStatusQueryResponse, unknown, void>['onSuccess'] | ||
'useFindPetsByTagsHook': UseMutationOptions<FindPetsByTagsQueryResponse, unknown, void>['onSuccess'] | ||
'useGetPetByIdHook': UseMutationOptions<GetPetByIdQueryResponse, unknown, void>['onSuccess'] | ||
'useUpdatePetWithFormHook': UseMutationOptions<UpdatePetWithFormMutationResponse, unknown, void>['onSuccess'] | ||
'useDeletePetHook': UseMutationOptions<DeletePetMutationResponse, unknown, void>['onSuccess'] | ||
'useUploadFileHook': UseMutationOptions<UploadFileMutationResponse, unknown, UploadFileMutationRequest>['onSuccess'] | ||
'useGetInventoryHook': UseMutationOptions<GetInventoryQueryResponse, unknown, void>['onSuccess'] | ||
'usePlaceOrderHook': UseMutationOptions<PlaceOrderMutationResponse, unknown, PlaceOrderMutationRequest>['onSuccess'] | ||
'usePlaceOrderPatchHook': UseMutationOptions<PlaceOrderPatchMutationResponse, unknown, PlaceOrderPatchMutationRequest>['onSuccess'] | ||
'useGetOrderByIdHook': UseMutationOptions<GetOrderByIdQueryResponse, unknown, void>['onSuccess'] | ||
'useDeleteOrderHook': UseMutationOptions<DeleteOrderMutationResponse, unknown, void>['onSuccess'] | ||
'useCreateUserHook': UseMutationOptions<CreateUserMutationResponse, unknown, CreateUserMutationRequest>['onSuccess'] | ||
'useCreateUsersWithListInputHook': UseMutationOptions<CreateUsersWithListInputMutationResponse, unknown, CreateUsersWithListInputMutationRequest>['onSuccess'] | ||
'useLoginUserHook': UseMutationOptions<LoginUserQueryResponse, unknown, void>['onSuccess'] | ||
'useLogoutUserHook': UseMutationOptions<LogoutUserQueryResponse, unknown, void>['onSuccess'] | ||
'useGetUserByNameHook': UseMutationOptions<GetUserByNameQueryResponse, unknown, void>['onSuccess'] | ||
'useUpdateUserHook': UseMutationOptions<UpdateUserMutationResponse, unknown, UpdateUserMutationRequest>['onSuccess'] | ||
'useDeleteUserHook': UseMutationOptions<DeleteUserMutationResponse, unknown, void>['onSuccess'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,62 @@ | ||
import { Editor, Function, File, useFile, usePlugin } from '@kubb/react' | ||
import { useOperations } from '@kubb/swagger/hooks' | ||
import { Editor, Type, File, usePlugin } from '@kubb/react' | ||
import { useOperationHelpers, useOperations, useOas } from '@kubb/swagger/hooks' | ||
import { Operations } from '@kubb/swagger-tanstack-query/components' | ||
import React from 'react' | ||
import { FileMeta, PluginOptions } from '@kubb/swagger-tanstack-query' | ||
import { Operation } from '@kubb/swagger/oas' | ||
import path from 'node:path' | ||
import { usePluginManager } from '@kubb/react' | ||
|
||
export const templates = { | ||
...Operations.templates, | ||
editor: function({ children }: React.ComponentProps<typeof Operations.templates.editor>) { | ||
editor: function({}: React.ComponentProps<typeof Operations.templates.editor>) { | ||
const pluginManager = usePluginManager() | ||
const { key: pluginKey } = usePlugin<PluginOptions>() | ||
const operations = useOperations() | ||
const { getSchemas } = useOas() | ||
const { getOperationName } = useOperationHelpers() | ||
|
||
const root = path.resolve(pluginManager.config.root, pluginManager.config.output.path) | ||
|
||
const imports = operations.map(operation => { | ||
const schemas = getSchemas(operation) | ||
|
||
return [schemas.response?.name, schemas.request?.name] | ||
}).flat().filter(Boolean) | ||
|
||
const invalidations = operations.reduce((acc, operation) => { | ||
const name = getOperationName(operation, { pluginKey, type: 'function' }) | ||
const schemas = getSchemas(operation) | ||
|
||
acc[name] = `UseMutationOptions<${schemas.response.name}, unknown, ${schemas.request?.name || 'void'}>['onSuccess']` | ||
|
||
const file = useFile({ name: 'operations', extName: '.ts', pluginKey }) | ||
return acc | ||
}, {} as Record<string, string>) | ||
|
||
return ( | ||
<Editor language="typescript"> | ||
<File<FileMeta> | ||
baseName={file.baseName} | ||
path={file.path} | ||
meta={file.meta} | ||
baseName={'invalidations.ts'} | ||
path={path.join(root, './invalidations.ts')} | ||
> | ||
<File.Import | ||
name={imports} | ||
path={path.join(root, './index.ts')} | ||
root={path.join(root, './invalidations.ts')} | ||
isTypeOnly | ||
/> | ||
|
||
<File.Import isTypeOnly name={['UseMutationOptions']} path="@tanstack/react-query" /> | ||
<File.Source> | ||
{children} | ||
<Type export name="Invalidations"> | ||
{`{ ${ | ||
Object.keys(invalidations).map(key => { | ||
return `${JSON.stringify(key)}: ${invalidations[key]}` | ||
}) | ||
} }`} | ||
</Type> | ||
</File.Source> | ||
</File> | ||
</Editor> | ||
) | ||
}, | ||
default: function({}: React.ComponentProps<typeof Operations.templates.default>) { | ||
const operations = useOperations() | ||
|
||
return ( | ||
<> | ||
{operations.map((item) => { | ||
return ( | ||
<Function name={item.getOperationId()} export> | ||
return {JSON.stringify(item.path)} | ||
</Function> | ||
) | ||
})} | ||
</> | ||
) | ||
}, | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.