@kubb/plugin-svelte-query 3.0.0-alpha.20

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