-
Notifications
You must be signed in to change notification settings - Fork 1
technical/apicraft/tanstack into release/apicraft/1.0.0 π add tanstack plugin #12
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
base: release/apicraft/1.0.0
Are you sure you want to change the base?
Conversation
release/apicraft/1.0.0 into main π support name by operation id and group by tags
release/apicraft/1.0.0 π use relative paths, add default tag
| const instanceFile = plugin.createFile({ | ||
| id: 'fetchesInstance', | ||
| path: normalizePath(`${plugin.output}/instance`) | ||
| path: nodePath.normalize(`${plugin.output}/instance`) |
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.
Ρ Π½ΠΎΠ΄Ρ Π΅ΡΡΡ ΡΠ΄ΠΎΠ±Π½ΡΠΉ ΠΌΠ΅ΡΠΎΠ΄ ΠΊΠΎΡΠΎΡΡΠΉ Π΄Π΅Π»Π°Π΅Ρ ΡΠΎΠΆΠ΅ ΡΠ°ΠΌΠΎΠ΅ ΠΈ Π΄Π°ΠΆΠ΅ Π±ΠΎΠ»ΡΡΠ΅
| ), | ||
| undefined | ||
| !requestHasRequiredParams | ||
| ? ts.factory.createObjectLiteralExpression([], false) |
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.
Π΅ΡΠ»ΠΈ Π² Π·Π°ΠΏΡΠΎΡΠ΅ Π½Π΅Ρ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΡ
ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠ² ΡΠΎ Π΄Π΅Π»Π°Π΅ΠΌ ΠΏΠΎ Π΄Π΅ΡΠΎΠ»ΡΡ ΠΏΡΡΡΠΎΠΉ ΠΊΠΎΠ½ΡΠΈΠ³ ΡΡΠΎΠ±Ρ ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΠ»ΠΎ Π²ΡΠ·ΡΠ²Π°ΡΡ ΡΡΠ½ΠΊΡΠΈΡ Π±Π΅Π· ΠΏΡΠΎΠΊΠΈΠ΄ΡΠ²Π°Π½ΠΈΡ ΠΊΠΎΠ½ΡΠΈΠ³Π° getUsers()
|
|
||
| requestFilePaths.forEach((requestFilePath) => { | ||
| generateQueryHookFile({ plugin, requestFilePath, request, requestName }); | ||
| generateMutationHookFile({ plugin, requestFilePath, request, requestName }); |
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.
Π΄ΠΎΠ²ΠΎΠ»ΡΠ½ΠΎ ΠΌΠ½ΠΎΠ³ΠΎ ΠΏΠΎΡΠ²Π»ΡΠ΅ΡΡΡ ΡΡΠ»ΠΎΠ²ΠΈΠΉ ΠΈ Π½Π΅ΠΊΡΠ°ΡΠΈΠ²ΡΡ ΡΠ΅ΡΠ½Π°ΡΠ½ΠΈΠΊΠΎΠ² Π΅ΡΠ»ΠΈ ΠΏΡΡΠ°ΡΡΡΡ ΡΠ΄Π΅Π»Π°ΡΡ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΡ ΡΡΠ°Π·Ρ Π½Π° Π΄Π²Π° ΠΊΠ΅ΠΉΡΠ° ΠΏΠΎΡΡΠΎΠΌΡ ΡΠ°Π·Π½Π΅Ρ Π½Π° Π΄Π²Π΅ ΡΡΠ½ΠΊΡΠΈΠΈ. ΠΠ»ΡΡ Π΅ΡΠ΅ ΠΏΠΎΡΠ²ΠΈΡΡΡ infinite query ΠΈ ΡΠ°ΠΌ Π²ΠΎΠΎΠ±ΡΠ΅ Π±ΡΠ΄ΡΡ Π΄ΡΡΠ³ΠΈΠ΅ ΠΏΠΎΠ»Ρ
ΠΠ»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π·Π°ΠΏΡΠΎΡΡ Π³Π΅Π½Π΅ΡΠΈΠΌ ΡΡΠ°Π·Ρ ΠΈ ΠΊΠ²Π΅ΡΠΈ ΠΈ ΠΌΡΡΠ°ΡΠΈΡ, Ρ Π²ΠΈΠ΄Π΅Π» ΠΌΠ½ΠΎΠ³ΠΎ Π²ΠΎΠΏΡΠΎΡΠΎΠ² ΠΊ orval ΠΈ Π΄ΡΡΠ³ΠΈΠΌ Π³Π΅Π½Π΅ΡΠ°ΡΠΎΡΠ°ΠΌ ΠΏΠΎΡΠ΅ΠΌΡ ΠΌΠΎΠ» Π½Π΅Π»ΡΠ·Ρ ΡΠ³Π΅Π½Π΅ΡΠΈΡΡ ΠΊΠ²Π΅ΡΠΈ Π΄Π»Ρ post Π·Π°ΠΏΡΠΎΡΠ° ΠΈΠ»ΠΈ ΠΌΡΡΠ°ΡΠΈΡ Π΄Π»Ρ get (ΡΠ°ΠΊΠΈΠ΅ ΠΊΠ΅ΠΉΡΡ Π΅ΡΡΡ Π±ΡΠΊΠ²Π°Π»ΡΠ½ΠΎ Π½Π° ΠΊΠΏΠΊ). ΠΠΎΡΡΠΎΠΌΡ Π½Π°Π΄ΠΎ ΠΏΠΎΠ΄Π΄Π΅ΠΆΡΠ°ΡΡ ΠΈ ΡΠΎ ΠΈ ΡΠΎ, ΠΌΠ± Π² ΠΊΠΎΠ½ΡΠΈΠ³ Π²ΡΠ½Π΅ΡΡΠΈ Π½Π°ΡΡΡΠΎΠΉΠΊΡ Π΄Π»Ρ ΡΡΠΎΠ³ΠΎ Π»ΠΈΠ±ΠΎ ΠΏΡΠΎΡΡΠΎ Π²ΡΠ΅Π³Π΄Π° Π³Π΅ΡΠ΅Π½ΠΈΡΡ ΠΈ ΡΠΎ ΠΈ ΡΠΎ
| query?: Omit<UseQueryOptions<Awaited<ReturnType<TFunc>>, never>, 'queryKey'>; | ||
| } & (IsParamsRequired<TFunc> extends true | ||
| ? { request: NonNullable<Parameters<TFunc>[0]> } | ||
| : { request?: NonNullable<Parameters<TFunc>[0]> }); |
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.
Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΠ» Π²Π°ΡΠΈΠ°Π½Ρ Ρ ΠΊΠΏΠΊ, ΡΠ°ΠΌ Π½Π΅ Π±ΡΠ»ΠΎ ΡΡΡΠ΅Π½ΠΎ ΡΡΠΎ Π·Π°ΠΏΡΠΎΡ ΠΌΠΎΠΆΠ΅Ρ ΠΈΠΌΠ΅ΡΡ/Π½Π΅ ΠΈΠΌΠ΅ΡΡ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΠ΅ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ΠΈ ΠΎΡ ΡΡΠΎΠ³ΠΎ Π΄ΠΎΠ»ΠΆΠ½Π° ΠΌΠ΅Π½ΡΡΡΡΡ ΡΠΈΠΏΠΈΠ·Π°ΡΠΈΡ
| queryKey: ['getUserByUsername', settings.request.path?.username], | ||
| queryFn: async () => getUserByUsername({ ...settings.request }), | ||
| ...settings.query | ||
| }); |
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.
ΠΏΡΠΈΠΌΠ΅Ρ ΠΊΠ°ΠΊ Π²ΡΠ³Π»ΡΠ΄ΠΈΡ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΡ
| # Card standard | ||
| generated | ||
| !generated |
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.
card ΡΡΠ°Π½Π΄Π°Ρ ΠΌΠΎΠΆΠ½ΠΎ ΠΈ Π²ΡΠΏΠΈΠ»ΠΈΡΡ )))
| nameBy: z.enum(['path', 'operationId']).optional(), | ||
| groupBy: z.enum(['path', 'tag']).optional() | ||
| groupBy: z.enum(['path', 'tag']).optional(), | ||
| hooks: z.enum(['tanstack']).optional() |
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.
Π²ΠΎΡ ΡΡΡ ΡΠΆΠ΅ tanstack Ρ Π΄ΡΠΌΠ°Ρ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡ ΠΏΠ»Π°Π³ΠΈΠ½ΠΎΠΌ, Π° Π½Π΅ ΡΠ΅ΡΠ΅Π· ΠΏΠΎΠ»Π΅ hooks
| normalizePath(`${plugin.output}/requests/${request.path}/${request.method.toLowerCase()}`) | ||
| ); | ||
| } | ||
| const requestFilePaths = getRequestFilePaths({ |
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.
requestFilePath = getRequestFilePath
| const requestHasPathParam = !!Object.keys(request.parameters?.path ?? {}).length; | ||
| const requestHasRequiredParam = checkRequestHasRequiredParam(request); |
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.
ΠΠΎΠΆΠ½ΠΎ ΡΡΠ½ΠΊΡΠΈΡ Π΄ΠΎΡΠ°Π±ΠΎΡΠ°ΡΡ< ΡΡΠΎ ΠΎΠ½Π° Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π»Π° ΠΌΠ½ΠΎΠ³ΠΎ ΠΊΠ»ΡΡΠ΅ΠΉ ΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠΆΠ΅ ΠΈΡ , Π° ΡΠΎ ΠΎΠ΄Π½Π° ΠΈ ΡΠ°ΠΆΠ΅ ΠΏΡΠΎΠ²Π΅ΡΠΊΠ°
const result.hasParams result.hasQuery ΠΈ ΡΠ΄
|
|
||
| export const handler: TanstackPlugin['Handler'] = ({ plugin }) => { | ||
| plugin.forEach('operation', (event) => { | ||
| if (event.type !== 'operation') return; |
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.
ΡΡΠΏΠΎΠΉ Π²ΠΎΠΏΡΠΎΡ, Π½ΠΎ ΡΠ°ΠΊΠΎΠ΅ ΡΠ΅Π°Π»ΡΠ½ΠΎ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ ?
| ts.factory.createStringLiteral('@siberiacancode/apicraft') | ||
| ); | ||
|
|
||
| // import type { getUserByUsername } from './getUserByUsername.gen'; |
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.
getUserByUsername -> requestName
| const requestPathParams = getRequestPathParams(request); | ||
| const requestHasRequiredParam = checkRequestHasRequiredParam(request); | ||
|
|
||
| // const useGetUserByUsernameQuery = (settings: TanstackQuerySettings<typeof getUserByUsername>) => useQuery |
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.
useMethodRequestNameQuery
| ts.factory.createCallExpression(ts.factory.createIdentifier('useQuery'), undefined, [ | ||
| ts.factory.createObjectLiteralExpression( | ||
| [ | ||
| // queryKey: ['getUserByUsername', settings.request.path.username] |
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.
['methodRequestName', ...settings.request.path]
| ts.factory.createArrayLiteralExpression( | ||
| [ | ||
| ts.factory.createStringLiteral(requestName), | ||
| ...requestPathParams.map((requestPathParam) => |
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.
Π½Π΅ ΡΠΎΠ»ΡΠΊΠΎ path, Π΅ΡΠ΅ query ΠΆΠΈΡΡ Π°Π»Ρ Π»ΠΈΠΌΠΈΡ ΠΈ ΡΠ΄
|
|
||
| import { getUserByUsername } from '../../../requests/users/{username}/get.gen'; | ||
|
|
||
| export const useGetUserByUsernameQuery = ( |
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.
ΠΏΠΎ ΡΠΈΠΏΠΈΠ·Π°ΡΠΈΠΈ Π΅ΡΠ΅ Π½Π΅ ΠΏΠΎΠ½ΡΠ», Π° Π² ΠΈΡΠΎΠ³Π΅ Π΅ΡΡΡ ΠΏΠΎΠ»Ρ query request ΠΈΠ»ΠΈ ΠΊΠ°ΠΊ
No description provided.