@kubb/plugin-svelte-query 0.0.0-canary-20241104172400

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/chunk-CDRGJAED.cjs +452 -0
  4. package/dist/chunk-CDRGJAED.cjs.map +1 -0
  5. package/dist/chunk-JGITTOE5.js +445 -0
  6. package/dist/chunk-JGITTOE5.js.map +1 -0
  7. package/dist/chunk-KRGCKSGR.cjs +527 -0
  8. package/dist/chunk-KRGCKSGR.cjs.map +1 -0
  9. package/dist/chunk-R6ZVBNG7.js +519 -0
  10. package/dist/chunk-R6ZVBNG7.js.map +1 -0
  11. package/dist/components.cjs +28 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +103 -0
  14. package/dist/components.d.ts +103 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +10 -0
  20. package/dist/generators.d.ts +10 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +127 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +9 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.js +120 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-B9W9aYra.d.cts +365 -0
  30. package/dist/types-B9W9aYra.d.ts +365 -0
  31. package/package.json +102 -0
  32. package/src/components/Mutation.tsx +158 -0
  33. package/src/components/MutationKey.tsx +54 -0
  34. package/src/components/Query.tsx +176 -0
  35. package/src/components/QueryKey.tsx +83 -0
  36. package/src/components/QueryOptions.tsx +133 -0
  37. package/src/components/index.ts +5 -0
  38. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  39. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  40. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  41. package/src/generators/__snapshots__/findByTags.ts +51 -0
  42. package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +44 -0
  49. package/src/generators/index.ts +2 -0
  50. package/src/generators/mutationGenerator.tsx +117 -0
  51. package/src/generators/queryGenerator.tsx +129 -0
  52. package/src/index.ts +2 -0
  53. package/src/plugin.ts +141 -0
  54. package/src/types.ts +135 -0
@@ -0,0 +1,51 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
4
+ import { queryOptions, createQuery } from "@tanstack/svelte-query";
5
+
6
+ export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
7
+
8
+ export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
9
+
10
+ /**
11
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
12
+ * @summary Finds Pets by tags
13
+ * @link /pet/findByTags
14
+ */
15
+ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
16
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
17
+ return findPetsByTagsQueryResponse.parse(res.data);
18
+ }
19
+
20
+ export function findPetsByTagsQueryOptions(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
21
+ const queryKey = findPetsByTagsQueryKey(params);
22
+ return queryOptions({
23
+ queryKey,
24
+ queryFn: async ({ signal }) => {
25
+ config.signal = signal;
26
+ return findPetsByTags(headers, params, config);
27
+ },
28
+ });
29
+ }
30
+
31
+ /**
32
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
33
+ * @summary Finds Pets by tags
34
+ * @link /pet/findByTags
35
+ */
36
+ export function createFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: {
37
+ query?: Partial<CreateBaseQueryOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
38
+ client?: Partial<RequestConfig>;
39
+ } = {}) {
40
+ const { query: queryOptions, client: config = {} } = options ?? {};
41
+ const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
42
+ const query = createQuery({
43
+ ...findPetsByTagsQueryOptions(headers, params, config) as unknown as CreateBaseQueryOptions,
44
+ queryKey,
45
+ ...queryOptions as unknown as Omit<CreateBaseQueryOptions, "queryKey">
46
+ }) as CreateQueryResult<TData, FindPetsByTags400> & {
47
+ queryKey: TQueryKey;
48
+ };
49
+ query.queryKey = queryKey as TQueryKey;
50
+ return query;
51
+ }
@@ -0,0 +1,51 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/react-query";
4
+ import { queryOptions, createQuery } from "@tanstack/react-query";
5
+
6
+ export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => ["test", { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
7
+
8
+ export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
9
+
10
+ /**
11
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
12
+ * @summary Finds Pets by tags
13
+ * @link /pet/findByTags
14
+ */
15
+ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
16
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
17
+ return findPetsByTagsQueryResponse.parse(res.data);
18
+ }
19
+
20
+ export function findPetsByTagsQueryOptions(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
21
+ const queryKey = findPetsByTagsQueryKey(params);
22
+ return queryOptions({
23
+ queryKey,
24
+ queryFn: async ({ signal }) => {
25
+ config.signal = signal;
26
+ return findPetsByTags(headers, params, config);
27
+ },
28
+ });
29
+ }
30
+
31
+ /**
32
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
33
+ * @summary Finds Pets by tags
34
+ * @link /pet/findByTags
35
+ */
36
+ export function createFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: {
37
+ query?: Partial<CreateBaseQueryOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
38
+ client?: Partial<RequestConfig>;
39
+ } = {}) {
40
+ const { query: queryOptions, client: config = {} } = options ?? {};
41
+ const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
42
+ const query = createQuery({
43
+ ...findPetsByTagsQueryOptions(headers, params, config) as unknown as CreateBaseQueryOptions,
44
+ queryKey,
45
+ ...queryOptions as unknown as Omit<CreateBaseQueryOptions, "queryKey">
46
+ }) as CreateQueryResult<TData, FindPetsByTags400> & {
47
+ queryKey: TQueryKey;
48
+ };
49
+ query.queryKey = queryKey as TQueryKey;
50
+ return query;
51
+ }
@@ -0,0 +1,51 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
4
+ import { queryOptions, createQuery } from "@tanstack/svelte-query";
5
+
6
+ export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
7
+
8
+ export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
9
+
10
+ /**
11
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
12
+ * @summary Finds Pets by tags
13
+ * @link /pet/findByTags
14
+ */
15
+ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
16
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
17
+ return findPetsByTagsQueryResponse.parse(res.data);
18
+ }
19
+
20
+ export function findPetsByTagsQueryOptions(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
21
+ const queryKey = findPetsByTagsQueryKey(params);
22
+ return queryOptions({
23
+ queryKey,
24
+ queryFn: async ({ signal }) => {
25
+ config.signal = signal;
26
+ return findPetsByTags(headers, params, config);
27
+ },
28
+ });
29
+ }
30
+
31
+ /**
32
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
33
+ * @summary Finds Pets by tags
34
+ * @link /pet/findByTags
35
+ */
36
+ export function createFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: {
37
+ query?: Partial<CreateBaseQueryOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
38
+ client?: Partial<RequestConfig>;
39
+ } = {}) {
40
+ const { query: queryOptions, client: config = {} } = options ?? {};
41
+ const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
42
+ const query = createQuery({
43
+ ...findPetsByTagsQueryOptions(headers, params, config) as unknown as CreateBaseQueryOptions,
44
+ queryKey,
45
+ ...queryOptions as unknown as Omit<CreateBaseQueryOptions, "queryKey">
46
+ }) as CreateQueryResult<TData, FindPetsByTags400> & {
47
+ queryKey: TQueryKey;
48
+ };
49
+ query.queryKey = queryKey as TQueryKey;
50
+ return query;
51
+ }
@@ -0,0 +1,50 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "custom-query";
4
+ import { queryOptions, createQuery } from "custom-query";
5
+
6
+ export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
7
+
8
+ export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey>;
9
+
10
+ /**
11
+ * @summary Updates a pet in the store with form data
12
+ * @link /pet/:petId
13
+ */
14
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
15
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
16
+ return updatePetWithFormMutationResponse.parse(res.data);
17
+ }
18
+
19
+ export function updatePetWithFormQueryOptions(petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
20
+ const queryKey = updatePetWithFormQueryKey(petId, data, params);
21
+ return queryOptions({
22
+ enabled: !!(petId),
23
+ queryKey,
24
+ queryFn: async ({ signal }) => {
25
+ config.signal = signal;
26
+ return updatePetWithForm(petId, data, params, config);
27
+ },
28
+ });
29
+ }
30
+
31
+ /**
32
+ * @summary Updates a pet in the store with form data
33
+ * @link /pet/:petId
34
+ */
35
+ export function createUpdatePetWithForm<TData = UpdatePetWithFormMutationResponse, TQueryData = UpdatePetWithFormMutationResponse, TQueryKey extends QueryKey = UpdatePetWithFormQueryKey>(petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, options: {
36
+ query?: Partial<CreateBaseQueryOptions<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, TData, TQueryData, TQueryKey>>;
37
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>>;
38
+ } = {}) {
39
+ const { query: queryOptions, client: config = {} } = options ?? {};
40
+ const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data, params);
41
+ const query = createQuery({
42
+ ...updatePetWithFormQueryOptions(petId, data, params, config) as unknown as CreateBaseQueryOptions,
43
+ queryKey,
44
+ ...queryOptions as unknown as Omit<CreateBaseQueryOptions, "queryKey">
45
+ }) as CreateQueryResult<TData, UpdatePetWithForm405> & {
46
+ queryKey: TQueryKey;
47
+ };
48
+ query.queryKey = queryKey as TQueryKey;
49
+ return query;
50
+ }
@@ -0,0 +1,44 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { CreateMutationOptions } from "@tanstack/svelte-query";
4
+ import { createMutation } from "@tanstack/svelte-query";
5
+
6
+ export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
7
+
8
+ export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
9
+
10
+ /**
11
+ * @summary Updates a pet in the store with form data
12
+ * @link /pet/:petId
13
+ */
14
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
15
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
16
+ return updatePetWithFormMutationResponse.parse(res.data);
17
+ }
18
+
19
+ /**
20
+ * @summary Updates a pet in the store with form data
21
+ * @link /pet/:petId
22
+ */
23
+ export function createUpdatePetWithForm(options: {
24
+ mutation?: CreateMutationOptions<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
25
+ petId: UpdatePetWithFormPathParams["petId"];
26
+ data?: UpdatePetWithFormMutationRequest;
27
+ params?: UpdatePetWithFormQueryParams;
28
+ }>;
29
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>>;
30
+ } = {}) {
31
+ const { mutation: mutationOptions, client: config = {} } = options ?? {};
32
+ const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
33
+ return createMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
34
+ petId: UpdatePetWithFormPathParams["petId"];
35
+ data?: UpdatePetWithFormMutationRequest;
36
+ params?: UpdatePetWithFormQueryParams;
37
+ }>({
38
+ mutationFn: async ({ petId, data, params }) => {
39
+ return updatePetWithForm(petId, data, params, config);
40
+ },
41
+ mutationKey,
42
+ ...mutationOptions
43
+ });
44
+ }
@@ -0,0 +1,44 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { CreateMutationOptions } from "@tanstack/svelte-query";
4
+ import { createMutation } from "@tanstack/svelte-query";
5
+
6
+ export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
7
+
8
+ export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
9
+
10
+ /**
11
+ * @summary Updates a pet in the store with form data
12
+ * @link /pet/:petId
13
+ */
14
+ async function updatePetWithForm({ petId }: UpdatePetWithFormPathParams, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
15
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
16
+ return updatePetWithFormMutationResponse.parse(res.data);
17
+ }
18
+
19
+ /**
20
+ * @summary Updates a pet in the store with form data
21
+ * @link /pet/:petId
22
+ */
23
+ export function createUpdatePetWithForm(options: {
24
+ mutation?: CreateMutationOptions<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
25
+ petId: UpdatePetWithFormPathParams["petId"];
26
+ data?: UpdatePetWithFormMutationRequest;
27
+ params?: UpdatePetWithFormQueryParams;
28
+ }>;
29
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>>;
30
+ } = {}) {
31
+ const { mutation: mutationOptions, client: config = {} } = options ?? {};
32
+ const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
33
+ return createMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
34
+ petId: UpdatePetWithFormPathParams["petId"];
35
+ data?: UpdatePetWithFormMutationRequest;
36
+ params?: UpdatePetWithFormQueryParams;
37
+ }>({
38
+ mutationFn: async ({ petId, data, params }) => {
39
+ return updatePetWithForm({ petId }, data, params, config);
40
+ },
41
+ mutationKey,
42
+ ...mutationOptions
43
+ });
44
+ }
@@ -0,0 +1,2 @@
1
+ export { queryGenerator } from './queryGenerator.tsx'
2
+ export { mutationGenerator } from './mutationGenerator.tsx'
@@ -0,0 +1,117 @@
1
+ import { pluginClientName } from '@kubb/plugin-client'
2
+ import { Client } from '@kubb/plugin-client/components'
3
+ import { createReactGenerator } from '@kubb/plugin-oas'
4
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { pluginTsName } from '@kubb/plugin-ts'
6
+ import { pluginZodName } from '@kubb/plugin-zod'
7
+ import { File, useApp } from '@kubb/react'
8
+ import { Mutation, MutationKey } from '../components'
9
+ import type { PluginSvelteQuery } from '../types'
10
+
11
+ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
12
+ name: 'svelte-query',
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output },
17
+ },
18
+ } = useApp<PluginSvelteQuery>()
19
+ const { getSchemas, getName, getFile } = useOperationManager()
20
+
21
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
22
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
23
+
24
+ const importPath = options.mutation ? options.mutation.importPath : '@tanstack/svelte-query'
25
+
26
+ const mutation = {
27
+ name: getName(operation, { type: 'function', prefix: 'create' }),
28
+ typeName: getName(operation, { type: 'type' }),
29
+ file: getFile(operation, { prefix: 'create' }),
30
+ }
31
+
32
+ const type = {
33
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
34
+ //todo remove type?
35
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
36
+ }
37
+
38
+ const zod = {
39
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
40
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
41
+ }
42
+
43
+ const client = {
44
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
45
+ }
46
+
47
+ const mutationKey = {
48
+ name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
49
+ typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
50
+ }
51
+
52
+ if (!isMutation) {
53
+ return null
54
+ }
55
+
56
+ return (
57
+ <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
58
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
59
+
60
+ <File.Import name={'client'} path={options.client.importPath} />
61
+ <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
62
+ <File.Import
63
+ name={[
64
+ type.schemas.request?.name,
65
+ type.schemas.response.name,
66
+ type.schemas.pathParams?.name,
67
+ type.schemas.queryParams?.name,
68
+ type.schemas.headerParams?.name,
69
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
70
+ ].filter(Boolean)}
71
+ root={mutation.file.path}
72
+ path={type.file.path}
73
+ isTypeOnly
74
+ />
75
+
76
+ <MutationKey
77
+ name={mutationKey.name}
78
+ typeName={mutationKey.typeName}
79
+ operation={operation}
80
+ pathParamsType={options.pathParamsType}
81
+ typeSchemas={type.schemas}
82
+ transformer={options.mutationKey}
83
+ />
84
+ <Client
85
+ name={client.name}
86
+ isExportable={false}
87
+ isIndexable={false}
88
+ baseURL={options.client.baseURL}
89
+ operation={operation}
90
+ typeSchemas={type.schemas}
91
+ zodSchemas={zod.schemas}
92
+ dataReturnType={options.client.dataReturnType}
93
+ paramsType={options.paramsType}
94
+ pathParamsType={options.pathParamsType}
95
+ parser={options.parser}
96
+ />
97
+ {options.mutation && (
98
+ <>
99
+ <File.Import name={['createMutation']} path={importPath} />
100
+ <File.Import name={['CreateMutationOptions', 'CreateMutationResult']} path={importPath} isTypeOnly />
101
+ <Mutation
102
+ name={mutation.name}
103
+ clientName={client.name}
104
+ typeName={mutation.typeName}
105
+ typeSchemas={type.schemas}
106
+ operation={operation}
107
+ dataReturnType={options.client.dataReturnType}
108
+ paramsType={options.paramsType}
109
+ pathParamsType={options.pathParamsType}
110
+ mutationKeyName={mutationKey.name}
111
+ />
112
+ </>
113
+ )}
114
+ </File>
115
+ )
116
+ },
117
+ })
@@ -0,0 +1,129 @@
1
+ import { pluginClientName } from '@kubb/plugin-client'
2
+ import { Client } from '@kubb/plugin-client/components'
3
+ import { createReactGenerator } from '@kubb/plugin-oas'
4
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { pluginTsName } from '@kubb/plugin-ts'
6
+ import { pluginZodName } from '@kubb/plugin-zod'
7
+ import { File, useApp } from '@kubb/react'
8
+ import { Query, QueryKey, QueryOptions } from '../components'
9
+ import type { PluginSvelteQuery } from '../types'
10
+
11
+ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
12
+ name: 'svelte-query',
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output },
17
+ },
18
+ } = useApp<PluginSvelteQuery>()
19
+ const { getSchemas, getName, getFile } = useOperationManager()
20
+
21
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
22
+ const importPath = options.query ? options.query.importPath : '@tanstack/svelte-query'
23
+
24
+ const query = {
25
+ name: getName(operation, { type: 'function', prefix: 'create' }),
26
+ typeName: getName(operation, { type: 'type' }),
27
+ file: getFile(operation, { prefix: 'create' }),
28
+ }
29
+
30
+ const client = {
31
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
32
+ }
33
+
34
+ const queryOptions = {
35
+ name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
36
+ }
37
+
38
+ const queryKey = {
39
+ name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
40
+ typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
41
+ }
42
+
43
+ const type = {
44
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
45
+ //todo remove type?
46
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
47
+ }
48
+
49
+ const zod = {
50
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
51
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
+ }
53
+
54
+ if (!isQuery) {
55
+ return null
56
+ }
57
+
58
+ return (
59
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
+ <File.Import name={'client'} path={options.client.importPath} />
62
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
63
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
64
+ <File.Import
65
+ name={[
66
+ type.schemas.request?.name,
67
+ type.schemas.response.name,
68
+ type.schemas.pathParams?.name,
69
+ type.schemas.queryParams?.name,
70
+ type.schemas.headerParams?.name,
71
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
72
+ ].filter(Boolean)}
73
+ root={query.file.path}
74
+ path={type.file.path}
75
+ isTypeOnly
76
+ />
77
+
78
+ <QueryKey
79
+ name={queryKey.name}
80
+ typeName={queryKey.typeName}
81
+ operation={operation}
82
+ pathParamsType={options.pathParamsType}
83
+ typeSchemas={type.schemas}
84
+ transformer={options.queryKey}
85
+ />
86
+
87
+ <Client
88
+ name={client.name}
89
+ isExportable={false}
90
+ isIndexable={false}
91
+ baseURL={options.client.baseURL}
92
+ operation={operation}
93
+ typeSchemas={type.schemas}
94
+ zodSchemas={zod.schemas}
95
+ dataReturnType={options.client.dataReturnType}
96
+ paramsType={options.paramsType}
97
+ pathParamsType={options.pathParamsType}
98
+ parser={options.parser}
99
+ />
100
+ <File.Import name={['queryOptions']} path={importPath} />
101
+ <QueryOptions
102
+ name={queryOptions.name}
103
+ clientName={client.name}
104
+ queryKeyName={queryKey.name}
105
+ typeSchemas={type.schemas}
106
+ paramsType={options.paramsType}
107
+ pathParamsType={options.pathParamsType}
108
+ />
109
+ {options.query && (
110
+ <>
111
+ <File.Import name={['createQuery']} path={importPath} />
112
+ <File.Import name={['QueryKey', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={importPath} isTypeOnly />
113
+ <Query
114
+ name={query.name}
115
+ queryOptionsName={queryOptions.name}
116
+ typeSchemas={type.schemas}
117
+ pathParamsType={options.pathParamsType}
118
+ operation={operation}
119
+ paramsType={options.paramsType}
120
+ dataReturnType={options.client.dataReturnType}
121
+ queryKeyName={queryKey.name}
122
+ queryKeyTypeName={queryKey.typeName}
123
+ />
124
+ </>
125
+ )}
126
+ </File>
127
+ )
128
+ },
129
+ })
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { pluginSvelteQuery, pluginSvelteQueryName } from './plugin.ts'
2
+ export type { PluginSvelteQuery } from './types.ts'