@toktokhan-dev/cli-plugin-gen-api-react-query 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +132 -0
- package/package.json +26 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Toktokhan.dev, Icn
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @toktokhan-dev/cli-plugin-gen-api-react-query
|
|
2
|
+
|
|
3
|
+
[@toktokhan-dev/cli](../../cli/README.md) 의 plugin 입니다.
|
|
4
|
+
openapi json 을 조회해 type 정의된 통신 모듈과, react-query hook 을 만들어 주는 플러그인 입니다. 자세한 내용은 [Tokdocs 공식 문서](https://toktokhan-dev-docs.vercel.app/docs/docs/tokript/Offical%20Plugins/gen-api-react-query)에서 확인 할 수 있습니다.
|
|
5
|
+
|
|
6
|
+
## Preview
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import instance from '@apis/_axios/instance'
|
|
10
|
+
import { useQuery } from '@tanstack/react-query'
|
|
11
|
+
|
|
12
|
+
import { HttpClient, RequestParams } from '../@http-client'
|
|
13
|
+
import { CalenderListType } from '../@types/data-contracts'
|
|
14
|
+
import {
|
|
15
|
+
Parameter,
|
|
16
|
+
QueryHookParams,
|
|
17
|
+
RequestFnReturn,
|
|
18
|
+
} from '../@types/react-query-type'
|
|
19
|
+
|
|
20
|
+
export class CalendarApi<
|
|
21
|
+
SecurityDataType = unknown,
|
|
22
|
+
> extends HttpClient<SecurityDataType> {
|
|
23
|
+
/**
|
|
24
|
+
* No description
|
|
25
|
+
*
|
|
26
|
+
* @tags calendar
|
|
27
|
+
* @name BusinessCalendarList
|
|
28
|
+
* @request GET:/v1/business/{business_id}/calendar/
|
|
29
|
+
* @secure
|
|
30
|
+
*/
|
|
31
|
+
businessCalendarList = (variables: {
|
|
32
|
+
businessId: number
|
|
33
|
+
query: {
|
|
34
|
+
/** 끝 날짜 */
|
|
35
|
+
end_date: string
|
|
36
|
+
/** 시작 날짜 */
|
|
37
|
+
start_date: string
|
|
38
|
+
}
|
|
39
|
+
params?: RequestParams
|
|
40
|
+
}) =>
|
|
41
|
+
this.request<CalenderListType[], any>({
|
|
42
|
+
path: `/v1/business/${variables.businessId}/calendar/`,
|
|
43
|
+
method: 'GET',
|
|
44
|
+
query: variables.query,
|
|
45
|
+
secure: true,
|
|
46
|
+
format: 'json',
|
|
47
|
+
...variables.params,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const calendarApi = new CalendarApi({ instance })
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* QUERY_KEYS
|
|
55
|
+
*/
|
|
56
|
+
export const QUERY_KEY_CALENDAR_API = {
|
|
57
|
+
BUSINESS_CALENDAR_LIST: (
|
|
58
|
+
variables?: Parameter<typeof calendarApi.businessCalendarList>,
|
|
59
|
+
) =>
|
|
60
|
+
['BUSINESS_CALENDAR_LIST', variables].filter(
|
|
61
|
+
(key) => typeof key !== 'undefined',
|
|
62
|
+
),
|
|
63
|
+
BUSINESS_CALENDAR_DAY_LIST: (
|
|
64
|
+
variables?: Parameter<typeof calendarApi.businessCalendarDayList>,
|
|
65
|
+
) =>
|
|
66
|
+
['BUSINESS_CALENDAR_DAY_LIST', variables].filter(
|
|
67
|
+
(key) => typeof key !== 'undefined',
|
|
68
|
+
),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* No description
|
|
73
|
+
*
|
|
74
|
+
* @tags calendar
|
|
75
|
+
* @name BusinessCalendarList
|
|
76
|
+
* @request GET:/v1/business/{business_id}/calendar/
|
|
77
|
+
* @secure */
|
|
78
|
+
|
|
79
|
+
export const useBusinessCalendarListQuery = <
|
|
80
|
+
TData = RequestFnReturn<typeof calendarApi.businessCalendarList>,
|
|
81
|
+
>(
|
|
82
|
+
params: QueryHookParams<typeof calendarApi.businessCalendarList, any, TData>,
|
|
83
|
+
) => {
|
|
84
|
+
const queryKey = QUERY_KEY_CALENDAR_API.BUSINESS_CALENDAR_LIST(
|
|
85
|
+
params.variables,
|
|
86
|
+
)
|
|
87
|
+
return useQuery({
|
|
88
|
+
queryKey,
|
|
89
|
+
queryFn: () => calendarApi.businessCalendarList(params.variables),
|
|
90
|
+
...params?.options,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
npm i -D @toktokhan-dev/cli @toktokhan-dev/cli-plugin-gen-api-react-query
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Register Plugin
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// tok-cli.config.ts
|
|
105
|
+
import { genApi } from '@toktokhan-dev/cli-plugin-gen-api-react-query'
|
|
106
|
+
|
|
107
|
+
const config: RootConfig<{
|
|
108
|
+
plugins: [typeof genApi]
|
|
109
|
+
}> = {
|
|
110
|
+
plugins: [genApi],
|
|
111
|
+
'gen:api': {
|
|
112
|
+
/** 조회할 스웨거의 url 혹은 file(yaml, json) 경로 입니다.*/
|
|
113
|
+
swaggerSchemaUrl: 'https://petstore.swagger.io/v2/swagger.json',
|
|
114
|
+
/** 생성될 파일들이 위치할 경로입니다. */
|
|
115
|
+
output: 'src/generated/openapi',
|
|
116
|
+
/** Api 의 axios 혹은 fetch 요청 instance 주소입니다. */
|
|
117
|
+
instancePath: 'src/configs/axios.ts',
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Run Script
|
|
123
|
+
|
|
124
|
+
`tokript2` 명령어로 각 플러그인으로 등록된 기능들을 사용할 수 있습니다.
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
npx tokript2 gen:api
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Configuration
|
|
131
|
+
|
|
132
|
+
자세한 내용은 [Tokdocs 공식 문서](https://toktokhan-dev-docs.vercel.app/docs/docs/tokript/Offical%20Plugins/gen-api-react-query)에서 확인 할 수 있습니다.
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toktokhan-dev/cli-plugin-gen-api-react-query",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.16",
|
|
4
|
+
"description": "A CLI plugin for generating API hooks with React Query built by TOKTOKHAN.DEV",
|
|
5
|
+
"author": "TOKTOKHAN.DEV <fe-system@toktokhan.dev>",
|
|
6
|
+
"license": "ISC",
|
|
5
7
|
"type": "module",
|
|
8
|
+
"homepage": "https://toktokhan-dev-docs.vercel.app/docs/docs/tokript/Offical%20Plugins/gen-api-react-query",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/TOKTOKHAN-DEV/toktokhan-dev/tree/main/packages/cli-plugins/gen-api-react-query"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/TOKTOKHAN-DEV/toktokhan-dev/issues"
|
|
15
|
+
},
|
|
6
16
|
"main": "dist/index.js",
|
|
7
17
|
"files": [
|
|
8
18
|
"dist",
|
|
@@ -15,20 +25,25 @@
|
|
|
15
25
|
"import": "./dist/index.js"
|
|
16
26
|
}
|
|
17
27
|
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
28
|
+
"keywords": [
|
|
29
|
+
"cli",
|
|
30
|
+
"plugin",
|
|
31
|
+
"react-query",
|
|
32
|
+
"api",
|
|
33
|
+
"generation",
|
|
34
|
+
"toktokhan_dev"
|
|
35
|
+
],
|
|
25
36
|
"dependencies": {
|
|
26
37
|
"eta": "^3.4.0",
|
|
27
38
|
"lodash": "^4.17.21",
|
|
28
39
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
29
40
|
"swagger-typescript-api": "^13.0.3",
|
|
30
|
-
"@toktokhan-dev/cli": "0.0.
|
|
31
|
-
"@toktokhan-dev/node": "0.0.
|
|
41
|
+
"@toktokhan-dev/cli": "0.0.10",
|
|
42
|
+
"@toktokhan-dev/node": "0.0.9"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/lodash": "^4.17.0",
|
|
46
|
+
"@toktokhan-dev/ts-config": "0.0.1"
|
|
32
47
|
},
|
|
33
48
|
"scripts": {
|
|
34
49
|
"build": "rollup -c",
|