Skip to content
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

Refactor swr part2 #1206

Merged
merged 7 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/knowledge-base/how-tos/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type RequestConfig<TData = unknown> = {
url?: string
method: 'get' | 'put' | 'patch' | 'post' | 'delete'
params?: object
data?: TData
data?: TData | FormData
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
signal?: AbortSignal
headers?: HeadersInit
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@shikijs/vitepress-twoslash": "~1.14.1",
"sitemap": "^8.0.0",
"vitepress": "^1.3.4",
"vue": "^3.5.1"
"vue": "^3.5.3"
},
"devDependencies": {
"@kubb/cli": "workspace:*",
Expand All @@ -36,7 +36,7 @@
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:^",
"@types/node": "^20.16.4",
"@types/node": "^20.16.5",
"@types/react": "^18.3.5",
"axios": "^1.7.7",
"react": "^18.3.1",
Expand Down
4 changes: 2 additions & 2 deletions e2e/kubb.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const baseConfig = {
exportType: false,
},
group: { type: 'tag' },
infer: true,
typedSchema: false,
inferred: true,
typed: false,
operations: false,
}),
pluginFaker({
Expand Down
12 changes: 6 additions & 6 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:*",
"@tanstack/react-query": "^5.54.1",
"@tanstack/solid-query": "^5.54.1",
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/vue-query": "^5.54.1",
"@tanstack/react-query": "^5.55.0",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/vue-query": "^5.54.2",
"axios": "^1.7.7",
"msw": "^2.4.2",
"msw": "^2.4.3",
"react": "^18.3.1",
"solid-js": "^1.8.22",
"svelte": "^3.59.2",
"swr": "^2.2.5",
"tsup": "^8.2.4",
"vue": "^3.5.1",
"vue": "^3.5.3",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type RequestConfig<TData = unknown> = {
url?: string
method: 'get' | 'put' | 'patch' | 'post' | 'delete'
params?: unknown
data?: TData
data?: TData | FormData
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
signal?: AbortSignal
headers?: AxiosRequestConfig['headers']
Expand Down
6 changes: 4 additions & 2 deletions examples/advanced/configs/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { pluginClient } from '@kubb/plugin-client'
import { pluginFaker } from '@kubb/plugin-faker'
import { pluginMsw } from '@kubb/plugin-msw'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginRedoc } from '@kubb/plugin-redoc'
import { pluginSwr } from '@kubb/plugin-swr'
import { pluginTanstackQuery } from '@kubb/plugin-tanstack-query'
import { pluginTs } from '@kubb/plugin-ts'
Expand All @@ -31,6 +32,7 @@ export default defineConfig(() => {
},
validate: false,
}),
pluginRedoc(),
pluginTs({
output: {
path: 'models/ts',
Expand Down Expand Up @@ -103,7 +105,7 @@ export default defineConfig(() => {
group: { type: 'tag' },
client: {
importPath: '../../../../swr-client.ts',
dataReturnType: 'full',
dataReturnType: 'data',
},
parser: 'zod',
}),
Expand Down Expand Up @@ -135,7 +137,7 @@ export default defineConfig(() => {
],
group: { type: 'tag' },
dateType: 'stringOffset',
infer: true,
inferred: true,
operations: false,
}),
pluginFaker({
Expand Down
13 changes: 7 additions & 6 deletions examples/advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@
"@kubb/plugin-faker": "workspace:*",
"@kubb/plugin-msw": "workspace:*",
"@kubb/plugin-oas": "workspace:*",
"@kubb/plugin-redoc": "workspace:*",
"@kubb/plugin-swr": "workspace:*",
"@kubb/plugin-tanstack-query": "workspace:*",
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:*",
"@tanstack/query-core": "^5.54.1",
"@tanstack/react-query": "^5.54.1",
"@tanstack/solid-query": "^5.54.1",
"@tanstack/svelte-query": "^5.54.1",
"@tanstack/vue-query": "^5.54.1",
"@tanstack/react-query": "^5.55.0",
"@tanstack/solid-query": "^5.54.2",
"@tanstack/svelte-query": "^5.54.2",
"@tanstack/vue-query": "^5.54.2",
"axios": "^1.7.7",
"msw": "^2.4.2",
"msw": "^2.4.3",
"react": "^18.3.1",
"solid-js": "^1.8.22",
"svelte": "^3.59.2",
"swr": "^2.2.5",
"vue": "^3.5.1",
"vue": "^3.5.3",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/axios-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type RequestConfig<TData = unknown> = {
url?: string
method: 'get' | 'put' | 'patch' | 'post' | 'delete'
params?: unknown
data?: TData
data?: TData | FormData
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
signal?: AbortSignal
headers?: AxiosRequestConfig['headers']
Expand Down
13 changes: 5 additions & 8 deletions examples/advanced/src/gen/clients/axios/petService/addPet.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { AddPetMutationRequest, AddPetMutationResponse } from '../../../models/ts/petController/AddPet.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../../../models/ts/petController/AddPet.ts'

/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* @link /pet
*/
export async function addPet(
data: AddPetMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<AddPetMutationResponse>> {
const res = await client<AddPetMutationResponse, AddPetMutationRequest>({
export async function addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> = {}) {
const res = await client<AddPetMutationResponse, AddPet405, AddPetMutationRequest>({
method: 'post',
url: '/pet',
baseURL: 'https://petstore3.swagger.io/api/v3',
data,
...options,
...config,
})
return res
}
14 changes: 7 additions & 7 deletions examples/advanced/src/gen/clients/axios/petService/deletePet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams } from '../../../models/ts/petController/DeletePet.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../../../models/ts/petController/DeletePet.ts'

/**
* @description delete a pet
Expand All @@ -14,14 +14,14 @@ export async function deletePet(
petId: DeletePetPathParams['petId']
},
headers?: DeletePetHeaderParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<DeletePetMutationResponse>> {
const res = await client<DeletePetMutationResponse>({
config: Partial<RequestConfig> = {},
) {
const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({
method: 'delete',
url: `/pet/${petId}`,
baseURL: 'https://petstore3.swagger.io/api/v3',
headers: { ...headers, ...options.headers },
...options,
headers: { ...headers, ...config.headers },
...config,
})
return res
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams } from '../../../models/ts/petController/FindPetsByStatus.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from '../../../models/ts/petController/FindPetsByStatus.ts'

/**
* @description Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
* @link /pet/findByStatus
*/
export async function findPetsByStatus(
params?: FindPetsByStatusQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<FindPetsByStatusQueryResponse>> {
const res = await client<FindPetsByStatusQueryResponse>({
export async function findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> = {}) {
const res = await client<FindPetsByStatusQueryResponse, FindPetsByStatus400, unknown>({
method: 'get',
url: '/pet/findByStatus',
baseURL: 'https://petstore3.swagger.io/api/v3',
params,
...options,
...config,
})
return res
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTagsHeaderParams } from '../../../models/ts/petController/FindPetsByTags.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type {
FindPetsByTagsQueryResponse,
FindPetsByTagsQueryParams,
FindPetsByTagsHeaderParams,
FindPetsByTags400,
} from '../../../models/ts/petController/FindPetsByTags.ts'

/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* @link /pet/findByTags
*/
export async function findPetsByTags(
headers: FindPetsByTagsHeaderParams,
params?: FindPetsByTagsQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<FindPetsByTagsQueryResponse>> {
const res = await client<FindPetsByTagsQueryResponse>({
export async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({
method: 'get',
url: '/pet/findByTags',
baseURL: 'https://petstore3.swagger.io/api/v3',
params,
headers: { ...headers, ...options.headers },
...options,
headers: { ...headers, ...config.headers },
...config,
})
return res
}
15 changes: 10 additions & 5 deletions examples/advanced/src/gen/clients/axios/petService/getPetById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { GetPetByIdQueryResponse, GetPetByIdPathParams } from '../../../models/ts/petController/GetPetById.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from '../../../models/ts/petController/GetPetById.ts'

/**
* @description Returns a single pet
Expand All @@ -13,8 +13,13 @@ export async function getPetById(
}: {
petId: GetPetByIdPathParams['petId']
},
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<GetPetByIdQueryResponse>> {
const res = await client<GetPetByIdQueryResponse>({ method: 'get', url: `/pet/${petId}`, baseURL: 'https://petstore3.swagger.io/api/v3', ...options })
config: Partial<RequestConfig> = {},
) {
const res = await client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, unknown>({
method: 'get',
url: `/pet/${petId}`,
baseURL: 'https://petstore3.swagger.io/api/v3',
...config,
})
return res
}
19 changes: 11 additions & 8 deletions examples/advanced/src/gen/clients/axios/petService/updatePet.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { UpdatePetMutationRequest, UpdatePetMutationResponse } from '../../../models/ts/petController/UpdatePet.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type {
UpdatePetMutationRequest,
UpdatePetMutationResponse,
UpdatePet400,
UpdatePet404,
UpdatePet405,
} from '../../../models/ts/petController/UpdatePet.ts'

/**
* @description Update an existing pet by Id
* @summary Update an existing pet
* @link /pet
*/
export async function updatePet(
data: UpdatePetMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UpdatePetMutationResponse>> {
const res = await client<UpdatePetMutationResponse, UpdatePetMutationRequest>({
export async function updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig<UpdatePetMutationRequest>> = {}) {
const res = await client<UpdatePetMutationResponse, UpdatePet400 | UpdatePet404 | UpdatePet405, UpdatePetMutationRequest>({
method: 'put',
url: '/pet',
baseURL: 'https://petstore3.swagger.io/api/v3',
data,
...options,
...config,
})
return res
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type {
UpdatePetWithFormMutationResponse,
UpdatePetWithFormPathParams,
UpdatePetWithFormQueryParams,
UpdatePetWithForm405,
} from '../../../models/ts/petController/UpdatePetWithForm.ts'

/**
Expand All @@ -17,14 +18,14 @@ export async function updatePetWithForm(
petId: UpdatePetWithFormPathParams['petId']
},
params?: UpdatePetWithFormQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UpdatePetWithFormMutationResponse>> {
const res = await client<UpdatePetWithFormMutationResponse>({
config: Partial<RequestConfig> = {},
) {
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({
method: 'post',
url: `/pet/${petId}`,
baseURL: 'https://petstore3.swagger.io/api/v3',
params,
...options,
...config,
})
return res
}
12 changes: 6 additions & 6 deletions examples/advanced/src/gen/clients/axios/petService/uploadFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import client from '../../../../axios-client.ts'
import type { ResponseConfig } from '../../../../axios-client.ts'
import type { RequestConfig } from '../../../../axios-client.ts'
import type {
UploadFileMutationRequest,
UploadFileMutationResponse,
Expand All @@ -19,16 +19,16 @@ export async function uploadFile(
},
data?: UploadFileMutationRequest,
params?: UploadFileQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UploadFileMutationResponse>> {
const res = await client<UploadFileMutationResponse, UploadFileMutationRequest>({
config: Partial<RequestConfig<UploadFileMutationRequest>> = {},
) {
const res = await client<UploadFileMutationResponse, unknown, UploadFileMutationRequest>({
method: 'post',
url: `/pet/${petId}/uploadImage`,
baseURL: 'https://petstore3.swagger.io/api/v3',
params,
data,
headers: { 'Content-Type': 'application/octet-stream', ...options.headers },
...options,
headers: { 'Content-Type': 'application/octet-stream', ...config.headers },
...config,
})
return res
}
Loading
Loading