@kubb/plugin-solid-query 3.18.3 → 4.0.2
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/dist/{components-CCkbce4B.cjs → components-CrpQqUQQ.cjs} +194 -14
- package/dist/components-CrpQqUQQ.cjs.map +1 -0
- package/dist/{components-DteoGXDw.js → components-JN6XAKh3.js} +172 -10
- package/dist/components-JN6XAKh3.js.map +1 -0
- package/dist/components.cjs +3 -1
- package/dist/components.d.cts +58 -2
- package/dist/components.d.ts +58 -2
- package/dist/components.js +2 -2
- package/dist/generators-CUcA3_rk.cjs +365 -0
- package/dist/generators-CUcA3_rk.cjs.map +1 -0
- package/dist/{generators-D4zsCZ8Y.js → generators-DRX-ix2A.js} +155 -5
- package/dist/generators-DRX-ix2A.js.map +1 -0
- package/dist/generators.cjs +3 -2
- package/dist/generators.d.cts +5 -2
- package/dist/generators.d.ts +5 -2
- package/dist/generators.js +3 -3
- package/dist/index.cjs +29 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-BcAT9UxT.d.cts → types-BI1GJc6y.d.cts} +27 -1
- package/dist/{types-B5mFPIGb.d.ts → types-fv5KLGsJ.d.ts} +27 -1
- package/package.json +11 -12
- package/src/components/Mutation.tsx +177 -0
- package/src/components/MutationKey.tsx +54 -0
- package/src/components/Query.tsx +1 -1
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +2 -2
- package/src/generators/__snapshots__/clientGetImportPath.ts +2 -2
- package/src/generators/__snapshots__/findByTags.ts +2 -2
- package/src/generators/__snapshots__/findByTagsObject.ts +2 -2
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithZod.ts +2 -2
- package/src/generators/__snapshots__/postAsQuery.ts +2 -2
- package/src/generators/index.ts +1 -0
- package/src/generators/mutationGenerator.tsx +144 -0
- package/src/generators/queryGenerator.tsx +1 -1
- package/src/plugin.ts +14 -9
- package/src/types.ts +28 -0
- package/dist/components-CCkbce4B.cjs.map +0 -1
- package/dist/components-DteoGXDw.js.map +0 -1
- package/dist/generators-D4zsCZ8Y.js.map +0 -1
- package/dist/generators-yp4-76zC.cjs +0 -199
- package/dist/generators-yp4-76zC.cjs.map +0 -1
package/src/types.ts
CHANGED
|
@@ -17,6 +17,11 @@ export type Transformer = (props: TransformerProps) => unknown[]
|
|
|
17
17
|
*/
|
|
18
18
|
type QueryKey = Transformer
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Customize the mutationKey
|
|
22
|
+
*/
|
|
23
|
+
type MutationKey = Transformer
|
|
24
|
+
|
|
20
25
|
type Query = {
|
|
21
26
|
/**
|
|
22
27
|
* Define which HttpMethods can be used for queries
|
|
@@ -33,6 +38,22 @@ type Query = {
|
|
|
33
38
|
importPath?: string
|
|
34
39
|
}
|
|
35
40
|
|
|
41
|
+
type Mutation = {
|
|
42
|
+
/**
|
|
43
|
+
* Define which HttpMethods can be used for mutations
|
|
44
|
+
* @default ['post', 'put', 'delete']
|
|
45
|
+
*/
|
|
46
|
+
methods: Array<HttpMethod>
|
|
47
|
+
/**
|
|
48
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
49
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
50
|
+
* It allows both relative and absolute path.
|
|
51
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
52
|
+
* @default '@tanstack/solid-query'
|
|
53
|
+
*/
|
|
54
|
+
importPath?: string
|
|
55
|
+
}
|
|
56
|
+
|
|
36
57
|
export type Options = {
|
|
37
58
|
/**
|
|
38
59
|
* Specify the export location for the files and define the behavior of the output
|
|
@@ -90,6 +111,11 @@ export type Options = {
|
|
|
90
111
|
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
91
112
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
92
113
|
*/
|
|
114
|
+
mutationKey?: MutationKey
|
|
115
|
+
/**
|
|
116
|
+
* Override some useMutation behaviours.
|
|
117
|
+
*/
|
|
118
|
+
mutation?: Partial<Mutation> | false
|
|
93
119
|
parser?: PluginClient['options']['parser']
|
|
94
120
|
transformers?: {
|
|
95
121
|
/**
|
|
@@ -113,6 +139,8 @@ type ResolvedOptions = {
|
|
|
113
139
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
114
140
|
queryKey: QueryKey | undefined
|
|
115
141
|
query: NonNullable<Required<Query>> | false
|
|
142
|
+
mutationKey: MutationKey | undefined
|
|
143
|
+
mutation: NonNullable<Required<Mutation>> | false
|
|
116
144
|
}
|
|
117
145
|
|
|
118
146
|
export type PluginSolidQuery = PluginFactoryOptions<'plugin-solid-query', Options, ResolvedOptions, never, ResolvePathOptions>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components-CCkbce4B.cjs","names":["getParams","FunctionParams","getTransformer: Transformer","URLPath","File","Function","Type","getParams","FunctionParams","Client","File","Function","FunctionParams","File","Function"],"sources":["../src/components/QueryKey.tsx","../src/components/QueryOptions.tsx","../src/components/Query.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams, Type } from '@kubb/react'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { ReactNode } from 'react'\nimport type { PluginSolidQuery, Transformer } from '../types'\n\ntype Props = {\n name: string\n typeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n transformer: Transformer | undefined\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n },\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n })\n}\n\nconst getTransformer: Transformer = ({ operation, schemas, casing }) => {\n const path = new URLPath(operation.path, { casing })\n const keys = [\n path.toObject({\n type: 'path',\n stringify: true,\n }),\n schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,\n schemas.request?.name ? '...(data ? [data] : [])' : undefined,\n ].filter(Boolean)\n\n return keys\n}\n\nexport function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {\n const params = getParams({ pathParamsType, paramsCasing, typeSchemas })\n const keys = transformer({\n operation,\n schemas: typeSchemas,\n casing: paramsCasing,\n })\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Function.Arrow name={name} export params={params.toConstructor()} singleLine>\n {`[${keys.join(', ')}] as const`}\n </Function.Arrow>\n </File.Source>\n <File.Source name={typeName} isExportable isIndexable isTypeOnly>\n <Type name={typeName} export>\n {`ReturnType<typeof ${name}>`}\n </Type>\n </File.Source>\n </>\n )\n}\n\nQueryKey.getParams = getParams\nQueryKey.getTransformer = getTransformer\n","import { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { ReactNode } from 'react'\n\nimport { isOptional } from '@kubb/oas'\nimport { Client } from '@kubb/plugin-client/components'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { PluginSolidQuery } from '../types.ts'\nimport { QueryKey } from './QueryKey.tsx'\n\ntype Props = {\n name: string\n clientName: string\n queryKeyName: string\n typeSchemas: OperationSchemas\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n config: {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n },\n })\n}\n\nexport function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryKeyName }: Props): ReactNode {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n const clientParams = Client.getParams({\n paramsCasing,\n typeSchemas,\n paramsType,\n pathParamsType,\n isConfigurable: true,\n })\n const queryKeyParams = QueryKey.getParams({\n pathParamsType,\n paramsCasing,\n typeSchemas,\n })\n\n const enabled = Object.entries(queryKeyParams.flatParams)\n .map(([key, item]) => (item && !item.optional ? key : undefined))\n .filter(Boolean)\n .join('&& ')\n\n const enabledText = enabled ? `enabled: !!(${enabled}),` : ''\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function name={name} export params={params.toConstructor()}>\n {`\n const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})\n return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({\n ${enabledText}\n queryKey,\n queryFn: async ({ signal }) => {\n config.signal = signal\n return ${clientName}(${clientParams.toCall()})\n },\n })\n`}\n </Function>\n </File.Source>\n )\n}\n\nQueryOptions.getParams = getParams\n","import { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\nimport type { ReactNode } from 'react'\nimport type { PluginSolidQuery } from '../types.ts'\nimport { QueryKey } from './QueryKey.tsx'\nimport { QueryOptions } from './QueryOptions.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n queryOptionsName: string\n queryKeyName: string\n queryKeyTypeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n options: {\n type: `\n{\n query?: Partial<UseBaseQueryOptions<${[TData, TError, 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>> & { client?: QueryClient },\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'}\n}\n`,\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: `\n{\n query?: Partial<UseBaseQueryOptions<${[TData, TError, 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>> & { client?: QueryClient },\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'}\n}\n`,\n default: '{}',\n },\n })\n}\n\nexport function Query({\n name,\n queryKeyTypeName,\n queryOptionsName,\n queryKeyName,\n paramsCasing,\n paramsType,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n operation,\n}: Props): ReactNode {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n const returnType = `UseQueryResult<${['TData', TError].join(', ')}> & { queryKey: TQueryKey }`\n const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]\n\n const queryKeyParams = QueryKey.getParams({\n pathParamsType,\n typeSchemas,\n paramsCasing,\n })\n const queryOptionsParams = QueryOptions.getParams({\n paramsType,\n paramsCasing,\n pathParamsType,\n typeSchemas,\n })\n const params = getParams({\n paramsCasing,\n paramsType,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n })\n\n const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as UseBaseQueryOptions`\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n export\n generics={generics.join(', ')}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {`\n const { query: queryConfig = {}, client: config = {} } = options ?? {}\n const { client: queryClient, ...queryOptions } = queryConfig\n const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})\n\n const query = createQuery(() => ({\n ...${queryOptions},\n queryKey,\n initialData: null,\n ...queryOptions as unknown as Omit<UseBaseQueryOptions, \"queryKey\">\n }), queryClient? () => queryClient: undefined) as ${returnType}\n\n return query\n `}\n </Function>\n </File.Source>\n )\n}\n\nQuery.getParams = getParams\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAASA,YAAU,EAAE,gBAAgB,cAAc,eAA+B;AAChF,QAAOC,4BAAe,QAAQ;EAC5B,YAAY;GACV,MAAM,mBAAmB,WAAW,WAAW;GAC/C,qDAAwB,YAAY,YAAY;IAAE,OAAO;IAAM,QAAQ;;;EAEzE,MAAM,YAAY,SAAS,OACvB;GACE,MAAM,YAAY,SAAS;GAC3B,qCAAqB,YAAY,SAAS;MAE5C;EACJ,QAAQ,YAAY,aAAa,OAC7B;GACE,MAAM,YAAY,aAAa;GAC/B,qCAAqB,YAAY,aAAa;MAEhD;;;AAIR,MAAMC,kBAA+B,EAAE,WAAW,SAAS,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a;GAC/B,qCAAqB,YAAY,aAAa;MAEhD;EACJ,SAAS,YAAY,cAAc,OAC/B;GACE,MAAM,YAAY,cAAc;GAChC,qCAAqB,YAAY,cAAc;MAEjD;EACJ,SAAS;GACP,MAAM;;wCAE4B;IAAC;IAAO;IAAQ;IAAS;IAAc;KAAa,KAAK,MAAM;aAC1F,YAAY,SAAS,OAAO,yBAAyB,YAAY,SAAS,KAAK,kCAAkC,qDAAqD;;;GAG7K,SAAS;;;;AAKf,SAAgB,MAAM,EACpB,MACA,kBACA,kBACA,cACA,cACA,YACA,gBACA,gBACA,aACA,aACmB;CACnB,MAAM,QAAQ,mBAAmB,SAAS,YAAY,SAAS,OAAO,kBAAkB,YAAY,SAAS,KAAK;CAClH,MAAM,SAAS,uBAAuB,YAAY,QAAQ,KAAK,SAAS,KAAK,MAAM,KAAK,UAAU,QAAQ;CAC1G,MAAM,aAAa,kBAAkB,CAAC,SAAS,QAAQ,KAAK,MAAM;CAClE,MAAM,WAAW;EAAC,WAAW;EAAS,gBAAgB;EAAS,gCAAgC;;CAE/F,MAAM,iBAAiB,SAAS,UAAU;EACxC;EACA;EACA;;CAEF,MAAM,qBAAqB,aAAa,UAAU;EAChD;EACA;EACA;EACA;;CAEF,MAAM,SAAS,UAAU;EACvB;EACA;EACA;EACA;EACA;;CAGF,MAAM,eAAe,GAAG,iBAAiB,GAAG,mBAAmB,SAAS;AAExE,QACE,kDAACC,kBAAK;EAAa;EAAM;EAAa;YACpC,kDAACC;GACO;GACN;GACA,UAAU,SAAS,KAAK;GACxB,QAAQ,OAAO;GACf,OAAO,EACL,mDAAsB;aAGvB;;;oDAG2C,aAAa,GAAG,eAAe,SAAS;;;aAG/E,aAAa;;;;2DAIiC,WAAW;;;;;;;AAStE,MAAM,YAAY"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components-DteoGXDw.js","names":["getParams","getTransformer: Transformer","getParams"],"sources":["../src/components/QueryKey.tsx","../src/components/QueryOptions.tsx","../src/components/Query.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams, Type } from '@kubb/react'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { ReactNode } from 'react'\nimport type { PluginSolidQuery, Transformer } from '../types'\n\ntype Props = {\n name: string\n typeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n transformer: Transformer | undefined\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n },\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n })\n}\n\nconst getTransformer: Transformer = ({ operation, schemas, casing }) => {\n const path = new URLPath(operation.path, { casing })\n const keys = [\n path.toObject({\n type: 'path',\n stringify: true,\n }),\n schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,\n schemas.request?.name ? '...(data ? [data] : [])' : undefined,\n ].filter(Boolean)\n\n return keys\n}\n\nexport function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {\n const params = getParams({ pathParamsType, paramsCasing, typeSchemas })\n const keys = transformer({\n operation,\n schemas: typeSchemas,\n casing: paramsCasing,\n })\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Function.Arrow name={name} export params={params.toConstructor()} singleLine>\n {`[${keys.join(', ')}] as const`}\n </Function.Arrow>\n </File.Source>\n <File.Source name={typeName} isExportable isIndexable isTypeOnly>\n <Type name={typeName} export>\n {`ReturnType<typeof ${name}>`}\n </Type>\n </File.Source>\n </>\n )\n}\n\nQueryKey.getParams = getParams\nQueryKey.getTransformer = getTransformer\n","import { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { ReactNode } from 'react'\n\nimport { isOptional } from '@kubb/oas'\nimport { Client } from '@kubb/plugin-client/components'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { PluginSolidQuery } from '../types.ts'\nimport { QueryKey } from './QueryKey.tsx'\n\ntype Props = {\n name: string\n clientName: string\n queryKeyName: string\n typeSchemas: OperationSchemas\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n config: {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n },\n })\n}\n\nexport function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryKeyName }: Props): ReactNode {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n const clientParams = Client.getParams({\n paramsCasing,\n typeSchemas,\n paramsType,\n pathParamsType,\n isConfigurable: true,\n })\n const queryKeyParams = QueryKey.getParams({\n pathParamsType,\n paramsCasing,\n typeSchemas,\n })\n\n const enabled = Object.entries(queryKeyParams.flatParams)\n .map(([key, item]) => (item && !item.optional ? key : undefined))\n .filter(Boolean)\n .join('&& ')\n\n const enabledText = enabled ? `enabled: !!(${enabled}),` : ''\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function name={name} export params={params.toConstructor()}>\n {`\n const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})\n return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({\n ${enabledText}\n queryKey,\n queryFn: async ({ signal }) => {\n config.signal = signal\n return ${clientName}(${clientParams.toCall()})\n },\n })\n`}\n </Function>\n </File.Source>\n )\n}\n\nQueryOptions.getParams = getParams\n","import { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\nimport type { ReactNode } from 'react'\nimport type { PluginSolidQuery } from '../types.ts'\nimport { QueryKey } from './QueryKey.tsx'\nimport { QueryOptions } from './QueryOptions.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n queryOptionsName: string\n queryKeyName: string\n queryKeyTypeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']\n paramsType: PluginSolidQuery['resolvedOptions']['paramsType']\n pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n options: {\n type: `\n{\n query?: Partial<UseBaseQueryOptions<${[TData, TError, 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>> & { client?: QueryClient },\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'}\n}\n`,\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: `\n{\n query?: Partial<UseBaseQueryOptions<${[TData, TError, 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>> & { client?: QueryClient },\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'}\n}\n`,\n default: '{}',\n },\n })\n}\n\nexport function Query({\n name,\n queryKeyTypeName,\n queryOptionsName,\n queryKeyName,\n paramsCasing,\n paramsType,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n operation,\n}: Props): ReactNode {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n const returnType = `UseQueryResult<${['TData', TError].join(', ')}> & { queryKey: TQueryKey }`\n const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]\n\n const queryKeyParams = QueryKey.getParams({\n pathParamsType,\n typeSchemas,\n paramsCasing,\n })\n const queryOptionsParams = QueryOptions.getParams({\n paramsType,\n paramsCasing,\n pathParamsType,\n typeSchemas,\n })\n const params = getParams({\n paramsCasing,\n paramsType,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n })\n\n const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as UseBaseQueryOptions`\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n export\n generics={generics.join(', ')}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {`\n const { query: queryConfig = {}, client: config = {} } = options ?? {}\n const { client: queryClient, ...queryOptions } = queryConfig\n const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})\n\n const query = createQuery(() => ({\n ...${queryOptions},\n queryKey,\n initialData: null,\n ...queryOptions as unknown as Omit<UseBaseQueryOptions, \"queryKey\">\n }), queryClient? () => queryClient: undefined) as ${returnType}\n\n return query\n `}\n </Function>\n </File.Source>\n )\n}\n\nQuery.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ACA;;CAEF,MAAM,SAAS,UAAU;EACvB;EACA;EACA;EACA;EACA;;CAGF,MAAM,eAAe,GAAG,iBAAiB,GAAG,mBAAmB,SAAS;AAExE,QACE,oBAAC,KAAK;EAAa;EAAM;EAAa;YACpC,oBAAC;GACO;GACN;GACA,UAAU,SAAS,KAAK;GACxB,QAAQ,OAAO;GACf,OAAO,EACL,UAAU,YAAY;aAGvB;;;oDAG2C,aAAa,GAAG,eAAe,SAAS;;;aAG/E,aAAa;;;;2DAIiC,WAAW;;;;;;;AAStE,MAAM,YAAY"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-D4zsCZ8Y.js","names":[],"sources":["../src/generators/queryGenerator.tsx"],"sourcesContent":["import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { Query, QueryKey, QueryOptions } from '../components'\nimport type { PluginSolidQuery } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSolidQuery>({\n name: 'svelte-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginSolidQuery>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(['post', 'put', 'delete', 'patch'], options.query ? options.query.methods : []).some((method) => operation.method === method)\n const importPath = options.query ? options.query.importPath : '@tanstack/solid-query'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'create' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'create' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n const client = {\n name: hasClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File\n baseName={query.file.baseName}\n path={query.file.path}\n meta={query.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />\n )}\n <File.Import name={'fetch'} path={options.client.importPath} />\n {!!hasClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.queryKey}\n />\n {!hasClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n <File.Import name={['queryOptions']} path={importPath} />\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n queryKeyName={queryKey.name}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n dataReturnType={options.client.dataReturnType}\n />\n {options.query && (\n <>\n <File.Import name={['createQuery']} path={importPath} />\n <File.Import name={['QueryKey', 'QueryClient', 'UseBaseQueryOptions', 'UseQueryResult']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n paramsCasing={options.paramsCasing}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,iBAAiB,qBAAuC;CACnE,MAAM;CACN,UAAU,EAAE,SAAS,aAAa;EAChC,MAAM,EACJ,QAAQ,EACN,SAAS,EAAE,YAEb,kBACE;EACJ,MAAM,MAAM;EACZ,MAAM,EAAE,YAAY,SAAS,YAAY;EAEzC,MAAM,UAAU,OAAO,QAAQ,UAAU,YAAY,OAAO,QAAQ,OAAO,QAAQ,MAAM,WAAW,UAAU,WAAW;EACzH,MAAM,aAAa,WAAW;GAAC;GAAQ;GAAO;GAAU;KAAU,QAAQ,QAAQ,QAAQ,MAAM,UAAU,IAAI,MAAM,WAAW,UAAU,WAAW;EACpJ,MAAM,aAAa,QAAQ,QAAQ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C1C,oBAAC,KAAK;MAAO,MAAM;OAAC;OAAY;OAAe;OAAuB;;MAAmB,MAAM;MAAY;;KAC3G,oBAAC;MACC,MAAM,MAAM;MACZ,kBAAkB,aAAa;MAC/B,aAAa,KAAK;MAClB,YAAY,QAAQ;MACpB,gBAAgB,QAAQ;MACb;MACX,cAAc,QAAQ;MACtB,gBAAgB,QAAQ,OAAO;MAC/B,cAAc,SAAS;MACvB,kBAAkB,SAAS"}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
const require_components = require('./components-CCkbce4B.cjs');
|
|
2
|
-
const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
|
|
3
|
-
const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
|
|
4
|
-
const __kubb_plugin_zod = require_components.__toESM(require("@kubb/plugin-zod"));
|
|
5
|
-
const __kubb_plugin_oas_utils = require_components.__toESM(require("@kubb/plugin-oas/utils"));
|
|
6
|
-
const __kubb_react = require_components.__toESM(require("@kubb/react"));
|
|
7
|
-
const __kubb_react_jsx_runtime = require_components.__toESM(require("@kubb/react/jsx-runtime"));
|
|
8
|
-
const __kubb_plugin_client_components = require_components.__toESM(require("@kubb/plugin-client/components"));
|
|
9
|
-
const __kubb_plugin_client = require_components.__toESM(require("@kubb/plugin-client"));
|
|
10
|
-
const __kubb_plugin_oas_hooks = require_components.__toESM(require("@kubb/plugin-oas/hooks"));
|
|
11
|
-
const remeda = require_components.__toESM(require("remeda"));
|
|
12
|
-
|
|
13
|
-
//#region src/generators/queryGenerator.tsx
|
|
14
|
-
const queryGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
15
|
-
name: "svelte-query",
|
|
16
|
-
Operation({ options, operation }) {
|
|
17
|
-
const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
|
|
18
|
-
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
19
|
-
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
20
|
-
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
21
|
-
const isMutation = (0, remeda.difference)([
|
|
22
|
-
"post",
|
|
23
|
-
"put",
|
|
24
|
-
"delete",
|
|
25
|
-
"patch"
|
|
26
|
-
], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
27
|
-
const importPath = options.query ? options.query.importPath : "@tanstack/solid-query";
|
|
28
|
-
const query = {
|
|
29
|
-
name: getName(operation, {
|
|
30
|
-
type: "function",
|
|
31
|
-
prefix: "create"
|
|
32
|
-
}),
|
|
33
|
-
typeName: getName(operation, { type: "type" }),
|
|
34
|
-
file: getFile(operation, { prefix: "create" })
|
|
35
|
-
};
|
|
36
|
-
const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
37
|
-
const client = {
|
|
38
|
-
name: hasClientPlugin ? getName(operation, {
|
|
39
|
-
type: "function",
|
|
40
|
-
pluginKey: [__kubb_plugin_client.pluginClientName]
|
|
41
|
-
}) : getName(operation, { type: "function" }),
|
|
42
|
-
file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
|
|
43
|
-
};
|
|
44
|
-
const queryOptions = { name: getName(operation, {
|
|
45
|
-
type: "function",
|
|
46
|
-
suffix: "QueryOptions"
|
|
47
|
-
}) };
|
|
48
|
-
const queryKey = {
|
|
49
|
-
name: getName(operation, {
|
|
50
|
-
type: "const",
|
|
51
|
-
suffix: "QueryKey"
|
|
52
|
-
}),
|
|
53
|
-
typeName: getName(operation, {
|
|
54
|
-
type: "type",
|
|
55
|
-
suffix: "QueryKey"
|
|
56
|
-
})
|
|
57
|
-
};
|
|
58
|
-
const type = {
|
|
59
|
-
file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
|
|
60
|
-
schemas: getSchemas(operation, {
|
|
61
|
-
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
62
|
-
type: "type"
|
|
63
|
-
})
|
|
64
|
-
};
|
|
65
|
-
const zod = {
|
|
66
|
-
file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
|
|
67
|
-
schemas: getSchemas(operation, {
|
|
68
|
-
pluginKey: [__kubb_plugin_zod.pluginZodName],
|
|
69
|
-
type: "function"
|
|
70
|
-
})
|
|
71
|
-
};
|
|
72
|
-
if (!isQuery || isMutation) return null;
|
|
73
|
-
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
74
|
-
baseName: query.file.baseName,
|
|
75
|
-
path: query.file.path,
|
|
76
|
-
meta: query.file.meta,
|
|
77
|
-
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
78
|
-
oas,
|
|
79
|
-
output,
|
|
80
|
-
config: pluginManager.config
|
|
81
|
-
}),
|
|
82
|
-
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
83
|
-
oas,
|
|
84
|
-
output
|
|
85
|
-
}),
|
|
86
|
-
children: [
|
|
87
|
-
options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
88
|
-
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
89
|
-
root: query.file.path,
|
|
90
|
-
path: zod.file.path
|
|
91
|
-
}),
|
|
92
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
93
|
-
name: "fetch",
|
|
94
|
-
path: options.client.importPath
|
|
95
|
-
}),
|
|
96
|
-
!!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
97
|
-
name: [client.name],
|
|
98
|
-
root: query.file.path,
|
|
99
|
-
path: client.file.path
|
|
100
|
-
}),
|
|
101
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
102
|
-
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
103
|
-
path: options.client.importPath,
|
|
104
|
-
isTypeOnly: true
|
|
105
|
-
}),
|
|
106
|
-
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
107
|
-
name: ["ResponseConfig"],
|
|
108
|
-
path: options.client.importPath,
|
|
109
|
-
isTypeOnly: true
|
|
110
|
-
}),
|
|
111
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
112
|
-
name: [
|
|
113
|
-
type.schemas.request?.name,
|
|
114
|
-
type.schemas.response.name,
|
|
115
|
-
type.schemas.pathParams?.name,
|
|
116
|
-
type.schemas.queryParams?.name,
|
|
117
|
-
type.schemas.headerParams?.name,
|
|
118
|
-
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
119
|
-
].filter(Boolean),
|
|
120
|
-
root: query.file.path,
|
|
121
|
-
path: type.file.path,
|
|
122
|
-
isTypeOnly: true
|
|
123
|
-
}),
|
|
124
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryKey, {
|
|
125
|
-
name: queryKey.name,
|
|
126
|
-
typeName: queryKey.typeName,
|
|
127
|
-
operation,
|
|
128
|
-
paramsCasing: options.paramsCasing,
|
|
129
|
-
pathParamsType: options.pathParamsType,
|
|
130
|
-
typeSchemas: type.schemas,
|
|
131
|
-
transformer: options.queryKey
|
|
132
|
-
}),
|
|
133
|
-
!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
|
|
134
|
-
name: client.name,
|
|
135
|
-
baseURL: options.client.baseURL,
|
|
136
|
-
operation,
|
|
137
|
-
typeSchemas: type.schemas,
|
|
138
|
-
zodSchemas: zod.schemas,
|
|
139
|
-
dataReturnType: options.client.dataReturnType,
|
|
140
|
-
paramsCasing: options.paramsCasing,
|
|
141
|
-
paramsType: options.paramsType,
|
|
142
|
-
pathParamsType: options.pathParamsType,
|
|
143
|
-
parser: options.parser
|
|
144
|
-
}),
|
|
145
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
146
|
-
name: ["queryOptions"],
|
|
147
|
-
path: importPath
|
|
148
|
-
}),
|
|
149
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryOptions, {
|
|
150
|
-
name: queryOptions.name,
|
|
151
|
-
clientName: client.name,
|
|
152
|
-
queryKeyName: queryKey.name,
|
|
153
|
-
typeSchemas: type.schemas,
|
|
154
|
-
paramsCasing: options.paramsCasing,
|
|
155
|
-
paramsType: options.paramsType,
|
|
156
|
-
pathParamsType: options.pathParamsType,
|
|
157
|
-
dataReturnType: options.client.dataReturnType
|
|
158
|
-
}),
|
|
159
|
-
options.query && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
160
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
161
|
-
name: ["createQuery"],
|
|
162
|
-
path: importPath
|
|
163
|
-
}),
|
|
164
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
165
|
-
name: [
|
|
166
|
-
"QueryKey",
|
|
167
|
-
"QueryClient",
|
|
168
|
-
"UseBaseQueryOptions",
|
|
169
|
-
"UseQueryResult"
|
|
170
|
-
],
|
|
171
|
-
path: importPath,
|
|
172
|
-
isTypeOnly: true
|
|
173
|
-
}),
|
|
174
|
-
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Query, {
|
|
175
|
-
name: query.name,
|
|
176
|
-
queryOptionsName: queryOptions.name,
|
|
177
|
-
typeSchemas: type.schemas,
|
|
178
|
-
paramsType: options.paramsType,
|
|
179
|
-
pathParamsType: options.pathParamsType,
|
|
180
|
-
operation,
|
|
181
|
-
paramsCasing: options.paramsCasing,
|
|
182
|
-
dataReturnType: options.client.dataReturnType,
|
|
183
|
-
queryKeyName: queryKey.name,
|
|
184
|
-
queryKeyTypeName: queryKey.typeName
|
|
185
|
-
})
|
|
186
|
-
] })
|
|
187
|
-
]
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
//#endregion
|
|
193
|
-
Object.defineProperty(exports, 'queryGenerator', {
|
|
194
|
-
enumerable: true,
|
|
195
|
-
get: function () {
|
|
196
|
-
return queryGenerator;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
//# sourceMappingURL=generators-yp4-76zC.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-yp4-76zC.cjs","names":["pluginClientName","pluginTsName","pluginZodName","File","QueryKey","Client","QueryOptions","Query"],"sources":["../src/generators/queryGenerator.tsx"],"sourcesContent":["import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { Query, QueryKey, QueryOptions } from '../components'\nimport type { PluginSolidQuery } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSolidQuery>({\n name: 'svelte-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginSolidQuery>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(['post', 'put', 'delete', 'patch'], options.query ? options.query.methods : []).some((method) => operation.method === method)\n const importPath = options.query ? options.query.importPath : '@tanstack/solid-query'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'create' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'create' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n const client = {\n name: hasClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File\n baseName={query.file.baseName}\n path={query.file.path}\n meta={query.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />\n )}\n <File.Import name={'fetch'} path={options.client.importPath} />\n {!!hasClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.queryKey}\n />\n {!hasClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n <File.Import name={['queryOptions']} path={importPath} />\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n queryKeyName={queryKey.name}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n dataReturnType={options.client.dataReturnType}\n />\n {options.query && (\n <>\n <File.Import name={['createQuery']} path={importPath} />\n <File.Import name={['QueryKey', 'QueryClient', 'UseBaseQueryOptions', 'UseQueryResult']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n paramsCasing={options.paramsCasing}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,6DAAwD;CACnE,MAAM;CACN,UAAU,EAAE,SAAS,aAAa;EAChC,MAAM,EACJ,QAAQ,EACN,SAAS,EAAE,YAEb;EAEF,MAAM;EACN,MAAM,EAAE,YAAY,SAAS;EAE7B,MAAM,UAAU,OAAO,QAAQ,UAAU,YAAY,OAAO,QAAQ,OAAO,QAAQ,MAAM,WAAW,UAAU,WAAW;EACzH,MAAM,oCAAwB;GAAC;GAAQ;GAAO;GAAU;KAAU,QAAQ,QAAQ,QAAQ,MAAM,UAAU,IAAI,MAA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