fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: cleanup

Lubos 80dc0151 4ae906d2

+3268 -3946
+5
.changeset/modern-colts-hang.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + feat(plugin): add `@pinia/colada` plugin
+20 -7
packages/openapi-ts-tests/main/test/openapi-ts.config.ts
··· 36 36 '3.1.x', 37 37 // 'invalid', 38 38 // 'openai.yaml', 39 - // 'full.yaml', 39 + 'full.yaml', 40 40 // 'opencode.yaml', 41 - 'zoom-video-sdk.json', 41 + // 'zoom-video-sdk.json', 42 42 ), 43 43 // https://registry.scalar.com/@lubos-heyapi-dev-team/apis/demo-api-scalar-galaxy/latest?format=json 44 44 // path: 'scalar:@lubos-heyapi-dev-team/demo-api-scalar-galaxy', ··· 81 81 // deprecated: false, 82 82 operations: { 83 83 include: [ 84 - 'GET /event', 84 + // 'GET /event', 85 85 // '/^[A-Z]+ /v1//', 86 86 ], 87 87 }, ··· 94 94 // exclude: ['bar'], 95 95 // }, 96 96 }, 97 + hooks: { 98 + operations: { 99 + // isMutation: () => true, 100 + }, 101 + }, 97 102 pagination: { 98 103 // keywords: ['aa'], 99 104 }, ··· 171 176 // responseStyle: 'data', 172 177 // transformer: '@hey-api/transformers', 173 178 // transformer: true, 174 - validator: 'valibot', 179 + // validator: 'valibot', 175 180 // validator: { 176 181 // request: 'zod', 177 182 // response: 'zod', ··· 198 203 // mutationOptions: { 199 204 // name: '{{name}}MO', 200 205 // }, 201 - name: '@tanstack/react-query', 206 + // name: '@tanstack/react-query', 202 207 // queryKeys: { 203 208 // name: '{{name}}QK', 204 209 // }, ··· 212 217 definitions: 'z{{name}}Definition', 213 218 exportFromIndex: true, 214 219 metadata: true, 215 - name: 'valibot', 220 + // name: 'valibot', 216 221 requests: { 217 222 // case: 'SCREAMING_SNAKE_CASE', 218 223 name: 'z{{name}}TestData', ··· 241 246 }, 242 247 exportFromIndex: true, 243 248 metadata: true, 244 - name: 'zod', 249 + // name: 'zod', 245 250 // requests: { 246 251 // // case: 'SCREAMING_SNAKE_CASE', 247 252 // // name: 'z{{name}}TestData', ··· 272 277 // httpResource 273 278 exportFromIndex: true, 274 279 // name: '@angular/common', 280 + }, 281 + { 282 + name: '@pinia/colada', 283 + '~hooks': { 284 + operations: { 285 + // isQuery: () => true, 286 + }, 287 + }, 275 288 }, 276 289 ], 277 290 // useOptions: false,
+1 -20
packages/openapi-ts-tests/main/test/plugins/@pinia/colada-functional.test.ts
··· 5 5 import { createClient } from '@hey-api/openapi-ts'; 6 6 import { describe, expect, it, vi } from 'vitest'; 7 7 8 - import { getSpecsPath } from '../../../utils'; 8 + import { getSpecsPath } from '../../../../utils'; 9 9 10 10 const __filename = fileURLToPath(import.meta.url); 11 11 const __dirname = path.dirname(__filename); ··· 69 69 70 70 expect(mutationOptions).toHaveProperty('mutation'); 71 71 expect(typeof mutationOptions.mutation).toBe('function'); 72 - }); 73 - 74 - it('should respect autoDetectHttpMethod setting', async () => { 75 - const piniaColadaDefault = await setupPiniaColadaTest({ 76 - autoDetectHttpMethod: true, 77 - }); 78 - 79 - // With auto-detection, GET should be query, POST should be mutation 80 - expect(piniaColadaDefault.getPetByIdQuery).toBeDefined(); // GET -> query 81 - expect(piniaColadaDefault.addPetMutation).toBeDefined(); // POST -> mutation 82 - expect(piniaColadaDefault.addPetQuery).toBeUndefined(); // POST should not generate query 83 - 84 - const piniaColadaDisabled = await setupPiniaColadaTest({ 85 - autoDetectHttpMethod: false, 86 - }); 87 - 88 - // With auto-detection disabled, both GET and POST should generate queries (legacy behavior) 89 - expect(piniaColadaDisabled.getPetByIdQuery).toBeDefined(); 90 - // Note: The legacy behavior test might need adjustment based on actual implementation 91 72 }); 92 73 93 74 it('should respect operation type overrides', async () => {
+16 -8
packages/openapi-ts-tests/main/test/plugins/@pinia/colada-integration.test.ts
··· 5 5 import { createClient, type UserConfig } from '@hey-api/openapi-ts'; 6 6 import { describe, expect, it } from 'vitest'; 7 7 8 - import { getFilePaths, getSpecsPath } from '../../../utils'; 8 + import { getFilePaths, getSpecsPath } from '../../../../utils'; 9 9 10 10 const __filename = fileURLToPath(import.meta.url); 11 11 const __dirname = path.dirname(__filename); ··· 14 14 const outputDir = path.join(__dirname, 'generated', version, 'integration'); 15 15 16 16 describe('@pinia/colada integration tests', () => { 17 - const createConfig = (userConfig: UserConfig): UserConfig => { 17 + const createConfig = ( 18 + userConfig: Omit<UserConfig, 'input'> & Pick<Partial<UserConfig>, 'input'>, 19 + ): UserConfig => { 18 20 const inputPath = path.join(getSpecsPath(), version, 'petstore.yaml'); 19 21 return { 20 - input: inputPath, 21 - logs: { level: 'silent' }, 22 - output: path.join( 23 - outputDir, 24 - typeof userConfig.output === 'string' ? userConfig.output : '', 25 - ), 22 + logs: { 23 + level: 'silent', 24 + }, 26 25 ...userConfig, 26 + input: userConfig.input ?? inputPath, 27 + output: 28 + userConfig.output ?? 29 + path.join( 30 + outputDir, 31 + typeof userConfig.output === 'string' ? userConfig.output : '', 32 + ), 27 33 }; 28 34 }; 29 35 ··· 70 76 '@hey-api/client-fetch', 71 77 { 72 78 name: '@hey-api/sdk', 79 + // @ts-expect-error 73 80 transformer: { 74 81 name: 'custom', 75 82 }, ··· 113 120 plugins: [ 114 121 '@hey-api/client-fetch', 115 122 { 123 + // @ts-expect-error 116 124 case: 'PascalCase', 117 125 name: '@hey-api/sdk', 118 126 },
+1 -1
packages/openapi-ts-tests/main/test/plugins/@pinia/colada-meta-functions.test.ts
··· 5 5 import { createClient, type UserConfig } from '@hey-api/openapi-ts'; 6 6 import { describe, expect, it } from 'vitest'; 7 7 8 - import { getFilePaths, getSpecsPath } from '../../../utils'; 8 + import { getFilePaths, getSpecsPath } from '../../../../utils'; 9 9 10 10 const __filename = fileURLToPath(import.meta.url); 11 11 const __dirname = path.dirname(__filename);
+1
packages/openapi-ts/src/config/parser.ts
··· 13 13 export const getParser = (userConfig: UserConfig): Config['parser'] => { 14 14 const parser: Config['parser'] = { 15 15 ...userConfig.parser, 16 + hooks: {}, 16 17 pagination: { 17 18 keywords: defaultPaginationKeywords, 18 19 },
+2 -25
packages/openapi-ts/src/ir/context.ts
··· 6 6 import type { PluginConfigMap } from '../plugins/config'; 7 7 import { PluginInstance } from '../plugins/shared/utils/instance'; 8 8 import type { PluginNames } from '../plugins/types'; 9 - import type { StringCase } from '../types/case'; 10 9 import type { Config } from '../types/config'; 11 10 import type { Files } from '../types/utils'; 12 11 import type { Logger } from '../utils/logger'; 13 12 import { resolveRef } from '../utils/ref'; 14 13 import type { IR } from './types'; 15 14 16 - export interface ContextFile { 17 - /** 18 - * Define casing for identifiers in this file. 19 - */ 20 - case?: StringCase; 21 - /** 22 - * Should the exports from this file be re-exported in the index barrel file? 23 - */ 24 - exportFromIndex?: boolean; 25 - /** 26 - * Unique file identifier. 27 - */ 28 - id: string; 29 - /** 30 - * Relative file path to the output path. 31 - * 32 - * @example 33 - * 'bar/foo.ts' 34 - */ 35 - path: string; 36 - } 37 - 38 15 export class IRContext<Spec extends Record<string, any> = any> { 39 16 /** 40 17 * Configuration for parsing and generating the output. This ··· 92 69 * Create and return a new TypeScript file. Also set the current file context 93 70 * to the newly created file. 94 71 */ 95 - public createFile(file: ContextFile): GeneratedFile { 72 + public createFile(file: IR.ContextFile): GeneratedFile { 96 73 // TODO: parser - handle attempt to create duplicate 97 74 const outputParts = file.path.split('/'); 98 75 const outputDir = path.resolve( ··· 127 104 /** 128 105 * Returns a specific file by ID from `files`. 129 106 */ 130 - public file({ id }: Pick<ContextFile, 'id'>): GeneratedFile | undefined { 107 + public file({ id }: Pick<IR.ContextFile, 'id'>): GeneratedFile | undefined { 131 108 return this.files[id]; 132 109 } 133 110
+84 -2
packages/openapi-ts/src/ir/types.d.ts
··· 3 3 SecuritySchemeObject, 4 4 ServerObject, 5 5 } from '../openApi/3.1.x/types/spec'; 6 - import type { ContextFile as CtxFile, IRContext } from './context'; 6 + import type { StringCase } from '../types/case'; 7 + import type { IRContext } from './context'; 7 8 import type { IRMediaType } from './mediaType'; 8 9 9 10 interface IRBodyObject { ··· 22 23 parameters?: Record<string, IRParameterObject>; 23 24 requestBodies?: Record<string, IRRequestBodyObject>; 24 25 schemas?: Record<string, IRSchemaObject>; 26 + } 27 + 28 + interface IRContextFile { 29 + /** 30 + * Define casing for identifiers in this file. 31 + */ 32 + case?: StringCase; 33 + /** 34 + * Should the exports from this file be re-exported in the index barrel file? 35 + */ 36 + exportFromIndex?: boolean; 37 + /** 38 + * Unique file identifier. 39 + */ 40 + id: string; 41 + /** 42 + * Relative file path to the output path. 43 + * 44 + * @example 45 + * 'bar/foo.ts' 46 + */ 47 + path: string; 48 + } 49 + 50 + interface IRHooks { 51 + /** 52 + * Hooks specifically for overriding operations behavior. 53 + * 54 + * Use these to classify operations, decide which outputs to generate, 55 + * or apply custom behavior to individual operations. 56 + */ 57 + operations?: { 58 + /** 59 + * Classify the given operation into one or more kinds. 60 + * 61 + * Each kind determines how we treat the operation (e.g., generating queries or mutations). 62 + * 63 + * **Default behavior:** 64 + * - GET → 'query' 65 + * - DELETE, PATCH, POST, PUT → 'mutation' 66 + * 67 + * **Resolution order:** 68 + * 1. If `isQuery` or `isMutation` returns `true` or `false`, that overrides `getKind`. 69 + * 2. If `isQuery` or `isMutation` returns `undefined`, the result of `getKind` is used. 70 + * 71 + * @param operation - The operation object to classify. 72 + * @returns An array containing one or more of 'query' or 'mutation'. 73 + */ 74 + getKind?: ( 75 + operation: IROperationObject, 76 + ) => ReadonlyArray<'mutation' | 'query'>; 77 + /** 78 + * Check if the given operation should be treated as a mutation. 79 + * 80 + * This affects which outputs are generated for the operation. 81 + * 82 + * **Default behavior:** DELETE, PATCH, POST, and PUT operations are treated as mutations. 83 + * 84 + * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`. 85 + * If it returns `undefined`, `getKind` is used instead. 86 + * 87 + * @param operation - The operation object to check. 88 + * @returns true if the operation is a mutation, false otherwise, or undefined to fallback to `getKind`. 89 + */ 90 + isMutation?: (operation: IROperationObject) => boolean | undefined; 91 + /** 92 + * Check if the given operation should be treated as a query. 93 + * 94 + * This affects which outputs are generated for the operation. 95 + * 96 + * **Default behavior:** GET operations are treated as queries. 97 + * 98 + * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`. 99 + * If it returns `undefined`, `getKind` is used instead. 100 + * 101 + * @param operation - The operation object to check. 102 + * @returns true if the operation is a query, false otherwise, or undefined to fallback to `getKind`. 103 + */ 104 + isQuery?: (operation: IROperationObject) => boolean | undefined; 105 + }; 25 106 } 26 107 27 108 interface IROperationObject { ··· 221 302 export type BodyObject = IRBodyObject; 222 303 export type ComponentsObject = IRComponentsObject; 223 304 export type Context<Spec extends Record<string, any> = any> = IRContext<Spec>; 224 - export type ContextFile = CtxFile; 305 + export type ContextFile = IRContextFile; 306 + export type Hooks = IRHooks; 225 307 export type Model = IRModel; 226 308 export type OperationObject = IROperationObject; 227 309 export type ParameterObject = IRParameterObject;
+9 -23
packages/openapi-ts/src/plugins/@pinia/colada/__tests__/plugin.test.ts
··· 49 49 describe('HTTP method auto-detection', () => { 50 50 it('should generate query for GET requests when autoDetectHttpMethod is true', () => { 51 51 const operation = createMockOperation('get'); 52 - const plugin = createMockPlugin({ autoDetectHttpMethod: true }); 52 + const plugin = createMockPlugin(); 53 53 54 54 // Test the logic: GET should generate query 55 55 const shouldGenerateQuery = ··· 62 62 63 63 it('should generate mutation for POST requests when autoDetectHttpMethod is true', () => { 64 64 const operation = createMockOperation('post'); 65 - const plugin = createMockPlugin({ autoDetectHttpMethod: true }); 65 + const plugin = createMockPlugin(); 66 66 67 67 // Test the logic: POST should generate mutation 68 68 const shouldGenerateMutation = ··· 75 75 76 76 it('should generate mutation for PUT requests when autoDetectHttpMethod is true', () => { 77 77 const operation = createMockOperation('put'); 78 - const plugin = createMockPlugin({ autoDetectHttpMethod: true }); 78 + const plugin = createMockPlugin(); 79 79 80 80 const shouldGenerateMutation = 81 81 !plugin.config.operationTypes[operation.id] && ··· 87 87 88 88 it('should generate mutation for DELETE requests when autoDetectHttpMethod is true', () => { 89 89 const operation = createMockOperation('delete'); 90 - const plugin = createMockPlugin({ autoDetectHttpMethod: true }); 90 + const plugin = createMockPlugin(); 91 91 92 92 const shouldGenerateMutation = 93 93 !plugin.config.operationTypes[operation.id] && ··· 100 100 it('should fall back to legacy behavior when autoDetectHttpMethod is false', () => { 101 101 const getOperation = createMockOperation('get'); 102 102 const postOperation = createMockOperation('post'); 103 - const plugin = createMockPlugin({ autoDetectHttpMethod: false }); 103 + const plugin = createMockPlugin(); 104 104 105 105 // Verify the plugin config is set correctly 106 106 expect(plugin.config.autoDetectHttpMethod).toBe(false); ··· 121 121 describe('Operation type overrides', () => { 122 122 it('should respect explicit query override', () => { 123 123 const operation = createMockOperation('post', 'testOp'); 124 - const plugin = createMockPlugin({ 125 - operationTypes: { testOp: 'query' }, 126 - }); 124 + const plugin = createMockPlugin(); 127 125 128 126 // Override should force POST to be a query 129 127 const override = plugin.config.operationTypes[operation.id]; ··· 137 135 138 136 it('should respect explicit mutation override', () => { 139 137 const operation = createMockOperation('get', 'testOp'); 140 - const plugin = createMockPlugin({ 141 - operationTypes: { testOp: 'mutation' }, 142 - }); 138 + const plugin = createMockPlugin(); 143 139 144 140 // Override should force GET to be a mutation 145 141 const override = plugin.config.operationTypes[operation.id]; ··· 153 149 154 150 it('should generate both query and mutation when override is "both"', () => { 155 151 const operation = createMockOperation('get', 'testOp'); 156 - const plugin = createMockPlugin({ 157 - operationTypes: { testOp: 'both' }, 158 - }); 152 + const plugin = createMockPlugin(); 159 153 160 154 const override = plugin.config.operationTypes[operation.id]; 161 155 const shouldGenerateQuery = override === 'query' || override === 'both'; ··· 248 242 createMockOperation('delete', 'deletePet', ['pet']), 249 243 ]; 250 244 251 - const plugin = createMockPlugin({ 252 - autoDetectHttpMethod: true, 253 - groupByTag: true, 254 - operationTypes: { 255 - // Force GET to generate both 256 - addPet: 'query', 257 - getPet: 'both', // Force POST to be query only 258 - }, 259 - }); 245 + const plugin = createMockPlugin({ groupByTag: true }); 260 246 261 247 operations.forEach((operation) => { 262 248 const override = plugin.config.operationTypes[operation.id];
-26
packages/openapi-ts/src/plugins/@pinia/colada/config-josh.ts
··· 1 - import { definePluginConfig } from '../../shared/utils/config'; 2 - import { handler } from './plugin'; 3 - import type { PiniaColadaPlugin } from './types'; 4 - 5 - export const defaultConfig: PiniaColadaPlugin['Config'] = { 6 - config: { 7 - enablePaginationOnKey: undefined, 8 - errorHandling: 'specific', 9 - exportFromIndex: false, 10 - groupByTag: false, 11 - importPath: '@pinia/colada', 12 - includeTypes: true, 13 - prefixUse: true, 14 - suffixQueryMutation: true, 15 - useInfiniteQueries: false, 16 - }, 17 - dependencies: ['@hey-api/typescript'], 18 - handler: handler as PiniaColadaPlugin['Handler'], 19 - name: '@pinia/colada', 20 - output: '@pinia/colada', 21 - }; 22 - 23 - /** 24 - * Type helper for `@pinia/colada` plugin, returns {@link Plugin.Config} object 25 - */ 26 - export const defineConfig = definePluginConfig(defaultConfig);
+1 -5
packages/openapi-ts/src/plugins/@pinia/colada/config.ts
··· 4 4 5 5 export const defaultConfig: PiniaColadaPlugin['Config'] = { 6 6 config: { 7 - autoDetectHttpMethod: true, 8 7 case: 'camelCase', 9 8 comments: true, 10 9 exportFromIndex: false, 11 10 groupByTag: false, 12 - operationTypes: {}, 13 11 }, 14 - dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 12 + dependencies: ['@hey-api/typescript', '@hey-api/sdk'], 15 13 handler: handler as PiniaColadaPlugin['Handler'], 16 14 name: '@pinia/colada', 17 15 output: '@pinia/colada', ··· 20 18 defaultValue: { 21 19 case: plugin.config.case ?? 'camelCase', 22 20 enabled: true, 23 - meta: false, 24 21 name: '{{name}}Mutation', 25 22 }, 26 23 mappers: { ··· 35 32 defaultValue: { 36 33 case: plugin.config.case ?? 'camelCase', 37 34 enabled: true, 38 - meta: false, 39 35 name: '{{name}}Query', 40 36 }, 41 37 mappers: {
+19
packages/openapi-ts/src/plugins/@pinia/colada/meta.ts
··· 1 + import type ts from 'typescript'; 2 + 3 + import type { IR } from '../../../ir/types'; 4 + import { tsc } from '../../../tsc'; 5 + import type { PiniaColadaPlugin } from './types'; 6 + 7 + export const handleMeta = ( 8 + plugin: PiniaColadaPlugin['Instance'], 9 + operation: IR.OperationObject, 10 + configPath: 'queryOptions' | 'mutationOptions', 11 + ): ts.Expression | undefined => { 12 + const metaFn = plugin.config[configPath].meta; 13 + if (!metaFn) return; 14 + 15 + const metaObject = metaFn(operation); 16 + if (!Object.keys(metaObject).length) return; 17 + 18 + return tsc.valueToExpression({ value: metaObject }); 19 + };
+118 -12
packages/openapi-ts/src/plugins/@pinia/colada/mutation.ts
··· 1 + import type ts from 'typescript'; 2 + 1 3 import type { GeneratedFile } from '../../../generate/file'; 2 4 import type { IR } from '../../../ir/types'; 5 + import { tsc } from '../../../tsc'; 6 + import { 7 + createOperationComment, 8 + isOperationOptionsRequired, 9 + } from '../../shared/utils/operation'; 10 + import { handleMeta } from './meta'; 11 + import type { PluginState } from './state'; 3 12 import type { PiniaColadaPlugin } from './types'; 4 - import { createComposable } from './utils'; 13 + import { useTypeData } from './utils'; 5 14 6 - /** 7 - * Creates a mutation function for an operation 8 - */ 9 - export const createMutationFunction = ({ 10 - context, 15 + export const createMutationOptions = ({ 11 16 file, 12 17 operation, 13 18 plugin, 19 + queryFn, 20 + state, 14 21 }: { 15 - context: IR.Context; 16 22 file: GeneratedFile; 17 23 operation: IR.OperationObject; 18 24 plugin: PiniaColadaPlugin['Instance']; 19 - }) => { 20 - // Allow hooks to customize or skip mutation generation 25 + queryFn: string; 26 + state: PluginState; 27 + }): void => { 21 28 if ( 22 - plugin.config.onMutation && 23 - plugin.config.onMutation(operation) === false 29 + !plugin.config.mutationOptions.enabled || 30 + !plugin.hooks.operation.isMutation(operation) 24 31 ) { 25 32 return; 26 33 } 27 34 28 - createComposable({ context, file, isQuery: false, operation, plugin }); 35 + if (!state.hasMutations) { 36 + state.hasMutations = true; 37 + } 38 + 39 + state.hasUsedQueryFn = true; 40 + 41 + const typeData = useTypeData({ file, operation, plugin }); 42 + 43 + const identifierMutationOptions = file.identifier({ 44 + $ref: `#/pinia-colada-mutation-options/${operation.id}`, 45 + case: plugin.config.mutationOptions.case, 46 + create: true, 47 + nameTransformer: plugin.config.mutationOptions.name, 48 + namespace: 'value', 49 + }); 50 + 51 + const awaitSdkExpression = tsc.awaitExpression({ 52 + expression: tsc.callExpression({ 53 + functionName: queryFn, 54 + parameters: ['options'], 55 + }), 56 + }); 57 + 58 + const statements: Array<ts.Statement> = []; 59 + 60 + if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 61 + statements.push( 62 + tsc.returnVariable({ 63 + expression: awaitSdkExpression, 64 + }), 65 + ); 66 + } else { 67 + statements.push( 68 + tsc.constVariable({ 69 + destructure: true, 70 + expression: awaitSdkExpression, 71 + name: 'data', 72 + }), 73 + tsc.returnVariable({ 74 + expression: 'data', 75 + }), 76 + ); 77 + } 78 + 79 + const mutationOptionsObj: Array<{ key: string; value: ts.Expression }> = [ 80 + { 81 + key: 'mutation', 82 + value: tsc.arrowFunction({ 83 + async: true, 84 + multiLine: true, 85 + parameters: [ 86 + { 87 + name: 'options', 88 + type: typeData, 89 + }, 90 + ], 91 + statements, 92 + }), 93 + }, 94 + ]; 95 + 96 + const meta = handleMeta(plugin, operation, 'mutationOptions'); 97 + 98 + if (meta) { 99 + mutationOptionsObj.push({ 100 + key: 'meta', 101 + value: meta, 102 + }); 103 + } 104 + 105 + const isRequiredOptionsForMutation = isOperationOptionsRequired({ 106 + context: plugin.context, 107 + operation, 108 + }); 109 + 110 + const statement = tsc.constVariable({ 111 + comment: plugin.config.comments 112 + ? createOperationComment({ operation }) 113 + : undefined, 114 + exportConst: true, 115 + expression: tsc.arrowFunction({ 116 + parameters: [ 117 + { 118 + isRequired: isRequiredOptionsForMutation, 119 + name: 'options', 120 + type: typeData, 121 + }, 122 + ], 123 + statements: [ 124 + tsc.returnStatement({ 125 + expression: tsc.objectExpression({ 126 + obj: mutationOptionsObj, 127 + }), 128 + }), 129 + ], 130 + }), 131 + name: identifierMutationOptions.name || '', 132 + }); 133 + 134 + file.add(statement); 29 135 };
-67
packages/openapi-ts/src/plugins/@pinia/colada/plugin-josh.ts
··· 1 - import { clientId } from '../../@hey-api/client-core/utils'; 2 - import { createMutationFunction } from './mutation'; 3 - import { createQueryFunction } from './query'; 4 - import type { PiniaColadaPlugin } from './types'; 5 - import { isQuery } from './utils'; 6 - 7 - export const handler: PiniaColadaPlugin['Handler'] = ({ plugin }) => { 8 - if (!plugin.config.groupByTag) { 9 - plugin.createFile({ 10 - id: plugin.name, 11 - path: plugin.output, 12 - }); 13 - } 14 - 15 - // Create files based on grouping strategy 16 - const getFile = (tag: string) => { 17 - if (!plugin.config.groupByTag) { 18 - return ( 19 - plugin.context.file({ id: plugin.name }) ?? 20 - plugin.createFile({ 21 - id: plugin.name, 22 - path: plugin.output, 23 - }) 24 - ); 25 - } 26 - 27 - const fileId = `${plugin.name}/${tag}`; 28 - return ( 29 - plugin.context.file({ id: fileId }) ?? 30 - plugin.createFile({ 31 - id: fileId, 32 - path: `${plugin.output}/${tag}`, 33 - }) 34 - ); 35 - }; 36 - 37 - plugin.forEach('operation', ({ operation }) => { 38 - const file = getFile(operation.tags?.[0] || 'default'); 39 - 40 - // Determine if the operation should be a query or mutation 41 - if (isQuery(operation, plugin)) { 42 - createQueryFunction({ context: plugin.context, file, operation, plugin }); 43 - } else { 44 - createMutationFunction({ 45 - context: plugin.context, 46 - file, 47 - operation, 48 - plugin, 49 - }); 50 - } 51 - }); 52 - 53 - // Add client import to all generated files 54 - Object.entries(plugin.context.files).forEach(([fileId, file]) => { 55 - if (fileId.startsWith(plugin.name)) { 56 - // Make sure we have a client import 57 - file.import({ 58 - alias: '_heyApiClient', 59 - module: file.relativePathToFile({ 60 - context: plugin.context, 61 - id: clientId, 62 - }), 63 - name: 'client', 64 - }); 65 - } 66 - }); 67 - };
+70 -482
packages/openapi-ts/src/plugins/@pinia/colada/plugin.ts
··· 1 - import type ts from 'typescript'; 2 - 3 - import { clientApi } from '../../../generate/client'; 4 - import type { IR } from '../../../ir/types'; 1 + import type { GeneratedFile } from '../../../generate/file'; 5 2 import { tsc } from '../../../tsc'; 6 3 import { stringCase } from '../../../utils/stringCase'; 7 4 import { sdkId } from '../../@hey-api/sdk/constants'; 8 - import { 9 - operationClasses, 10 - operationOptionsType, 11 - } from '../../@hey-api/sdk/operation'; 5 + import { operationClasses } from '../../@hey-api/sdk/operation'; 12 6 import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 13 - import { 14 - createOperationComment, 15 - isOperationOptionsRequired, 16 - } from '../../shared/utils/operation'; 7 + import { createMutationOptions } from './mutation'; 8 + import { createQueryOptions } from './query'; 9 + import type { PluginState } from './state'; 17 10 import type { PiniaColadaPlugin } from './types'; 18 - 19 - type PluginHandler = PiniaColadaPlugin['Handler']; 20 - type PluginInstance = PiniaColadaPlugin['Instance']; 21 - 22 - interface PluginState { 23 - hasMutations: boolean; 24 - hasQueries: boolean; 25 - hasUsedQueryFn: boolean; 26 - } 27 - 28 - const handleMeta = ( 29 - plugin: PluginInstance, 30 - operation: IR.OperationObject, 31 - type: 'queryOptions' | 'mutationOptions', 32 - ): ts.Expression | undefined => { 33 - const metaConfig = plugin.config[type].meta; 34 - 35 - if (typeof metaConfig !== 'function') { 36 - return undefined; 37 - } 38 - 39 - const customMeta = metaConfig(operation); 40 - 41 - return tsc.valueToExpression({ value: customMeta }); 42 - }; 43 - 44 - const useTypeData = ({ 45 - file, 46 - operation, 47 - plugin, 48 - }: { 49 - file: ReturnType<PluginInstance['createFile']>; 50 - operation: IR.OperationObject; 51 - plugin: PluginInstance; 52 - }) => { 53 - const pluginSdk = plugin.getPlugin('@hey-api/sdk')!; 54 - const typeData = operationOptionsType({ file, operation, plugin: pluginSdk }); 55 - return typeData; 56 - }; 57 - 58 - const shouldGenerateQuery = ( 59 - operation: IR.OperationObject, 60 - plugin: PluginInstance, 61 - ): boolean => { 62 - // Check for explicit override first 63 - const override = plugin.config.operationTypes[operation.id]; 64 - if (override === 'mutation') return false; 65 - if (override === 'query' || override === 'both') return true; 66 - 67 - // Use auto-detection if enabled 68 - if (plugin.config.autoDetectHttpMethod) { 69 - return operation.method === 'get'; 70 - } 11 + import { getFileForOperation } from './utils'; 71 12 72 - // Default behavior (backward compatibility) 73 - return ['get', 'post'].includes(operation.method); 74 - }; 13 + export const handler: PiniaColadaPlugin['Handler'] = ({ plugin }) => { 14 + const files = new Map<string, GeneratedFile>(); 15 + const states = new Map<string, PluginState>(); 75 16 76 - const shouldGenerateMutation = ( 77 - operation: IR.OperationObject, 78 - plugin: PluginInstance, 79 - ): boolean => { 80 - // Check for explicit override first 81 - const override = plugin.config.operationTypes[operation.id]; 82 - if (override === 'query') return false; 83 - if (override === 'mutation' || override === 'both') return true; 84 - 85 - // Use auto-detection if enabled 86 - if (plugin.config.autoDetectHttpMethod) { 87 - return operation.method !== 'get'; 88 - } 89 - 90 - // Default behavior (backward compatibility) 91 - return operation.method !== 'get'; 92 - }; 93 - 94 - const createQueryOptions = ({ 95 - file, 96 - operation, 97 - plugin, 98 - queryFn, 99 - state, 100 - }: { 101 - file: ReturnType<PluginInstance['createFile']>; 102 - operation: IR.OperationObject; 103 - plugin: PluginInstance; 104 - queryFn: string; 105 - state: PluginState; 106 - }) => { 107 - if (!plugin.config.queryOptions || !shouldGenerateQuery(operation, plugin)) { 108 - return state; 109 - } 110 - const isRequiredOptions = isOperationOptionsRequired({ 111 - context: plugin.context, 112 - operation, 113 - }); 114 - 115 - if (!state.hasQueries) { 116 - state.hasQueries = true; 117 - } 118 - 119 - state.hasUsedQueryFn = true; 120 - 121 - const typeData = useTypeData({ file, operation, plugin }); 122 - 123 - const identifierQueryOptions = file.identifier({ 124 - $ref: `#/pinia-colada-query-options/${operation.id}`, 125 - case: plugin.config.queryOptions.case, 126 - create: true, 127 - nameTransformer: plugin.config.queryOptions.name, 128 - namespace: 'value', 129 - }); 17 + plugin.forEach('operation', ({ operation }) => { 18 + const { file, state } = getFileForOperation({ 19 + files, 20 + operation, 21 + plugin, 22 + states, 23 + }); 24 + state.hasUsedQueryFn = false; 130 25 131 - const awaitSdkExpression = tsc.awaitExpression({ 132 - expression: tsc.callExpression({ 133 - functionName: queryFn, 134 - parameters: [ 135 - tsc.objectExpression({ 136 - multiLine: true, 137 - obj: [ 138 - { 139 - spread: 'options', 140 - }, 141 - { 142 - key: 'signal', 143 - value: tsc.identifier({ 144 - text: 'context.signal', 26 + const sdkPlugin = plugin.getPlugin('@hey-api/sdk')!; 27 + const classes = sdkPlugin.config.asClass 28 + ? operationClasses({ 29 + context: plugin.context, 30 + operation, 31 + plugin: sdkPlugin, 32 + }) 33 + : undefined; 34 + const entry = classes ? classes.values().next().value : undefined; 35 + const queryFn = 36 + // TODO: this should use class graph to determine correct path string 37 + // as it's really easy to break once we change the class casing 38 + ( 39 + entry 40 + ? [ 41 + entry.path[0], 42 + ...entry.path.slice(1).map((className: string) => 43 + stringCase({ 44 + case: 'camelCase', 45 + value: className, 46 + }), 47 + ), 48 + entry.methodName, 49 + ].filter(Boolean) 50 + : [ 51 + serviceFunctionIdentifier({ 52 + config: plugin.context.config, 53 + handleIllegal: true, 54 + id: operation.id, 55 + operation, 145 56 }), 146 - }, 147 - { 148 - key: 'throwOnError', 149 - value: true, 150 - }, 151 - ], 152 - }), 153 - ], 154 - }), 155 - }); 156 - 157 - const statements: Array<ts.Statement> = []; 158 - 159 - if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 160 - statements.push( 161 - tsc.returnVariable({ 162 - expression: awaitSdkExpression, 163 - }), 164 - ); 165 - } else { 166 - statements.push( 167 - tsc.constVariable({ 168 - destructure: true, 169 - expression: awaitSdkExpression, 170 - name: 'data', 171 - }), 172 - tsc.returnVariable({ 173 - expression: 'data', 174 - }), 175 - ); 176 - } 57 + ] 58 + ).join('.'); 177 59 178 - // Generate query options object for Pinia Colada 179 - const queryOptionsObj: Array<{ key: string; value: ts.Expression }> = [ 180 - { 181 - key: 'key', 182 - value: tsc.arrayLiteralExpression({ 183 - elements: [ 184 - tsc.stringLiteral({ text: operation.id || '' }), 185 - tsc.identifier({ text: 'options?.path' }), 186 - ], 187 - }), 188 - }, 189 - { 190 - key: 'query', 191 - value: tsc.arrowFunction({ 192 - async: true, 193 - multiLine: true, 194 - parameters: [ 195 - { 196 - name: 'context', 197 - type: tsc.typeReferenceNode({ 198 - typeName: '{ signal: AbortSignal }', 199 - }), 200 - }, 201 - ], 202 - statements, 203 - }), 204 - }, 205 - ]; 206 - 207 - const meta = handleMeta(plugin, operation, 'queryOptions'); 208 - 209 - if (meta) { 210 - queryOptionsObj.push({ 211 - key: 'meta', 212 - value: meta, 60 + createQueryOptions({ 61 + file, 62 + operation, 63 + plugin, 64 + queryFn, 65 + state, 213 66 }); 214 - } 215 67 216 - const statement = tsc.constVariable({ 217 - comment: plugin.config.comments 218 - ? createOperationComment({ operation }) 219 - : undefined, 220 - exportConst: true, 221 - expression: tsc.arrowFunction({ 222 - parameters: [ 223 - { 224 - isRequired: isRequiredOptions, 225 - name: 'options', 226 - type: typeData, 227 - }, 228 - ], 229 - statements: [ 230 - tsc.returnStatement({ 231 - expression: tsc.objectExpression({ 232 - obj: queryOptionsObj, 233 - }), 234 - }), 235 - ], 236 - }), 237 - name: identifierQueryOptions.name || '', 238 - }); 239 - 240 - file.add(statement); 241 - 242 - return state; 243 - }; 244 - 245 - const createMutationOptions = ({ 246 - file, 247 - operation, 248 - plugin, 249 - queryFn, 250 - state, 251 - }: { 252 - file: ReturnType<PluginInstance['createFile']>; 253 - operation: IR.OperationObject; 254 - plugin: PluginInstance; 255 - queryFn: string; 256 - state: PluginState; 257 - }) => { 258 - if ( 259 - !plugin.config.mutationOptions || 260 - !shouldGenerateMutation(operation, plugin) 261 - ) { 262 - return state; 263 - } 264 - 265 - if (!state.hasMutations) { 266 - state.hasMutations = true; 267 - } 268 - 269 - state.hasUsedQueryFn = true; 270 - 271 - const typeData = useTypeData({ file, operation, plugin }); 272 - 273 - const identifierMutationOptions = file.identifier({ 274 - $ref: `#/pinia-colada-mutation-options/${operation.id}`, 275 - case: plugin.config.mutationOptions.case, 276 - create: true, 277 - nameTransformer: plugin.config.mutationOptions.name, 278 - namespace: 'value', 279 - }); 280 - 281 - const awaitSdkExpression = tsc.awaitExpression({ 282 - expression: tsc.callExpression({ 283 - functionName: queryFn, 284 - parameters: ['options'], 285 - }), 286 - }); 287 - 288 - const statements: Array<ts.Statement> = []; 289 - 290 - if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 291 - statements.push( 292 - tsc.returnVariable({ 293 - expression: awaitSdkExpression, 294 - }), 295 - ); 296 - } else { 297 - statements.push( 298 - tsc.constVariable({ 299 - destructure: true, 300 - expression: awaitSdkExpression, 301 - name: 'data', 302 - }), 303 - tsc.returnVariable({ 304 - expression: 'data', 305 - }), 306 - ); 307 - } 308 - 309 - // Generate mutation options object for Pinia Colada 310 - const mutationOptionsObj: Array<{ key: string; value: ts.Expression }> = [ 311 - { 312 - key: 'mutation', 313 - value: tsc.arrowFunction({ 314 - async: true, 315 - multiLine: true, 316 - parameters: [ 317 - { 318 - name: 'options', 319 - type: typeData, 320 - }, 321 - ], 322 - statements, 323 - }), 324 - }, 325 - ]; 326 - 327 - const meta = handleMeta(plugin, operation, 'mutationOptions'); 328 - 329 - if (meta) { 330 - mutationOptionsObj.push({ 331 - key: 'meta', 332 - value: meta, 68 + createMutationOptions({ 69 + file, 70 + operation, 71 + plugin, 72 + queryFn, 73 + state, 333 74 }); 334 - } 335 75 336 - const isRequiredOptionsForMutation = isOperationOptionsRequired({ 337 - context: plugin.context, 338 - operation, 339 - }); 340 - 341 - const statement = tsc.constVariable({ 342 - comment: plugin.config.comments 343 - ? createOperationComment({ operation }) 344 - : undefined, 345 - exportConst: true, 346 - expression: tsc.arrowFunction({ 347 - parameters: [ 348 - { 349 - isRequired: isRequiredOptionsForMutation, 350 - name: 'options', 351 - type: typeData, 352 - }, 353 - ], 354 - statements: [ 355 - tsc.returnStatement({ 356 - expression: tsc.objectExpression({ 357 - obj: mutationOptionsObj, 358 - }), 359 - }), 360 - ], 361 - }), 362 - name: identifierMutationOptions.name || '', 363 - }); 364 - 365 - file.add(statement); 366 - 367 - return state; 368 - }; 369 - 370 - export const handler: PluginHandler = ({ plugin }) => { 371 - const filesMap = new Map<string, ReturnType<typeof plugin.createFile>>(); 372 - const stateMap = new Map<string, PluginState>(); 373 - 374 - // Helper to get or create file for an operation 375 - const getFileForOperation = (operation: IR.OperationObject) => { 376 - if (!plugin.config.groupByTag) { 377 - // Single file mode 378 - const fileId = plugin.name; 379 - if (!filesMap.has(fileId)) { 380 - const file = plugin.createFile({ 381 - case: plugin.config.case, 382 - id: fileId, 383 - path: plugin.output, 384 - }); 385 - filesMap.set(fileId, file); 386 - stateMap.set(fileId, { 387 - hasMutations: false, 388 - hasQueries: false, 389 - hasUsedQueryFn: false, 390 - }); 391 - // Import Options type from SDK 392 - file.import({ 393 - ...clientApi.Options, 394 - module: file.relativePathToFile({ 395 - context: plugin.context, 396 - id: sdkId, 397 - }), 398 - }); 399 - } 400 - return { file: filesMap.get(fileId)!, state: stateMap.get(fileId)! }; 401 - } 402 - 403 - // Group by tag mode 404 - const tag = operation.tags?.[0] || 'default'; 405 - const fileId = `${plugin.name}/${tag}`; 406 - 407 - if (!filesMap.has(fileId)) { 408 - const file = plugin.createFile({ 409 - case: plugin.config.case, 410 - id: fileId, 411 - path: `${plugin.output}/${tag}`, 412 - }); 413 - filesMap.set(fileId, file); 414 - stateMap.set(fileId, { 415 - hasMutations: false, 416 - hasQueries: false, 417 - hasUsedQueryFn: false, 418 - }); 419 - // Import Options type from SDK 76 + if (state.hasUsedQueryFn) { 420 77 file.import({ 421 - ...clientApi.Options, 422 - module: file.relativePathToFile({ context: plugin.context, id: sdkId }), 78 + module: file.relativePathToFile({ 79 + context: plugin.context, 80 + id: sdkId, 81 + }), 82 + name: queryFn.split('.')[0]!, 423 83 }); 424 84 } 425 - return { file: filesMap.get(fileId)!, state: stateMap.get(fileId)! }; 426 - }; 427 - 428 - plugin.forEach( 429 - 'operation', 430 - ({ operation }: { operation: IR.OperationObject }) => { 431 - const { file, state } = getFileForOperation(operation); 432 - state.hasUsedQueryFn = false; 433 - 434 - const sdkPlugin = plugin.getPlugin('@hey-api/sdk'); 435 - const classes = sdkPlugin?.config.asClass 436 - ? operationClasses({ 437 - context: plugin.context, 438 - operation, 439 - plugin: sdkPlugin, 440 - }) 441 - : undefined; 442 - const entry = classes ? classes.values().next().value : undefined; 443 - const queryFn = 444 - // TODO: this should use class graph to determine correct path string 445 - // as it's really easy to break once we change the class casing 446 - ( 447 - entry 448 - ? [ 449 - entry.path[0], 450 - ...entry.path.slice(1).map((className: string) => 451 - stringCase({ 452 - case: 'camelCase', 453 - value: className, 454 - }), 455 - ), 456 - entry.methodName, 457 - ].filter(Boolean) 458 - : [ 459 - serviceFunctionIdentifier({ 460 - config: plugin.context.config, 461 - handleIllegal: true, 462 - id: operation.id, 463 - operation, 464 - }), 465 - ] 466 - ).join('.'); 85 + }); 467 86 468 - createQueryOptions({ 469 - file, 470 - operation, 471 - plugin, 472 - queryFn, 473 - state, 474 - }); 475 - 476 - createMutationOptions({ 477 - file, 478 - operation, 479 - plugin, 480 - queryFn, 481 - state, 482 - }); 483 - 484 - if (state.hasUsedQueryFn) { 485 - file.import({ 486 - module: file.relativePathToFile({ 487 - context: plugin.context, 488 - id: sdkId, 489 - }), 490 - name: queryFn.split('.')[0]!, 491 - }); 492 - } 493 - }, 494 - ); 495 - 496 - // Note: Client import removed as it's not currently used in the generated code 497 - // The SDK functions are called directly instead 498 - 499 - // If groupByTag is enabled, create an index file that re-exports all tag files 87 + // re-export all split files 500 88 if (plugin.config.groupByTag && plugin.config.exportFromIndex) { 501 89 const indexFile = plugin.createFile({ 502 90 case: plugin.config.case, ··· 504 92 path: `${plugin.output}/index`, 505 93 }); 506 94 507 - filesMap.forEach((file, fileId) => { 95 + files.forEach((_, fileId) => { 508 96 if (fileId !== plugin.name) { 509 97 const tag = fileId.split('/').pop()!; 510 98 indexFile.add(
+150 -10
packages/openapi-ts/src/plugins/@pinia/colada/query.ts
··· 1 + import type ts from 'typescript'; 2 + 1 3 import type { GeneratedFile } from '../../../generate/file'; 2 4 import type { IR } from '../../../ir/types'; 5 + import { tsc } from '../../../tsc'; 6 + import { 7 + createOperationComment, 8 + isOperationOptionsRequired, 9 + } from '../../shared/utils/operation'; 10 + import { handleMeta } from './meta'; 11 + import type { PluginState } from './state'; 3 12 import type { PiniaColadaPlugin } from './types'; 4 - import { createComposable } from './utils'; 13 + import { useTypeData } from './utils'; 5 14 6 - /** 7 - * Creates a query function for an operation 8 - */ 9 - export const createQueryFunction = ({ 10 - context, 15 + export const createQueryOptions = ({ 11 16 file, 12 17 operation, 13 18 plugin, 19 + queryFn, 20 + state, 14 21 }: { 15 - context: IR.Context; 16 22 file: GeneratedFile; 17 23 operation: IR.OperationObject; 18 24 plugin: PiniaColadaPlugin['Instance']; 19 - }) => { 20 - if (plugin.config.onQuery && plugin.config.onQuery(operation) === false) { 25 + queryFn: string; 26 + state: PluginState; 27 + }): void => { 28 + if ( 29 + !plugin.config.queryOptions.enabled || 30 + !plugin.hooks.operation.isQuery(operation) 31 + ) { 21 32 return; 22 33 } 23 34 24 - createComposable({ context, file, isQuery: true, operation, plugin }); 35 + const isRequiredOptions = isOperationOptionsRequired({ 36 + context: plugin.context, 37 + operation, 38 + }); 39 + 40 + if (!state.hasQueries) { 41 + state.hasQueries = true; 42 + } 43 + 44 + state.hasUsedQueryFn = true; 45 + 46 + const typeData = useTypeData({ file, operation, plugin }); 47 + 48 + const identifierQueryOptions = file.identifier({ 49 + $ref: `#/pinia-colada-query-options/${operation.id}`, 50 + case: plugin.config.queryOptions.case, 51 + create: true, 52 + nameTransformer: plugin.config.queryOptions.name, 53 + namespace: 'value', 54 + }); 55 + 56 + const awaitSdkExpression = tsc.awaitExpression({ 57 + expression: tsc.callExpression({ 58 + functionName: queryFn, 59 + parameters: [ 60 + tsc.objectExpression({ 61 + multiLine: true, 62 + obj: [ 63 + { 64 + spread: 'options', 65 + }, 66 + { 67 + key: 'signal', 68 + value: tsc.identifier({ 69 + text: 'context.signal', 70 + }), 71 + }, 72 + { 73 + key: 'throwOnError', 74 + value: true, 75 + }, 76 + ], 77 + }), 78 + ], 79 + }), 80 + }); 81 + 82 + const statements: Array<ts.Statement> = []; 83 + 84 + if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 85 + statements.push( 86 + tsc.returnVariable({ 87 + expression: awaitSdkExpression, 88 + }), 89 + ); 90 + } else { 91 + statements.push( 92 + tsc.constVariable({ 93 + destructure: true, 94 + expression: awaitSdkExpression, 95 + name: 'data', 96 + }), 97 + tsc.returnVariable({ 98 + expression: 'data', 99 + }), 100 + ); 101 + } 102 + 103 + const queryOptionsObj: Array<{ key: string; value: ts.Expression }> = [ 104 + { 105 + key: 'key', 106 + value: tsc.arrayLiteralExpression({ 107 + elements: [ 108 + tsc.stringLiteral({ text: operation.id || '' }), 109 + tsc.identifier({ text: 'options?.path' }), 110 + ], 111 + }), 112 + }, 113 + { 114 + key: 'query', 115 + value: tsc.arrowFunction({ 116 + async: true, 117 + multiLine: true, 118 + parameters: [ 119 + { 120 + name: 'context', 121 + type: tsc.typeReferenceNode({ 122 + typeName: '{ signal: AbortSignal }', 123 + }), 124 + }, 125 + ], 126 + statements, 127 + }), 128 + }, 129 + ]; 130 + 131 + const meta = handleMeta(plugin, operation, 'queryOptions'); 132 + 133 + if (meta) { 134 + queryOptionsObj.push({ 135 + key: 'meta', 136 + value: meta, 137 + }); 138 + } 139 + 140 + const statement = tsc.constVariable({ 141 + comment: plugin.config.comments 142 + ? createOperationComment({ operation }) 143 + : undefined, 144 + exportConst: true, 145 + expression: tsc.arrowFunction({ 146 + parameters: [ 147 + { 148 + isRequired: isRequiredOptions, 149 + name: 'options', 150 + type: typeData, 151 + }, 152 + ], 153 + statements: [ 154 + tsc.returnStatement({ 155 + expression: tsc.objectExpression({ 156 + obj: queryOptionsObj, 157 + }), 158 + }), 159 + ], 160 + }), 161 + name: identifierQueryOptions.name || '', 162 + }); 163 + 164 + file.add(statement); 25 165 };
+5
packages/openapi-ts/src/plugins/@pinia/colada/state.ts
··· 1 + export interface PluginState { 2 + hasMutations: boolean; 3 + hasQueries: boolean; 4 + hasUsedQueryFn: boolean; 5 + }
-217
packages/openapi-ts/src/plugins/@pinia/colada/types.d-josh.ts
··· 1 - import type { IR } from '../../../ir/types'; 2 - // import type { StringCase, StringName } from '../../../types/case'; 3 - import type { DefinePlugin, Plugin } from '../../types'; 4 - 5 - export type UserConfig = Plugin.Name<'@pinia/colada'> & { 6 - /** 7 - * Default cache time for queries in milliseconds. 8 - * 9 - * @default undefined 10 - */ 11 - defaultCacheTime?: number; 12 - /** 13 - * Default stale time for queries in milliseconds. 14 - * 15 - * @default undefined 16 - */ 17 - defaultStaleTime?: number; 18 - /** 19 - * Enable pagination support on this key when found in the query parameters or body. 20 - * 21 - * @default undefined 22 - */ 23 - enablePaginationOnKey?: string; 24 - /** 25 - * How to handle error responses. 26 - * 'unified' - Unified error type for all errors 27 - * 'specific' - Specific error types per operation 28 - * 29 - * @default 'specific' 30 - */ 31 - errorHandling?: 'unified' | 'specific'; 32 - /** 33 - * Should the exports from the generated files be re-exported in the index barrel file? 34 - * 35 - * @default false 36 - */ 37 - exportFromIndex?: boolean; 38 - /** 39 - * Group operations by tag into separate files. 40 - * 41 - * @default false 42 - */ 43 - groupByTag?: boolean; 44 - /** 45 - * Import path for the plugin. 46 - * 47 - * @default '@pinia/colada' 48 - */ 49 - importPath?: string; 50 - /** 51 - * Include types in the generated files. 52 - * 53 - * @default true 54 - */ 55 - includeTypes?: boolean; 56 - /** 57 - * Custom hook to customize or skip mutation generation. 58 - * Return false to skip generating a mutation for this operation. 59 - * 60 - * @default undefined 61 - */ 62 - onMutation?: (operation: IR.OperationObject) => boolean | undefined; 63 - /** 64 - * Custom hook to customize or skip query generation. 65 - * Return false to skip generating a query for this operation. 66 - * 67 - * @default undefined 68 - */ 69 - onQuery?: (operation: IR.OperationObject) => boolean | undefined; 70 - /** 71 - * Plugin output path. 72 - * 73 - * @default '@pinia/colada' 74 - */ 75 - output: string; 76 - /** 77 - * Whether to prefix generated function names with 'use'. 78 - * 79 - * @default true 80 - */ 81 - prefixUse?: boolean; 82 - /** 83 - * Custom hook that determines if an operation should be a query or not. 84 - * Return true to force query, false to force mutation, undefined to use default logic. 85 - * 86 - * @default undefined 87 - */ 88 - resolveQuery?: (operation: IR.OperationObject) => boolean | undefined; 89 - /** 90 - * Custom hook to resolve query key. 91 - * Default is [operation.tags?.[0] || 'default', operation.id] 92 - * 93 - * @default undefined 94 - */ 95 - resolveQueryKey?: (operation: IR.OperationObject) => Array<string>; 96 - /** 97 - * Whether to suffix generated function names with 'Query' or 'Mutation' to indicate the type 98 - * of Pinia Colada operation that is used under the hood. 99 - * 100 - * @default true 101 - */ 102 - suffixQueryMutation?: boolean; 103 - /** 104 - * Use infinite queries. 105 - * 106 - * @default false 107 - */ 108 - useInfiniteQueries?: boolean; 109 - }; 110 - 111 - export type Config = Plugin.Name<'@pinia/colada'> & { 112 - /** 113 - * Default cache time for queries in milliseconds. 114 - * 115 - * @default undefined 116 - */ 117 - defaultCacheTime: number | undefined; 118 - /** 119 - * Default stale time for queries in milliseconds. 120 - * 121 - * @default undefined 122 - */ 123 - defaultStaleTime: number | undefined; 124 - /** 125 - * Enable pagination support on this key when found in the query parameters or body. 126 - * 127 - * @default undefined 128 - */ 129 - enablePaginationOnKey?: string; 130 - /** 131 - * How to handle error responses. 132 - * 'unified' - Unified error type for all errors 133 - * 'specific' - Specific error types per operation 134 - * 135 - * @default 'specific' 136 - */ 137 - errorHandling?: 'unified' | 'specific'; 138 - /** 139 - * Should the exports from the generated files be re-exported in the index barrel file? 140 - * 141 - * @default false 142 - */ 143 - exportFromIndex: boolean; 144 - /** 145 - * Group operations by tag into separate files. 146 - * 147 - * @default false 148 - */ 149 - groupByTag?: boolean; 150 - /** 151 - * Import path for the plugin. 152 - * 153 - * @default '@pinia/colada' 154 - */ 155 - importPath?: string; 156 - /** 157 - * Include types in the generated files. 158 - * 159 - * @default true 160 - */ 161 - includeTypes?: boolean; 162 - /** 163 - * Custom hook to customize or skip mutation generation. 164 - * Return false to skip generating a mutation for this operation. 165 - * 166 - * @default undefined 167 - */ 168 - onMutation?: (operation: IR.OperationObject) => boolean | undefined; 169 - /** 170 - * Custom hook to customize or skip query generation. 171 - * Return false to skip generating a query for this operation. 172 - * 173 - * @default undefined 174 - */ 175 - onQuery?: (operation: IR.OperationObject) => boolean | undefined; 176 - /** 177 - * Plugin output path. 178 - * 179 - * @default '@pinia/colada' 180 - */ 181 - output: string; 182 - /** 183 - * Whether to prefix generated function names with 'use'. 184 - * 185 - * @default true 186 - */ 187 - prefixUse?: boolean; 188 - /** 189 - * Custom hook that determines if an operation should be a query or not. 190 - * Return true to force query, false to force mutation, undefined to use default logic. 191 - * 192 - * @default undefined 193 - */ 194 - resolveQuery?: (operation: IR.OperationObject) => boolean | undefined; 195 - /** 196 - * Custom hook to resolve query key. 197 - * Default is [operation.tags?.[0] || 'default', operation.id] 198 - * 199 - * @default undefined 200 - */ 201 - resolveQueryKey?: (operation: IR.OperationObject) => Array<string>; 202 - /** 203 - * Whether to suffix generated function names with 'Query' or 'Mutation' to indicate the type 204 - * of Pinia Colada operation that is used under the hood. 205 - * 206 - * @default true 207 - */ 208 - suffixQueryMutation?: boolean; 209 - /** 210 - * Use infinite queries. 211 - * 212 - * @default false 213 - */ 214 - useInfiniteQueries?: boolean; 215 - }; 216 - 217 - export type PiniaColadaPlugin = DefinePlugin<UserConfig, Config>;
+248 -270
packages/openapi-ts/src/plugins/@pinia/colada/types.d.ts
··· 2 2 import type { StringCase, StringName } from '../../../types/case'; 3 3 import type { DefinePlugin, Plugin } from '../../types'; 4 4 5 - export type UserConfig = Plugin.Name<'@pinia/colada'> & { 6 - /** 7 - * Auto-detect whether to generate query or mutation based on HTTP method. 8 - * - GET requests → query 9 - * - POST/PUT/PATCH/DELETE → mutation 10 - * Can be overridden per operation using the `operationTypes` option. 11 - * 12 - * @default true 13 - */ 14 - autoDetectHttpMethod?: boolean; 15 - /** 16 - * The casing convention to use for generated names. 17 - * 18 - * @default 'camelCase' 19 - */ 20 - case?: StringCase; 21 - /** 22 - * Add comments from SDK functions to the generated Pinia Colada code? 23 - * 24 - * @default true 25 - */ 26 - comments?: boolean; 27 - /** 28 - * Should the exports from the generated files be re-exported in the index barrel file? 29 - * 30 - * @default false 31 - */ 32 - exportFromIndex?: boolean; 33 - /** 34 - * Group generated files by OpenAPI tags. When enabled, operations will be organized 35 - * into separate files based on their tags, allowing for better code organization 36 - * and tree-shaking. 37 - * 38 - * @default false 39 - */ 40 - groupByTag?: boolean; 41 - /** 42 - * Configuration for generated mutation options helpers. 43 - * 44 - * Can be: 45 - * - `boolean`: Shorthand for `{ enabled: boolean }` 46 - * - `string` or `function`: Shorthand for `{ name: string | function }` 47 - * - `object`: Full configuration object 48 - * 49 - * @default true 50 - */ 51 - mutationOptions?: 52 - | boolean 53 - | StringName 54 - | { 55 - /** 56 - * The casing convention to use for generated names. 57 - * 58 - * @default 'camelCase' 59 - */ 60 - case?: StringCase; 61 - /** 62 - * Whether to generate mutation options helpers. 63 - * 64 - * @default true 65 - */ 66 - enabled?: boolean; 67 - /** 68 - * Custom function to generate metadata for the operation. 69 - * Can return any valid meta object that will be included in the generated mutation options. 70 - * 71 - * @param operation - The operation object containing all available metadata 72 - * @returns A meta object with any properties you want to include 73 - * 74 - * @example 75 - * ```typescript 76 - * meta: (operation) => ({ 77 - * customField: operation.id, 78 - * isDeprecated: operation.deprecated, 79 - * tags: operation.tags, 80 - * customObject: { 81 - * method: operation.method, 82 - * path: operation.path 83 - * } 84 - * }) 85 - * ``` 86 - */ 87 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 88 - /** 89 - * Custom naming pattern for generated mutation options names. The name variable is 90 - * obtained from the SDK function name. 91 - * 92 - * @default '{{name}}Mutation' 93 - */ 94 - name?: StringName; 95 - }; 96 - /** 97 - * Override the auto-detected operation type for specific operations. 98 - * Useful for edge cases where the HTTP method doesn't match the intended behavior. 99 - * 100 - * @example 101 - * ```typescript 102 - * operationTypes: { 103 - * 'getPetById': 'mutation', // Force GET to be a mutation 104 - * 'deletePet': 'query', // Force DELETE to be a query 105 - * } 106 - * ``` 107 - */ 108 - operationTypes?: Record<string, 'query' | 'mutation' | 'both'>; 109 - /** 110 - * Name of the generated file. 111 - * 112 - * @default '@pinia/colada' 113 - */ 114 - output?: string; 115 - /** 116 - * Configuration for generated query options helpers. 117 - * 118 - * Can be: 119 - * - `boolean`: Shorthand for `{ enabled: boolean }` 120 - * - `string` or `function`: Shorthand for `{ name: string | function }` 121 - * - `object`: Full configuration object 122 - * 123 - * @default true 124 - */ 125 - queryOptions?: 126 - | boolean 127 - | StringName 128 - | { 129 - /** 130 - * The casing convention to use for generated names. 131 - * 132 - * @default 'camelCase' 133 - */ 134 - case?: StringCase; 135 - /** 136 - * Whether to generate query options helpers. 137 - * 138 - * @default true 139 - */ 140 - enabled?: boolean; 141 - /** 142 - * Custom function to generate metadata for the operation. 143 - * Can return any valid meta object that will be included in the generated query options. 144 - * 145 - * @param operation - The operation object containing all available metadata 146 - * @returns A meta object with any properties you want to include 147 - * 148 - * @example 149 - * ```typescript 150 - * meta: (operation) => ({ 151 - * customField: operation.id, 152 - * isDeprecated: operation.deprecated, 153 - * tags: operation.tags, 154 - * customObject: { 155 - * method: operation.method, 156 - * path: operation.path 157 - * } 158 - * }) 159 - * ``` 160 - */ 161 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 162 - /** 163 - * Custom naming pattern for generated query options names. The name variable is 164 - * obtained from the SDK function name. 165 - * 166 - * @default '{{name}}Query' 167 - */ 168 - name?: StringName; 169 - }; 170 - }; 171 - 172 - export type Config = Plugin.Name<'@pinia/colada'> & { 173 - /** 174 - * Auto-detect whether to generate query or mutation based on HTTP method. 175 - * - GET requests → query 176 - * - POST/PUT/PATCH/DELETE → mutation 177 - * Can be overridden per operation using the `operationTypes` option. 178 - * 179 - * @default true 180 - */ 181 - autoDetectHttpMethod: boolean; 182 - /** 183 - * The casing convention to use for generated names. 184 - * 185 - * @default 'camelCase' 186 - */ 187 - case: StringCase; 188 - /** 189 - * Add comments from SDK functions to the generated Pinia Colada code? 190 - * 191 - * @default true 192 - */ 193 - comments: boolean; 194 - /** 195 - * Should the exports from the generated files be re-exported in the index barrel file? 196 - * 197 - * @default false 198 - */ 199 - exportFromIndex: boolean; 200 - /** 201 - * Group generated files by OpenAPI tags. When enabled, operations will be organized 202 - * into separate files based on their tags, allowing for better code organization 203 - * and tree-shaking. 204 - * 205 - * @default false 206 - */ 207 - groupByTag: boolean; 208 - /** 209 - * Resolved configuration for generated mutation options helpers. 210 - */ 211 - mutationOptions: { 5 + export type UserConfig = Plugin.Name<'@pinia/colada'> & 6 + Plugin.Hooks & { 212 7 /** 213 8 * The casing convention to use for generated names. 214 9 * 215 10 * @default 'camelCase' 216 11 */ 217 - case: StringCase; 12 + case?: StringCase; 218 13 /** 219 - * Whether to generate mutation options helpers. 14 + * Add comments from SDK functions to the generated Pinia Colada code? 220 15 * 221 16 * @default true 222 17 */ 223 - enabled: boolean; 18 + comments?: boolean; 224 19 /** 225 - * Custom function to generate metadata for the operation. 226 - * Can return any valid meta object that will be included in the generated mutation options. 20 + * Should the exports from the generated files be re-exported in the index barrel file? 227 21 * 228 - * @param operation - The operation object containing all available metadata 229 - * @returns A meta object with any properties you want to include 22 + * @default false 23 + */ 24 + exportFromIndex?: boolean; 25 + /** 26 + * Group generated files by OpenAPI tags. When enabled, operations will be organized 27 + * into separate files based on their tags, allowing for better code organization 28 + * and tree-shaking. 230 29 * 231 - * @example 232 - * ```typescript 233 - * meta: (operation) => ({ 234 - * customField: operation.id, 235 - * isDeprecated: operation.deprecated, 236 - * tags: operation.tags, 237 - * customObject: { 238 - * method: operation.method, 239 - * path: operation.path 240 - * } 241 - * }) 242 - * ``` 30 + * @default false 243 31 */ 244 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 32 + groupByTag?: boolean; 245 33 /** 246 - * Custom naming pattern for generated mutation options names. The name variable is 247 - * obtained from the SDK function name. 34 + * Configuration for generated mutation options helpers. 248 35 * 249 - * @default '{{name}}Mutation' 36 + * Can be: 37 + * - `boolean`: Shorthand for `{ enabled: boolean }` 38 + * - `string` or `function`: Shorthand for `{ name: string | function }` 39 + * - `object`: Full configuration object 40 + * 41 + * @default true 250 42 */ 251 - name: StringName; 43 + mutationOptions?: 44 + | boolean 45 + | StringName 46 + | { 47 + /** 48 + * The casing convention to use for generated names. 49 + * 50 + * @default 'camelCase' 51 + */ 52 + case?: StringCase; 53 + /** 54 + * Whether to generate mutation options helpers. 55 + * 56 + * @default true 57 + */ 58 + enabled?: boolean; 59 + /** 60 + * Custom function to generate metadata for the operation. 61 + * Can return any valid meta object that will be included in the generated mutation options. 62 + * 63 + * @param operation - The operation object containing all available metadata 64 + * @returns A meta object with any properties you want to include 65 + * 66 + * @example 67 + * ```typescript 68 + * meta: (operation) => ({ 69 + * customField: operation.id, 70 + * isDeprecated: operation.deprecated, 71 + * tags: operation.tags, 72 + * customObject: { 73 + * method: operation.method, 74 + * path: operation.path 75 + * } 76 + * }) 77 + * ``` 78 + * 79 + * @default undefined 80 + */ 81 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 82 + /** 83 + * Custom naming pattern for generated mutation options names. The name variable is 84 + * obtained from the SDK function name. 85 + * 86 + * @default '{{name}}Mutation' 87 + */ 88 + name?: StringName; 89 + }; 90 + /** 91 + * Name of the generated file. 92 + * 93 + * @default '@pinia/colada' 94 + */ 95 + output?: string; 96 + /** 97 + * Configuration for generated query options helpers. 98 + * 99 + * Can be: 100 + * - `boolean`: Shorthand for `{ enabled: boolean }` 101 + * - `string` or `function`: Shorthand for `{ name: string | function }` 102 + * - `object`: Full configuration object 103 + * 104 + * @default true 105 + */ 106 + queryOptions?: 107 + | boolean 108 + | StringName 109 + | { 110 + /** 111 + * The casing convention to use for generated names. 112 + * 113 + * @default 'camelCase' 114 + */ 115 + case?: StringCase; 116 + /** 117 + * Whether to generate query options helpers. 118 + * 119 + * @default true 120 + */ 121 + enabled?: boolean; 122 + /** 123 + * Custom function to generate metadata for the operation. 124 + * Can return any valid meta object that will be included in the generated query options. 125 + * 126 + * @param operation - The operation object containing all available metadata 127 + * @returns A meta object with any properties you want to include 128 + * 129 + * @example 130 + * ```typescript 131 + * meta: (operation) => ({ 132 + * customField: operation.id, 133 + * isDeprecated: operation.deprecated, 134 + * tags: operation.tags, 135 + * customObject: { 136 + * method: operation.method, 137 + * path: operation.path 138 + * } 139 + * }) 140 + * ``` 141 + * 142 + * @default undefined 143 + */ 144 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 145 + /** 146 + * Custom naming pattern for generated query options names. The name variable is 147 + * obtained from the SDK function name. 148 + * 149 + * @default '{{name}}Query' 150 + */ 151 + name?: StringName; 152 + }; 252 153 }; 253 - /** 254 - * Override the auto-detected operation type for specific operations. 255 - * Useful for edge cases where the HTTP method doesn't match the intended behavior. 256 - */ 257 - operationTypes: Record<string, 'query' | 'mutation' | 'both'>; 258 - /** 259 - * Name of the generated file. 260 - * 261 - * @default '@pinia/colada' 262 - */ 263 - output: string; 264 - /** 265 - * Resolved configuration for generated query options helpers. 266 - */ 267 - queryOptions: { 154 + 155 + export type Config = Plugin.Name<'@pinia/colada'> & 156 + Plugin.Hooks & { 268 157 /** 269 158 * The casing convention to use for generated names. 270 159 * ··· 272 161 */ 273 162 case: StringCase; 274 163 /** 275 - * Whether to generate query options helpers. 164 + * Add comments from SDK functions to the generated Pinia Colada code? 276 165 * 277 166 * @default true 278 167 */ 279 - enabled: boolean; 168 + comments: boolean; 280 169 /** 281 - * Custom function to generate metadata for the operation. 282 - * Can return any valid meta object that will be included in the generated query options. 170 + * Should the exports from the generated files be re-exported in the index barrel file? 283 171 * 284 - * @param operation - The operation object containing all available metadata 285 - * @returns A meta object with any properties you want to include 172 + * @default false 173 + */ 174 + exportFromIndex: boolean; 175 + /** 176 + * Group generated files by OpenAPI tags. When enabled, operations will be organized 177 + * into separate files based on their tags, allowing for better code organization 178 + * and tree-shaking. 286 179 * 287 - * @example 288 - * ```typescript 289 - * meta: (operation) => ({ 290 - * customField: operation.id, 291 - * isDeprecated: operation.deprecated, 292 - * tags: operation.tags, 293 - * customObject: { 294 - * method: operation.method, 295 - * path: operation.path 296 - * } 297 - * }) 298 - * ``` 180 + * @default false 181 + */ 182 + groupByTag: boolean; 183 + /** 184 + * Resolved configuration for generated mutation options helpers. 299 185 */ 300 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 186 + mutationOptions: { 187 + /** 188 + * The casing convention to use for generated names. 189 + * 190 + * @default 'camelCase' 191 + */ 192 + case: StringCase; 193 + /** 194 + * Whether to generate mutation options helpers. 195 + * 196 + * @default true 197 + */ 198 + enabled: boolean; 199 + /** 200 + * Custom function to generate metadata for the operation. 201 + * Can return any valid meta object that will be included in the generated mutation options. 202 + * 203 + * @param operation - The operation object containing all available metadata 204 + * @returns A meta object with any properties you want to include 205 + * 206 + * @example 207 + * ```typescript 208 + * meta: (operation) => ({ 209 + * customField: operation.id, 210 + * isDeprecated: operation.deprecated, 211 + * tags: operation.tags, 212 + * customObject: { 213 + * method: operation.method, 214 + * path: operation.path 215 + * } 216 + * }) 217 + * ``` 218 + * 219 + * @default undefined 220 + */ 221 + meta: 222 + | ((operation: IR.OperationObject) => Record<string, unknown>) 223 + | undefined; 224 + /** 225 + * Custom naming pattern for generated mutation options names. The name variable is 226 + * obtained from the SDK function name. 227 + * 228 + * @default '{{name}}Mutation' 229 + */ 230 + name: StringName; 231 + }; 301 232 /** 302 - * Custom naming pattern for generated query options names. The name variable is 303 - * obtained from the SDK function name. 233 + * Name of the generated file. 304 234 * 305 - * @default '{{name}}Query' 235 + * @default '@pinia/colada' 306 236 */ 307 - name: StringName; 237 + output: string; 238 + /** 239 + * Resolved configuration for generated query options helpers. 240 + */ 241 + queryOptions: { 242 + /** 243 + * The casing convention to use for generated names. 244 + * 245 + * @default 'camelCase' 246 + */ 247 + case: StringCase; 248 + /** 249 + * Whether to generate query options helpers. 250 + * 251 + * @default true 252 + */ 253 + enabled: boolean; 254 + /** 255 + * Custom function to generate metadata for the operation. 256 + * Can return any valid meta object that will be included in the generated query options. 257 + * 258 + * @param operation - The operation object containing all available metadata 259 + * @returns A meta object with any properties you want to include 260 + * 261 + * @example 262 + * ```typescript 263 + * meta: (operation) => ({ 264 + * customField: operation.id, 265 + * isDeprecated: operation.deprecated, 266 + * tags: operation.tags, 267 + * customObject: { 268 + * method: operation.method, 269 + * path: operation.path 270 + * } 271 + * }) 272 + * ``` 273 + * 274 + * @default undefined 275 + */ 276 + meta: 277 + | ((operation: IR.OperationObject) => Record<string, unknown>) 278 + | undefined; 279 + /** 280 + * Custom naming pattern for generated query options names. The name variable is 281 + * obtained from the SDK function name. 282 + * 283 + * @default '{{name}}Query' 284 + */ 285 + name: StringName; 286 + }; 308 287 }; 309 - }; 310 288 311 289 export type PiniaColadaPlugin = DefinePlugin<UserConfig, Config>;
+65 -408
packages/openapi-ts/src/plugins/@pinia/colada/utils.ts
··· 1 - import type { TypeNode } from 'typescript'; 2 - 1 + import { clientApi } from '../../../generate/client'; 3 2 import type { GeneratedFile } from '../../../generate/file'; 4 3 import type { IR } from '../../../ir/types'; 5 - import type { Property } from '../../../tsc'; 6 - import { tsc } from '../../../tsc'; 7 - import { escapeComment } from '../../../utils/escape'; 8 - import { stringCase } from '../../../utils/stringCase'; 9 - import { irParametersToIrSchema } from '../../@hey-api/typescript/operation'; 10 - import { schemaToType } from '../../@hey-api/typescript/plugin'; 4 + import { sdkId } from '../../@hey-api/sdk/constants'; 5 + import { operationOptionsType } from '../../@hey-api/sdk/operation'; 6 + import type { PluginState } from './state'; 11 7 import type { PiniaColadaPlugin } from './types'; 12 8 13 - const importIdentifierData = () => ({ 14 - name: '', 15 - }); 16 - const importIdentifierError = () => ({ 17 - name: '', 18 - }); 19 - const importIdentifierResponse = () => ({ 20 - name: '', 21 - }); 22 - 23 - /** 24 - * Determines if an operation should be a query or mutation 25 - */ 26 - export const isQuery = ( 27 - operation: IR.OperationObject, 28 - plugin: PiniaColadaPlugin['Instance'], 29 - ): boolean => { 30 - // 1. Check for hook override 31 - const hookResult = plugin.config.resolveQuery?.(operation); 32 - if (hookResult !== undefined) { 33 - return hookResult; 9 + export const getFileForOperation = ({ 10 + files, 11 + operation, 12 + plugin, 13 + states, 14 + }: { 15 + files: Map<string, GeneratedFile>; 16 + operation: IR.OperationObject; 17 + plugin: PiniaColadaPlugin['Instance']; 18 + states: Map<string, PluginState>; 19 + }) => { 20 + if (!plugin.config.groupByTag) { 21 + // Single file mode 22 + const fileId = plugin.name; 23 + if (!files.has(fileId)) { 24 + const file = plugin.createFile({ 25 + case: plugin.config.case, 26 + id: fileId, 27 + path: plugin.output, 28 + }); 29 + files.set(fileId, file); 30 + states.set(fileId, { 31 + hasMutations: false, 32 + hasQueries: false, 33 + hasUsedQueryFn: false, 34 + }); 35 + // Import Options type from SDK 36 + file.import({ 37 + ...clientApi.Options, 38 + module: file.relativePathToFile({ 39 + context: plugin.context, 40 + id: sdkId, 41 + }), 42 + }); 43 + } 44 + return { file: files.get(fileId)!, state: states.get(fileId)! }; 34 45 } 35 46 36 - // 2. Use method as primary signal 37 - if (['get', 'head', 'options'].includes(operation.method)) { 38 - return true; 39 - } 40 - 41 - // 3. Consider body presence as secondary signal 42 - // If method is not GET/HEAD/OPTIONS but also has no body schema, likely a query 43 - return !operation.body?.schema; 44 - }; 47 + // Group by tag mode 48 + const tag = operation.tags?.[0] || 'default'; 49 + const fileId = `${plugin.name}/${tag}`; 45 50 46 - /** 47 - * Generates the cache configuration object for a query 48 - */ 49 - export const generateCacheConfig = ( 50 - operation: IR.OperationObject, 51 - plugin: PiniaColadaPlugin['Instance'], 52 - ) => { 53 - const obj: Array<{ 54 - key: string; 55 - value: any; 56 - }> = []; 57 - 58 - // Use default stale time if specified in config 59 - if (plugin.config.defaultStaleTime !== undefined) { 60 - obj.push({ 61 - key: 'staleTime', 62 - value: plugin.config.defaultStaleTime, 51 + if (!files.has(fileId)) { 52 + const file = plugin.createFile({ 53 + case: plugin.config.case, 54 + id: fileId, 55 + path: `${plugin.output}/${tag}`, 63 56 }); 64 - } 65 - 66 - // Use default cache time if specified in config 67 - if (plugin.config.defaultCacheTime !== undefined) { 68 - obj.push({ 69 - key: 'gcTime', 70 - value: plugin.config.defaultCacheTime, 57 + files.set(fileId, file); 58 + states.set(fileId, { 59 + hasMutations: false, 60 + hasQueries: false, 61 + hasUsedQueryFn: false, 71 62 }); 72 - } 73 - 74 - // Add pagination config if enabled and operation has pagination parameters 75 - if ( 76 - plugin.config.enablePaginationOnKey && 77 - hasPagination(operation, plugin.config.enablePaginationOnKey) 78 - ) { 79 - obj.push({ 80 - key: 'infinite', 81 - value: true, 63 + // Import Options type from SDK 64 + file.import({ 65 + ...clientApi.Options, 66 + module: file.relativePathToFile({ context: plugin.context, id: sdkId }), 82 67 }); 83 68 } 84 - 85 - return obj; 69 + return { 70 + file: files.get(fileId)!, 71 + state: states.get(fileId)!, 72 + }; 86 73 }; 87 74 88 - /** 89 - * Checks if operation has pagination parameters 90 - */ 91 - export const hasPagination = ( 92 - operation: IR.OperationObject, 93 - paginationParam: string, 94 - ): boolean => 95 - // Check if operation has pagination parameter 96 - !!operation.parameters?.query?.[paginationParam] || 97 - !!operation.body?.pagination; 98 - 99 - /** 100 - * Generates the function name for an operation 101 - */ 102 - export const generateFunctionName = ( 103 - operation: IR.OperationObject, 104 - isQueryType: boolean, 105 - prefixUse: boolean = true, 106 - suffixQueryMutation: boolean = true, 107 - ): string => { 108 - const operationPascalCase = stringCase({ 109 - case: 'PascalCase', 110 - value: operation.id, 111 - }); 112 - const prefix = prefixUse ? 'use' : ''; 113 - const suffix = suffixQueryMutation 114 - ? isQueryType 115 - ? 'Query' 116 - : 'Mutation' 117 - : ''; 118 - return `${prefix}${operationPascalCase}${suffix}`; 119 - }; 120 - 121 - const parametersPluralizedNames = [ 122 - 'query', 123 - 'path', 124 - 'headers', 125 - 'body', 126 - 'cookies', 127 - ] as const; 128 - type ParamNames = (typeof parametersPluralizedNames)[number]; 129 - // Define a conditional type to transform the names 130 - type NonPluralizedName<T extends ParamNames> = T extends 'headers' 131 - ? 'header' 132 - : T extends 'cookies' 133 - ? 'cookie' 134 - : T; 135 - function getNonPluralizedName<T extends ParamNames>( 136 - name: T, 137 - ): NonPluralizedName<T> { 138 - return ( 139 - ['headers', 'cookies'].includes(name) ? name.slice(0, -1) : name 140 - ) as NonPluralizedName<T>; 141 - } 142 - type DataKeyNames = Exclude<ParamNames, 'cookies'>; 143 - function getDataSubType(identifier: string, dataKey: DataKeyNames) { 144 - return tsc.indexedAccessTypeNode({ 145 - indexType: tsc.literalTypeNode({ 146 - literal: tsc.stringLiteral({ 147 - text: dataKey, 148 - }), 149 - }), 150 - objectType: tsc.typeReferenceNode({ 151 - typeName: identifier, 152 - }), 153 - }); 154 - } 155 - 156 - function createParameterConst( 157 - name: ParamNames, 158 - operation?: IR.OperationObject, 159 - ) { 160 - const nonPluralizedName = getNonPluralizedName(name); 161 - if (nonPluralizedName === 'body' && !operation?.body?.schema) return []; 162 - if ( 163 - nonPluralizedName !== 'body' && 164 - !operation?.parameters?.[nonPluralizedName] 165 - ) 166 - return []; 167 - return [ 168 - tsc.constVariable({ 169 - expression: tsc.callExpression({ 170 - functionName: 'toRef', 171 - parameters: [getParameterQualifiedName(name)], 172 - }), 173 - name: `${name}Ref`, 174 - }), 175 - ]; 176 - } 177 - function getParameterQualifiedName(name: ParamNames) { 178 - return tsc.propertyAccessExpression({ 179 - expression: 'params', 180 - isOptional: true, 181 - name, 182 - }); 183 - } 184 - /** 185 - * Creates a composable function for an operation 186 - */ 187 - export const createComposable = ({ 75 + export const useTypeData = ({ 188 76 file, 189 - isQuery, 190 77 operation, 191 78 plugin, 192 79 }: { 193 - context: IR.Context; 194 80 file: GeneratedFile; 195 - isQuery: boolean; 196 81 operation: IR.OperationObject; 197 82 plugin: PiniaColadaPlugin['Instance']; 198 83 }) => { 199 - // Import necessary functions and types 200 - file.import({ 201 - module: '@pinia/colada', 202 - name: isQuery ? 'useQuery' : 'useMutation', 203 - }); 204 - file.import({ 205 - asType: true, 206 - module: '@pinia/colada', 207 - name: `Use${isQuery ? 'Query' : 'Mutation'}Options`, 208 - }); 209 - file.import({ 210 - module: 'vue', 211 - name: 'toRef', 212 - }); 213 - 214 - // Get query key from hooks or generate default 215 - const queryKey = plugin.config.resolveQueryKey?.(operation) ?? [ 216 - operation.tags?.[0] || 'default', 217 - operation.id, 218 - ]; 219 - 220 - // Get identifiers for data, response and error types 221 - const identifierData = importIdentifierData(); 222 - const identifierResponse = importIdentifierResponse(); 223 - const identifierError = importIdentifierError(); 224 - 225 - /** 226 - * Creates a parameter for a composable function 227 - */ 228 - function createParameter( 229 - name: ParamNames, 230 - operation?: IR.OperationObject, 231 - ): Array<Property> { 232 - const nonPluralizedName = getNonPluralizedName(name); 233 - if (nonPluralizedName === 'body' && !operation?.body?.schema) return []; 234 - if ( 235 - nonPluralizedName !== 'body' && 236 - !operation?.parameters?.[nonPluralizedName] 237 - ) 238 - return []; 239 - let type: TypeNode = tsc.keywordTypeNode({ keyword: 'unknown' }); 240 - if (nonPluralizedName === 'cookie') { 241 - type = 242 - schemaToType({ 243 - onRef: undefined, 244 - plugin: plugin as any, 245 - schema: irParametersToIrSchema({ 246 - parameters: operation?.parameters?.cookie || {}, 247 - }), 248 - state: { 249 - usedTypeIDs: new Set(), 250 - }, 251 - }) ?? type; 252 - } else if (name !== 'cookies') { 253 - type = identifierData.name 254 - ? getDataSubType(identifierData.name, name) 255 - : type; 256 - } 257 - return [ 258 - { 259 - name, 260 - type, 261 - }, 262 - ]; 263 - } 264 - const parameters = parametersPluralizedNames.flatMap((name) => 265 - createParameter(name, operation), 266 - ); 267 - 268 - // Create the composable function 269 - const node = tsc.constVariable({ 270 - comment: [ 271 - operation.deprecated && '@deprecated', 272 - operation.summary && escapeComment(operation.summary), 273 - operation.description && escapeComment(operation.description), 274 - ].filter(Boolean), 275 - exportConst: true, 276 - expression: tsc.arrowFunction({ 277 - async: true, 278 - parameters: [ 279 - { 280 - isRequired: parameters.length > 0, 281 - name: 'params', 282 - type: tsc.typeInterfaceNode({ 283 - properties: parameters, 284 - useLegacyResolution: true, 285 - }), 286 - }, 287 - // Additional Pinia Colada options 288 - { 289 - isRequired: false, 290 - name: 'options', 291 - type: tsc.typeReferenceNode({ 292 - typeName: isQuery 293 - ? `UseQueryOptions<${identifierResponse.name || 'unknown'}, ${identifierError.name || 'unknown'}, ${identifierData.name || 'unknown'}>` 294 - : `UseMutationOptions<${identifierResponse.name || 'unknown'}, ${identifierData.name || 'unknown'}, ${identifierError.name || 'unknown'}>`, 295 - }), 296 - }, 297 - ], 298 - statements: [ 299 - // Create reactive refs for parameters 300 - ...parametersPluralizedNames.flatMap((name) => 301 - createParameterConst(name, operation), 302 - ), 303 - 304 - // Create query/mutation result 305 - tsc.constVariable({ 306 - expression: tsc.callExpression({ 307 - functionName: isQuery ? 'useQuery' : 'useMutation', 308 - parameters: [ 309 - tsc.objectExpression({ 310 - obj: [ 311 - // Query/mutation function 312 - { 313 - key: isQuery ? 'query' : 'mutation', 314 - value: tsc.callExpression({ 315 - functionName: '_heyApiClient', 316 - parameters: [ 317 - tsc.objectExpression({ 318 - obj: [ 319 - { 320 - key: 'method', 321 - value: operation.method, 322 - }, 323 - { 324 - key: 'url', 325 - value: operation.path, 326 - }, 327 - // Add data if it's a valid body parameter (mutations only) 328 - ...parametersPluralizedNames.flatMap((name) => { 329 - const nonPluralizedName = 330 - getNonPluralizedName(name); 331 - if ( 332 - nonPluralizedName === 'body' && 333 - !operation?.body?.schema 334 - ) 335 - return []; 336 - if ( 337 - nonPluralizedName !== 'body' && 338 - !operation?.parameters?.[nonPluralizedName] 339 - ) 340 - return []; 341 - return [ 342 - { 343 - key: 344 - nonPluralizedName === 'body' 345 - ? 'data' 346 - : name, 347 - value: tsc.identifier({ text: `${name}Ref` }), 348 - }, 349 - ]; 350 - }), 351 - ].filter(Boolean), 352 - }), 353 - ], 354 - }), 355 - }, 356 - // Query key (optional for mutations) 357 - { 358 - key: 'key', 359 - value: tsc.arrayLiteralExpression({ 360 - elements: [ 361 - ...queryKey.map((k: string) => tsc.ots.string(k)), 362 - // Add path params to query key if they exist 363 - ...parametersPluralizedNames.flatMap((name) => { 364 - const nonPluralizedName = getNonPluralizedName(name); 365 - if ( 366 - nonPluralizedName === 'body' && 367 - !operation?.body?.schema 368 - ) 369 - return []; 370 - if ( 371 - nonPluralizedName !== 'body' && 372 - !operation?.parameters?.[nonPluralizedName] 373 - ) 374 - return []; 375 - return [tsc.identifier({ text: `${name}Ref` })]; 376 - }), 377 - ], 378 - }), 379 - }, 380 - // Spread additional options 381 - { 382 - spread: 'options', 383 - }, 384 - ], 385 - }), 386 - ], 387 - }), 388 - name: isQuery ? 'queryResult' : 'mutationResult', 389 - }), 390 - 391 - // Return useQuery/useMutation call with reactive parameters 392 - tsc.returnStatement({ 393 - expression: tsc.objectExpression({ 394 - obj: [ 395 - // Spread the query/mutation result 396 - { 397 - spread: isQuery ? 'queryResult' : 'mutationResult', 398 - }, 399 - // Return reactive parameters 400 - ...parametersPluralizedNames.flatMap((name) => { 401 - const nonPluralizedName = getNonPluralizedName(name); 402 - if (nonPluralizedName === 'body' && !operation?.body?.schema) 403 - return []; 404 - if ( 405 - nonPluralizedName !== 'body' && 406 - !operation?.parameters?.[nonPluralizedName] 407 - ) 408 - return []; 409 - return [ 410 - { 411 - key: name, 412 - value: tsc.identifier({ text: `${name}Ref` }), 413 - }, 414 - ]; 415 - }), 416 - ], 417 - }), 418 - }), 419 - ], 420 - }), 421 - name: generateFunctionName( 422 - operation, 423 - isQuery, 424 - plugin.config.prefixUse, 425 - plugin.config.suffixQueryMutation, 426 - ), 427 - }); 428 - 429 - file.add(node); 84 + const pluginSdk = plugin.getPlugin('@hey-api/sdk')!; 85 + const typeData = operationOptionsType({ file, operation, plugin: pluginSdk }); 86 + return typeData; 430 87 };
-3
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts
··· 34 34 defaultValue: { 35 35 case: plugin.config.case ?? 'camelCase', 36 36 enabled: true, 37 - meta: false, 38 37 name: '{{name}}InfiniteOptions', 39 38 }, 40 39 mappers: { ··· 49 48 defaultValue: { 50 49 case: plugin.config.case ?? 'camelCase', 51 50 enabled: true, 52 - meta: false, 53 51 name: '{{name}}Mutation', 54 52 }, 55 53 mappers: { ··· 79 77 defaultValue: { 80 78 case: plugin.config.case ?? 'camelCase', 81 79 enabled: true, 82 - meta: false, 83 80 name: '{{name}}Options', 84 81 }, 85 82 mappers: {
+466 -464
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.d.ts
··· 2 2 import type { StringCase, StringName } from '../../../types/case'; 3 3 import type { DefinePlugin, Plugin } from '../../types'; 4 4 5 - export type UserConfig = Plugin.Name<'@tanstack/angular-query-experimental'> & { 6 - /** 7 - * The casing convention to use for generated names. 8 - * 9 - * @default 'camelCase' 10 - */ 11 - case?: StringCase; 12 - /** 13 - * Add comments from SDK functions to the generated TanStack Query code? 14 - * 15 - * @default true 16 - */ 17 - comments?: boolean; 18 - /** 19 - * Should the exports from the generated files be re-exported in the index barrel file? 20 - * 21 - * @default false 22 - */ 23 - exportFromIndex?: boolean; 24 - /** 25 - * Configuration for generated infinite query key helpers. 26 - * 27 - * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 28 - * 29 - * Can be: 30 - * - `boolean`: Shorthand for `{ enabled: boolean }` 31 - * - `string` or `function`: Shorthand for `{ name: string | function }` 32 - * - `object`: Full configuration object 33 - * 34 - * @default true 35 - */ 36 - infiniteQueryKeys?: 37 - | boolean 38 - | StringName 39 - | { 40 - /** 41 - * The casing convention to use for generated names. 42 - * 43 - * @default 'camelCase' 44 - */ 45 - case?: StringCase; 46 - /** 47 - * Whether to generate infinite query key helpers. 48 - * 49 - * @default true 50 - */ 51 - enabled?: boolean; 52 - /** 53 - * Custom naming pattern for generated infinite query key names. The name variable is 54 - * obtained from the SDK function name. 55 - * 56 - * @default '{{name}}InfiniteQueryKey' 57 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 58 - */ 59 - name?: StringName; 60 - /** 61 - * Whether to include operation tags in infinite query keys. 62 - * This will make query keys larger but provides better cache invalidation capabilities. 63 - * 64 - * @default false 65 - */ 66 - tags?: boolean; 67 - }; 68 - /** 69 - * Configuration for generated infinite query options helpers. 70 - * 71 - * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 72 - * 73 - * Can be: 74 - * - `boolean`: Shorthand for `{ enabled: boolean }` 75 - * - `string` or `function`: Shorthand for `{ name: string | function }` 76 - * - `object`: Full configuration object 77 - * 78 - * @default true 79 - */ 80 - infiniteQueryOptions?: 81 - | boolean 82 - | StringName 83 - | { 84 - /** 85 - * The casing convention to use for generated names. 86 - * 87 - * @default 'camelCase' 88 - */ 89 - case?: StringCase; 90 - /** 91 - * Whether to generate infinite query options helpers. 92 - * 93 - * @default true 94 - */ 95 - enabled?: boolean; 96 - /** 97 - * Custom function to generate metadata for the operation. 98 - * Can return any valid meta object that will be included in the generated infinite query options. 99 - * @param operation - The operation object containing all available metadata 100 - * @returns A meta object with any properties you want to include 101 - * 102 - * @example 103 - * ```typescript 104 - * meta: (operation) => ({ 105 - * customField: operation.id, 106 - * isDeprecated: operation.deprecated, 107 - * tags: operation.tags, 108 - * customObject: { 109 - * method: operation.method, 110 - * path: operation.path 111 - * } 112 - * }) 113 - * ``` 114 - * 115 - * @default false 116 - */ 117 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 118 - /** 119 - * Custom naming pattern for generated infinite query options names. The name variable is 120 - * obtained from the SDK function name. 121 - * 122 - * @default '{{name}}InfiniteOptions' 123 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 124 - */ 125 - name?: StringName; 126 - }; 127 - /** 128 - * Configuration for generated mutation options helpers. 129 - * 130 - * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation} 131 - * 132 - * Can be: 133 - * - `boolean`: Shorthand for `{ enabled: boolean }` 134 - * - `string` or `function`: Shorthand for `{ name: string | function }` 135 - * - `object`: Full configuration object 136 - * 137 - * @default true 138 - */ 139 - mutationOptions?: 140 - | boolean 141 - | StringName 142 - | { 143 - /** 144 - * The casing convention to use for generated names. 145 - * 146 - * @default 'camelCase' 147 - */ 148 - case?: StringCase; 149 - /** 150 - * Whether to generate mutation options helpers. 151 - * 152 - * @default true 153 - */ 154 - enabled?: boolean; 155 - /** 156 - * Custom function to generate metadata for the operation. 157 - * Can return any valid meta object that will be included in the generated mutation options. 158 - * @param operation - The operation object containing all available metadata 159 - * @returns A meta object with any properties you want to include 160 - * 161 - * @example 162 - * ```typescript 163 - * meta: (operation) => ({ 164 - * customField: operation.id, 165 - * isDeprecated: operation.deprecated, 166 - * tags: operation.tags, 167 - * customObject: { 168 - * method: operation.method, 169 - * path: operation.path 170 - * } 171 - * }) 172 - * ``` 173 - * 174 - * @default false 175 - */ 176 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 177 - /** 178 - * Custom naming pattern for generated mutation options names. The name variable is 179 - * obtained from the SDK function name. 180 - * 181 - * @default '{{name}}Mutation' 182 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 183 - */ 184 - name?: StringName; 185 - }; 186 - /** 187 - * Name of the generated file. 188 - * 189 - * @default '@tanstack/angular-query-experimental' 190 - */ 191 - output?: string; 192 - /** 193 - * Configuration for generated query keys. 194 - * 195 - * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey} 196 - * 197 - * Can be: 198 - * - `boolean`: Shorthand for `{ enabled: boolean }` 199 - * - `string` or `function`: Shorthand for `{ name: string | function }` 200 - * - `object`: Full configuration object 201 - * 202 - * @default true 203 - */ 204 - queryKeys?: 205 - | boolean 206 - | StringName 207 - | { 208 - /** 209 - * The casing convention to use for generated names. 210 - * 211 - * @default 'camelCase' 212 - */ 213 - case?: StringCase; 214 - /** 215 - * Whether to generate query keys. 216 - * 217 - * @default true 218 - */ 219 - enabled?: boolean; 220 - /** 221 - * Custom naming pattern for generated query key names. The name variable is 222 - * obtained from the SDK function name. 223 - * 224 - * @default '{{name}}QueryKey' 225 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 226 - */ 227 - name?: StringName; 228 - /** 229 - * Whether to include operation tags in query keys. 230 - * This will make query keys larger but provides better cache invalidation capabilities. 231 - * 232 - * @default false 233 - */ 234 - tags?: boolean; 235 - }; 236 - /** 237 - * Configuration for generated query options helpers. 238 - * 239 - * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions} 240 - * 241 - * Can be: 242 - * - `boolean`: Shorthand for `{ enabled: boolean }` 243 - * - `string` or `function`: Shorthand for `{ name: string | function }` 244 - * - `object`: Full configuration object 245 - * 246 - * @default true 247 - */ 248 - queryOptions?: 249 - | boolean 250 - | StringName 251 - | { 252 - /** 253 - * The casing convention to use for generated names. 254 - * 255 - * @default 'camelCase' 256 - */ 257 - case?: StringCase; 258 - /** 259 - * Whether to generate query options helpers. 260 - * 261 - * @default true 262 - */ 263 - enabled?: boolean; 264 - /** 265 - * Custom function to generate metadata for the operation. 266 - * Can return any valid meta object that will be included in the generated query options. 267 - * @param operation - The operation object containing all available metadata 268 - * @returns A meta object with any properties you want to include 269 - * 270 - * @example 271 - * ```typescript 272 - * meta: (operation) => ({ 273 - * customField: operation.id, 274 - * isDeprecated: operation.deprecated, 275 - * tags: operation.tags, 276 - * customObject: { 277 - * method: operation.method, 278 - * path: operation.path 279 - * } 280 - * }) 281 - * ``` 282 - * 283 - * @default false 284 - */ 285 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 286 - /** 287 - * Custom naming pattern for generated query options names. The name variable is 288 - * obtained from the SDK function name. 289 - * 290 - * @default '{{name}}Options' 291 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 292 - */ 293 - name?: StringName; 294 - }; 295 - }; 296 - 297 - export type Config = Plugin.Name<'@tanstack/angular-query-experimental'> & { 298 - /** 299 - * The casing convention to use for generated names. 300 - * 301 - * @default 'camelCase' 302 - */ 303 - case: StringCase; 304 - /** 305 - * Add comments from SDK functions to the generated TanStack Query code? 306 - * 307 - * @default true 308 - */ 309 - comments: boolean; 310 - /** 311 - * Should the exports from the generated files be re-exported in the index barrel file? 312 - * 313 - * @default false 314 - */ 315 - exportFromIndex: boolean; 316 - /** 317 - * Resolved configuration for generated infinite query key helpers. 318 - * 319 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 320 - */ 321 - infiniteQueryKeys: { 5 + export type UserConfig = Plugin.Name<'@tanstack/angular-query-experimental'> & 6 + Plugin.Hooks & { 322 7 /** 323 8 * The casing convention to use for generated names. 324 9 * 325 10 * @default 'camelCase' 326 11 */ 327 - case: StringCase; 12 + case?: StringCase; 328 13 /** 329 - * Whether to generate infinite query key helpers. 14 + * Add comments from SDK functions to the generated TanStack Query code? 330 15 * 331 16 * @default true 332 17 */ 333 - enabled: boolean; 18 + comments?: boolean; 334 19 /** 335 - * Custom naming pattern for generated infinite query key names. The name variable is 336 - * obtained from the SDK function name. 337 - * 338 - * @default '{{name}}InfiniteQueryKey' 339 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 340 - */ 341 - name: StringName; 342 - /** 343 - * Whether to include operation tags in infinite query keys. 344 - * This will make query keys larger but provides better cache invalidation capabilities. 20 + * Should the exports from the generated files be re-exported in the index barrel file? 345 21 * 346 22 * @default false 347 23 */ 348 - tags: boolean; 349 - }; 350 - /** 351 - * Resolved configuration for generated infinite query options helpers. 352 - * 353 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 354 - */ 355 - infiniteQueryOptions: { 24 + exportFromIndex?: boolean; 356 25 /** 357 - * The casing convention to use for generated names. 26 + * Configuration for generated infinite query key helpers. 358 27 * 359 - * @default 'camelCase' 360 - */ 361 - case: StringCase; 362 - /** 363 - * Whether to generate infinite query options helpers. 28 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 29 + * 30 + * Can be: 31 + * - `boolean`: Shorthand for `{ enabled: boolean }` 32 + * - `string` or `function`: Shorthand for `{ name: string | function }` 33 + * - `object`: Full configuration object 364 34 * 365 35 * @default true 366 36 */ 367 - enabled: boolean; 37 + infiniteQueryKeys?: 38 + | boolean 39 + | StringName 40 + | { 41 + /** 42 + * The casing convention to use for generated names. 43 + * 44 + * @default 'camelCase' 45 + */ 46 + case?: StringCase; 47 + /** 48 + * Whether to generate infinite query key helpers. 49 + * 50 + * @default true 51 + */ 52 + enabled?: boolean; 53 + /** 54 + * Custom naming pattern for generated infinite query key names. The name variable is 55 + * obtained from the SDK function name. 56 + * 57 + * @default '{{name}}InfiniteQueryKey' 58 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 59 + */ 60 + name?: StringName; 61 + /** 62 + * Whether to include operation tags in infinite query keys. 63 + * This will make query keys larger but provides better cache invalidation capabilities. 64 + * 65 + * @default false 66 + */ 67 + tags?: boolean; 68 + }; 368 69 /** 369 - * Custom function to generate metadata for the operation. 370 - * Can return any valid meta object that will be included in the generated infinite query options. 371 - * @param operation - The operation object containing all available metadata 372 - * @returns A meta object with any properties you want to include 70 + * Configuration for generated infinite query options helpers. 373 71 * 374 - * @example 375 - * ```typescript 376 - * meta: (operation) => ({ 377 - * customField: operation.id, 378 - * isDeprecated: operation.deprecated, 379 - * tags: operation.tags, 380 - * customObject: { 381 - * method: operation.method, 382 - * path: operation.path 383 - * } 384 - * }) 385 - * ``` 72 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 386 73 * 387 - * @default false 74 + * Can be: 75 + * - `boolean`: Shorthand for `{ enabled: boolean }` 76 + * - `string` or `function`: Shorthand for `{ name: string | function }` 77 + * - `object`: Full configuration object 78 + * 79 + * @default true 388 80 */ 389 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 81 + infiniteQueryOptions?: 82 + | boolean 83 + | StringName 84 + | { 85 + /** 86 + * The casing convention to use for generated names. 87 + * 88 + * @default 'camelCase' 89 + */ 90 + case?: StringCase; 91 + /** 92 + * Whether to generate infinite query options helpers. 93 + * 94 + * @default true 95 + */ 96 + enabled?: boolean; 97 + /** 98 + * Custom function to generate metadata for the operation. 99 + * Can return any valid meta object that will be included in the generated infinite query options. 100 + * @param operation - The operation object containing all available metadata 101 + * @returns A meta object with any properties you want to include 102 + * 103 + * @example 104 + * ```typescript 105 + * meta: (operation) => ({ 106 + * customField: operation.id, 107 + * isDeprecated: operation.deprecated, 108 + * tags: operation.tags, 109 + * customObject: { 110 + * method: operation.method, 111 + * path: operation.path 112 + * } 113 + * }) 114 + * ``` 115 + * 116 + * @default undefined 117 + */ 118 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 119 + /** 120 + * Custom naming pattern for generated infinite query options names. The name variable is 121 + * obtained from the SDK function name. 122 + * 123 + * @default '{{name}}InfiniteOptions' 124 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 125 + */ 126 + name?: StringName; 127 + }; 390 128 /** 391 - * Custom naming pattern for generated infinite query options names. The name variable is 392 - * obtained from the SDK function name. 129 + * Configuration for generated mutation options helpers. 130 + * 131 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation} 132 + * 133 + * Can be: 134 + * - `boolean`: Shorthand for `{ enabled: boolean }` 135 + * - `string` or `function`: Shorthand for `{ name: string | function }` 136 + * - `object`: Full configuration object 393 137 * 394 - * @default '{{name}}InfiniteOptions' 395 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 138 + * @default true 396 139 */ 397 - name: StringName; 398 - }; 399 - /** 400 - * Resolved configuration for generated mutation options helpers. 401 - * 402 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 403 - */ 404 - mutationOptions: { 140 + mutationOptions?: 141 + | boolean 142 + | StringName 143 + | { 144 + /** 145 + * The casing convention to use for generated names. 146 + * 147 + * @default 'camelCase' 148 + */ 149 + case?: StringCase; 150 + /** 151 + * Whether to generate mutation options helpers. 152 + * 153 + * @default true 154 + */ 155 + enabled?: boolean; 156 + /** 157 + * Custom function to generate metadata for the operation. 158 + * Can return any valid meta object that will be included in the generated mutation options. 159 + * @param operation - The operation object containing all available metadata 160 + * @returns A meta object with any properties you want to include 161 + * 162 + * @example 163 + * ```typescript 164 + * meta: (operation) => ({ 165 + * customField: operation.id, 166 + * isDeprecated: operation.deprecated, 167 + * tags: operation.tags, 168 + * customObject: { 169 + * method: operation.method, 170 + * path: operation.path 171 + * } 172 + * }) 173 + * ``` 174 + * 175 + * @default undefined 176 + */ 177 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 178 + /** 179 + * Custom naming pattern for generated mutation options names. The name variable is 180 + * obtained from the SDK function name. 181 + * 182 + * @default '{{name}}Mutation' 183 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 184 + */ 185 + name?: StringName; 186 + }; 405 187 /** 406 - * The casing convention to use for generated names. 188 + * Name of the generated file. 407 189 * 408 - * @default 'camelCase' 190 + * @default '@tanstack/angular-query-experimental' 409 191 */ 410 - case: StringCase; 192 + output?: string; 411 193 /** 412 - * Whether to generate mutation options helpers. 194 + * Configuration for generated query keys. 195 + * 196 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey} 197 + * 198 + * Can be: 199 + * - `boolean`: Shorthand for `{ enabled: boolean }` 200 + * - `string` or `function`: Shorthand for `{ name: string | function }` 201 + * - `object`: Full configuration object 413 202 * 414 203 * @default true 415 204 */ 416 - enabled: boolean; 205 + queryKeys?: 206 + | boolean 207 + | StringName 208 + | { 209 + /** 210 + * The casing convention to use for generated names. 211 + * 212 + * @default 'camelCase' 213 + */ 214 + case?: StringCase; 215 + /** 216 + * Whether to generate query keys. 217 + * 218 + * @default true 219 + */ 220 + enabled?: boolean; 221 + /** 222 + * Custom naming pattern for generated query key names. The name variable is 223 + * obtained from the SDK function name. 224 + * 225 + * @default '{{name}}QueryKey' 226 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 227 + */ 228 + name?: StringName; 229 + /** 230 + * Whether to include operation tags in query keys. 231 + * This will make query keys larger but provides better cache invalidation capabilities. 232 + * 233 + * @default false 234 + */ 235 + tags?: boolean; 236 + }; 417 237 /** 418 - * Custom function to generate metadata for the operation. 419 - * Can return any valid meta object that will be included in the generated mutation options. 420 - * @param operation - The operation object containing all available metadata 421 - * @returns A meta object with any properties you want to include 238 + * Configuration for generated query options helpers. 422 239 * 423 - * @example 424 - * ```typescript 425 - * meta: (operation) => ({ 426 - * customField: operation.id, 427 - * isDeprecated: operation.deprecated, 428 - * tags: operation.tags, 429 - * customObject: { 430 - * method: operation.method, 431 - * path: operation.path 432 - * } 433 - * }) 434 - * ``` 240 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions} 435 241 * 436 - * @default false 437 - */ 438 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 439 - /** 440 - * Custom naming pattern for generated mutation options names. The name variable is 441 - * obtained from the SDK function name. 242 + * Can be: 243 + * - `boolean`: Shorthand for `{ enabled: boolean }` 244 + * - `string` or `function`: Shorthand for `{ name: string | function }` 245 + * - `object`: Full configuration object 442 246 * 443 - * @default '{{name}}Mutation' 444 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 247 + * @default true 445 248 */ 446 - name: StringName; 249 + queryOptions?: 250 + | boolean 251 + | StringName 252 + | { 253 + /** 254 + * The casing convention to use for generated names. 255 + * 256 + * @default 'camelCase' 257 + */ 258 + case?: StringCase; 259 + /** 260 + * Whether to generate query options helpers. 261 + * 262 + * @default true 263 + */ 264 + enabled?: boolean; 265 + /** 266 + * Custom function to generate metadata for the operation. 267 + * Can return any valid meta object that will be included in the generated query options. 268 + * @param operation - The operation object containing all available metadata 269 + * @returns A meta object with any properties you want to include 270 + * 271 + * @example 272 + * ```typescript 273 + * meta: (operation) => ({ 274 + * customField: operation.id, 275 + * isDeprecated: operation.deprecated, 276 + * tags: operation.tags, 277 + * customObject: { 278 + * method: operation.method, 279 + * path: operation.path 280 + * } 281 + * }) 282 + * ``` 283 + * 284 + * @default undefined 285 + */ 286 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 287 + /** 288 + * Custom naming pattern for generated query options names. The name variable is 289 + * obtained from the SDK function name. 290 + * 291 + * @default '{{name}}Options' 292 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 293 + */ 294 + name?: StringName; 295 + }; 447 296 }; 448 - /** 449 - * Name of the generated file. 450 - * 451 - * @default '@tanstack/angular-query-experimental' 452 - */ 453 - output: string; 454 - /** 455 - * Resolved configuration for generated query keys. 456 - * 457 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 458 - */ 459 - queryKeys: { 297 + 298 + export type Config = Plugin.Name<'@tanstack/angular-query-experimental'> & 299 + Plugin.Hooks & { 460 300 /** 461 301 * The casing convention to use for generated names. 462 302 * ··· 464 304 */ 465 305 case: StringCase; 466 306 /** 467 - * Whether to generate query keys. 307 + * Add comments from SDK functions to the generated TanStack Query code? 468 308 * 469 309 * @default true 470 310 */ 471 - enabled: boolean; 311 + comments: boolean; 472 312 /** 473 - * Custom naming pattern for generated query key names. The name variable is 474 - * obtained from the SDK function name. 313 + * Should the exports from the generated files be re-exported in the index barrel file? 475 314 * 476 - * @default '{{name}}QueryKey' 477 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 315 + * @default false 478 316 */ 479 - name: StringName; 317 + exportFromIndex: boolean; 480 318 /** 481 - * Whether to include operation tags in query keys. 482 - * This will make query keys larger but provides better cache invalidation capabilities. 319 + * Resolved configuration for generated infinite query key helpers. 483 320 * 484 - * @default false 321 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 485 322 */ 486 - tags: boolean; 487 - }; 488 - /** 489 - * Resolved configuration for generated query options helpers. 490 - * 491 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 492 - */ 493 - queryOptions: { 323 + infiniteQueryKeys: { 324 + /** 325 + * The casing convention to use for generated names. 326 + * 327 + * @default 'camelCase' 328 + */ 329 + case: StringCase; 330 + /** 331 + * Whether to generate infinite query key helpers. 332 + * 333 + * @default true 334 + */ 335 + enabled: boolean; 336 + /** 337 + * Custom naming pattern for generated infinite query key names. The name variable is 338 + * obtained from the SDK function name. 339 + * 340 + * @default '{{name}}InfiniteQueryKey' 341 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 342 + */ 343 + name: StringName; 344 + /** 345 + * Whether to include operation tags in infinite query keys. 346 + * This will make query keys larger but provides better cache invalidation capabilities. 347 + * 348 + * @default false 349 + */ 350 + tags: boolean; 351 + }; 494 352 /** 495 - * The casing convention to use for generated names. 353 + * Resolved configuration for generated infinite query options helpers. 496 354 * 497 - * @default 'camelCase' 355 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 498 356 */ 499 - case: StringCase; 357 + infiniteQueryOptions: { 358 + /** 359 + * The casing convention to use for generated names. 360 + * 361 + * @default 'camelCase' 362 + */ 363 + case: StringCase; 364 + /** 365 + * Whether to generate infinite query options helpers. 366 + * 367 + * @default true 368 + */ 369 + enabled: boolean; 370 + /** 371 + * Custom function to generate metadata for the operation. 372 + * Can return any valid meta object that will be included in the generated infinite query options. 373 + * @param operation - The operation object containing all available metadata 374 + * @returns A meta object with any properties you want to include 375 + * 376 + * @example 377 + * ```typescript 378 + * meta: (operation) => ({ 379 + * customField: operation.id, 380 + * isDeprecated: operation.deprecated, 381 + * tags: operation.tags, 382 + * customObject: { 383 + * method: operation.method, 384 + * path: operation.path 385 + * } 386 + * }) 387 + * ``` 388 + * 389 + * @default undefined 390 + */ 391 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 392 + /** 393 + * Custom naming pattern for generated infinite query options names. The name variable is 394 + * obtained from the SDK function name. 395 + * 396 + * @default '{{name}}InfiniteOptions' 397 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 398 + */ 399 + name: StringName; 400 + }; 500 401 /** 501 - * Whether to generate query options helpers. 402 + * Resolved configuration for generated mutation options helpers. 502 403 * 503 - * @default true 404 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 504 405 */ 505 - enabled: boolean; 406 + mutationOptions: { 407 + /** 408 + * The casing convention to use for generated names. 409 + * 410 + * @default 'camelCase' 411 + */ 412 + case: StringCase; 413 + /** 414 + * Whether to generate mutation options helpers. 415 + * 416 + * @default true 417 + */ 418 + enabled: boolean; 419 + /** 420 + * Custom function to generate metadata for the operation. 421 + * Can return any valid meta object that will be included in the generated mutation options. 422 + * @param operation - The operation object containing all available metadata 423 + * @returns A meta object with any properties you want to include 424 + * 425 + * @example 426 + * ```typescript 427 + * meta: (operation) => ({ 428 + * customField: operation.id, 429 + * isDeprecated: operation.deprecated, 430 + * tags: operation.tags, 431 + * customObject: { 432 + * method: operation.method, 433 + * path: operation.path 434 + * } 435 + * }) 436 + * ``` 437 + * 438 + * @default undefined 439 + */ 440 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 441 + /** 442 + * Custom naming pattern for generated mutation options names. The name variable is 443 + * obtained from the SDK function name. 444 + * 445 + * @default '{{name}}Mutation' 446 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 447 + */ 448 + name: StringName; 449 + }; 506 450 /** 507 - * Custom function to generate metadata for the operation. 508 - * Can return any valid meta object that will be included in the generated query options. 509 - * @param operation - The operation object containing all available metadata 510 - * @returns A meta object with any properties you want to include 451 + * Name of the generated file. 511 452 * 512 - * @example 513 - * ```typescript 514 - * meta: (operation) => ({ 515 - * customField: operation.id, 516 - * isDeprecated: operation.deprecated, 517 - * tags: operation.tags, 518 - * customObject: { 519 - * method: operation.method, 520 - * path: operation.path 521 - * } 522 - * }) 523 - * ``` 453 + * @default '@tanstack/angular-query-experimental' 454 + */ 455 + output: string; 456 + /** 457 + * Resolved configuration for generated query keys. 524 458 * 525 - * @default false 459 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 526 460 */ 527 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 461 + queryKeys: { 462 + /** 463 + * The casing convention to use for generated names. 464 + * 465 + * @default 'camelCase' 466 + */ 467 + case: StringCase; 468 + /** 469 + * Whether to generate query keys. 470 + * 471 + * @default true 472 + */ 473 + enabled: boolean; 474 + /** 475 + * Custom naming pattern for generated query key names. The name variable is 476 + * obtained from the SDK function name. 477 + * 478 + * @default '{{name}}QueryKey' 479 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 480 + */ 481 + name: StringName; 482 + /** 483 + * Whether to include operation tags in query keys. 484 + * This will make query keys larger but provides better cache invalidation capabilities. 485 + * 486 + * @default false 487 + */ 488 + tags: boolean; 489 + }; 528 490 /** 529 - * Custom naming pattern for generated query options names. The name variable is 530 - * obtained from the SDK function name. 491 + * Resolved configuration for generated query options helpers. 531 492 * 532 - * @default '{{name}}Options' 533 493 * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 534 494 */ 535 - name: StringName; 495 + queryOptions: { 496 + /** 497 + * The casing convention to use for generated names. 498 + * 499 + * @default 'camelCase' 500 + */ 501 + case: StringCase; 502 + /** 503 + * Whether to generate query options helpers. 504 + * 505 + * @default true 506 + */ 507 + enabled: boolean; 508 + /** 509 + * Custom function to generate metadata for the operation. 510 + * Can return any valid meta object that will be included in the generated query options. 511 + * @param operation - The operation object containing all available metadata 512 + * @returns A meta object with any properties you want to include 513 + * 514 + * @example 515 + * ```typescript 516 + * meta: (operation) => ({ 517 + * customField: operation.id, 518 + * isDeprecated: operation.deprecated, 519 + * tags: operation.tags, 520 + * customObject: { 521 + * method: operation.method, 522 + * path: operation.path 523 + * } 524 + * }) 525 + * ``` 526 + * 527 + * @default undefined 528 + */ 529 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 530 + /** 531 + * Custom naming pattern for generated query options names. The name variable is 532 + * obtained from the SDK function name. 533 + * 534 + * @default '{{name}}Options' 535 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 536 + */ 537 + name: StringName; 538 + }; 536 539 }; 537 - }; 538 540 539 541 export type TanStackAngularQueryPlugin = DefinePlugin<UserConfig, Config>;
+2 -4
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 236 236 state: PluginState; 237 237 }) => { 238 238 if ( 239 - !plugin.config.infiniteQueryOptions || 240 - !(['get', 'post'] as ReadonlyArray<typeof operation.method>).includes( 241 - operation.method, 242 - ) 239 + !plugin.config.infiniteQueryOptions.enabled || 240 + !plugin.hooks.operation.isQuery(operation) 243 241 ) { 244 242 return state; 245 243 }
+5 -14
packages/openapi-ts/src/plugins/@tanstack/query-core/meta.ts
··· 4 4 import { tsc } from '../../../tsc'; 5 5 import type { PluginInstance } from './types'; 6 6 7 - /** 8 - * Handle the meta configuration 9 - * @param plugin - The plugin instance 10 - * @param operation - The operation object to get the meta from 11 - * @param targetArray - The target array to add the meta to 12 - * @param configPath - The path to the meta configuration 13 - */ 14 7 export const handleMeta = ( 15 8 plugin: PluginInstance, 16 9 operation: IR.OperationObject, 17 10 configPath: 'queryOptions' | 'infiniteQueryOptions' | 'mutationOptions', 18 11 ): ts.Expression | undefined => { 19 - const metaConfig = plugin.config[configPath].meta; 12 + const metaFn = plugin.config[configPath].meta; 13 + if (!metaFn) return; 20 14 21 - if (typeof metaConfig !== 'function') { 22 - return undefined; 23 - } 15 + const metaObject = metaFn(operation); 16 + if (!Object.keys(metaObject).length) return; 24 17 25 - const customMeta = metaConfig(operation); 26 - 27 - return tsc.valueToExpression({ value: customMeta }); 18 + return tsc.valueToExpression({ value: metaObject }); 28 19 };
+1 -5
packages/openapi-ts/src/plugins/@tanstack/query-core/mutationOptions.ts
··· 22 22 }) => { 23 23 if ( 24 24 !plugin.config.mutationOptions.enabled || 25 - !( 26 - ['delete', 'patch', 'post', 'put'] as ReadonlyArray< 27 - typeof operation.method 28 - > 29 - ).includes(operation.method) 25 + !plugin.hooks.operation.isMutation(operation) 30 26 ) { 31 27 return state; 32 28 }
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts
··· 735 735 736 736 // queries 737 737 if ( 738 - plugin.config.queryOptions && 738 + plugin.config.queryOptions.enabled && 739 739 (['GET', 'POST'] as ReadonlyArray<Method>).includes(operation.method) 740 740 ) { 741 741 if (!hasQueries) {
+2 -4
packages/openapi-ts/src/plugins/@tanstack/query-core/queryOptions.ts
··· 29 29 state: PluginState; 30 30 }) => { 31 31 if ( 32 - !plugin.config.queryOptions || 33 - !(['get', 'post'] as ReadonlyArray<typeof operation.method>).includes( 34 - operation.method, 35 - ) 32 + !plugin.config.queryOptions.enabled || 33 + !plugin.hooks.operation.isQuery(operation) 36 34 ) { 37 35 return state; 38 36 }
-3
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
··· 34 34 defaultValue: { 35 35 case: plugin.config.case ?? 'camelCase', 36 36 enabled: true, 37 - meta: false, 38 37 name: '{{name}}InfiniteOptions', 39 38 }, 40 39 mappers: { ··· 49 48 defaultValue: { 50 49 case: plugin.config.case ?? 'camelCase', 51 50 enabled: true, 52 - meta: false, 53 51 name: '{{name}}Mutation', 54 52 }, 55 53 mappers: { ··· 79 77 defaultValue: { 80 78 case: plugin.config.case ?? 'camelCase', 81 79 enabled: true, 82 - meta: false, 83 80 name: '{{name}}Options', 84 81 }, 85 82 mappers: {
+473 -459
packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts
··· 2 2 import type { StringCase, StringName } from '../../../types/case'; 3 3 import type { DefinePlugin, Plugin } from '../../types'; 4 4 5 - export type UserConfig = Plugin.Name<'@tanstack/react-query'> & { 6 - /** 7 - * The casing convention to use for generated names. 8 - * 9 - * @default 'camelCase' 10 - */ 11 - case?: StringCase; 12 - /** 13 - * Add comments from SDK functions to the generated TanStack Query code? 14 - * Duplicating comments this way is useful so you don't need to drill into 15 - * the underlying SDK function to learn what it does or whether it's 16 - * deprecated. You can set this option to `false` if you prefer less 17 - * comment duplication. 18 - * 19 - * @default true 20 - */ 21 - comments?: boolean; 22 - /** 23 - * Should the exports from the generated files be re-exported in the index 24 - * barrel file? 25 - * 26 - * @default false 27 - */ 28 - exportFromIndex?: boolean; 29 - /** 30 - * Configuration for generated infinite query key helpers. 31 - * 32 - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions TanStack Query: infiniteQueryOptions} 33 - * 34 - * Can be: 35 - * - `boolean`: Shorthand for `{ enabled: boolean }` 36 - * - `string` or `function`: Shorthand for `{ name: string | function }` 37 - * - `object`: Full configuration object 38 - * 39 - * @default true 40 - */ 41 - infiniteQueryKeys?: 42 - | boolean 43 - | StringName 44 - | { 45 - /** 46 - * The casing convention to use for generated names. 47 - * 48 - * @default 'camelCase' 49 - */ 50 - case?: StringCase; 51 - /** 52 - * Whether to generate infinite query key helpers. 53 - * 54 - * @default true 55 - */ 56 - enabled?: boolean; 57 - /** 58 - * Custom naming pattern for generated infinite query key names. The name variable is 59 - * obtained from the SDK function name. 60 - * 61 - * @default '{{name}}InfiniteQueryKey' 62 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 63 - */ 64 - name?: StringName; 65 - /** 66 - * Whether to include operation tags in infinite query keys. 67 - * This will make query keys larger but provides better cache invalidation capabilities. 68 - * 69 - * @default false 70 - */ 71 - tags?: boolean; 72 - }; 73 - /** 74 - * Configuration for generated infinite query options helpers. 75 - * 76 - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions TanStack Query: infiniteQueryOptions} 77 - * 78 - * Can be: 79 - * - `boolean`: Shorthand for `{ enabled: boolean }` 80 - * - `string` or `function`: Shorthand for `{ name: string | function }` 81 - * - `object`: Full configuration object 82 - * 83 - * @default true 84 - */ 85 - infiniteQueryOptions?: 86 - | boolean 87 - | StringName 88 - | { 89 - /** 90 - * The casing convention to use for generated names. 91 - * 92 - * @default 'camelCase' 93 - */ 94 - case?: StringCase; 95 - /** 96 - * Whether to generate infinite query options helpers. 97 - * 98 - * @default true 99 - */ 100 - enabled?: boolean; 101 - /** 102 - * Custom function to generate metadata for the operation. 103 - * Can return any valid meta object that will be included in the generated infinite query options. 104 - * 105 - * @param operation - The operation object containing all available metadata 106 - * @returns A meta object with any properties you want to include 107 - * 108 - * @example 109 - * ```typescript 110 - * meta: (operation) => ({ 111 - * customField: operation.id, 112 - * isDeprecated: operation.deprecated, 113 - * tags: operation.tags, 114 - * customObject: { 115 - * method: operation.method, 116 - * path: operation.path 117 - * } 118 - * }) 119 - * ``` 120 - */ 121 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 122 - /** 123 - * Custom naming pattern for generated infinite query options names. The name variable is 124 - * obtained from the SDK function name. 125 - * 126 - * @default '{{name}}InfiniteOptions' 127 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 128 - */ 129 - name?: StringName; 130 - }; 131 - /** 132 - * Configuration for generated mutation options helpers. 133 - * 134 - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation TanStack Query: useMutation} 135 - * 136 - * Can be: 137 - * - `boolean`: Shorthand for `{ enabled: boolean }` 138 - * - `string` or `function`: Shorthand for `{ name: string | function }` 139 - * - `object`: Full configuration object 140 - * 141 - * @default true 142 - */ 143 - mutationOptions?: 144 - | boolean 145 - | StringName 146 - | { 147 - /** 148 - * The casing convention to use for generated names. 149 - * 150 - * @default 'camelCase' 151 - */ 152 - case?: StringCase; 153 - /** 154 - * Whether to generate mutation options helpers. 155 - * 156 - * @default true 157 - */ 158 - enabled?: boolean; 159 - /** 160 - * Custom function to generate metadata for the operation. 161 - * Can return any valid meta object that will be included in the generated mutation options. 162 - * 163 - * @param operation - The operation object containing all available metadata 164 - * @returns A meta object with any properties you want to include 165 - * 166 - * @example 167 - * ```typescript 168 - * meta: (operation) => ({ 169 - * customField: operation.id, 170 - * isDeprecated: operation.deprecated, 171 - * tags: operation.tags, 172 - * customObject: { 173 - * method: operation.method, 174 - * path: operation.path 175 - * } 176 - * }) 177 - * ``` 178 - */ 179 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 180 - /** 181 - * Custom naming pattern for generated mutation options names. The name variable is 182 - * obtained from the SDK function name. 183 - * 184 - * @default '{{name}}Mutation' 185 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 186 - */ 187 - name?: StringName; 188 - }; 189 - /** 190 - * Name of the generated file. 191 - * 192 - * @default '@tanstack/react-query' 193 - */ 194 - output?: string; 195 - /** 196 - * Configuration for generated query keys. 197 - * 198 - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryKey TanStack Query: queryKey} 199 - * 200 - * Can be: 201 - * - `boolean`: Shorthand for `{ enabled: boolean }` 202 - * - `string` or `function`: Shorthand for `{ name: string | function }` 203 - * - `object`: Full configuration object 204 - * 205 - * @default true 206 - */ 207 - queryKeys?: 208 - | boolean 209 - | StringName 210 - | { 211 - /** 212 - * The casing convention to use for generated names. 213 - * 214 - * @default 'camelCase' 215 - */ 216 - case?: StringCase; 217 - /** 218 - * Whether to generate query keys. 219 - * 220 - * @default true 221 - */ 222 - enabled?: boolean; 223 - /** 224 - * Custom naming pattern for generated query key names. The name variable is 225 - * obtained from the SDK function name. 226 - * 227 - * @default '{{name}}QueryKey' 228 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 229 - */ 230 - name?: StringName; 231 - /** 232 - * Whether to include operation tags in query keys. 233 - * This will make query keys larger but provides better cache invalidation capabilities. 234 - * 235 - * @default false 236 - */ 237 - tags?: boolean; 238 - }; 239 - /** 240 - * Configuration for generated query options helpers. 241 - * 242 - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions TanStack Query: queryOptions} 243 - * 244 - * Can be: 245 - * - `boolean`: Shorthand for `{ enabled: boolean }` 246 - * - `string` or `function`: Shorthand for `{ name: string | function }` 247 - * - `object`: Full configuration object 248 - * 249 - * @default true 250 - */ 251 - queryOptions?: 252 - | boolean 253 - | StringName 254 - | { 255 - /** 256 - * The casing convention to use for generated names. 257 - * 258 - * @default 'camelCase' 259 - */ 260 - case?: StringCase; 261 - /** 262 - * Whether to generate query options helpers. 263 - * 264 - * @default true 265 - */ 266 - enabled?: boolean; 267 - /** 268 - * Custom function to generate metadata for the operation. 269 - * Can return any valid meta object that will be included in the generated query options. 270 - * 271 - * @param operation - The operation object containing all available metadata 272 - * @returns A meta object with any properties you want to include 273 - * 274 - * @example 275 - * ```typescript 276 - * meta: (operation) => ({ 277 - * customField: operation.id, 278 - * isDeprecated: operation.deprecated, 279 - * tags: operation.tags, 280 - * customObject: { 281 - * method: operation.method, 282 - * path: operation.path 283 - * } 284 - * }) 285 - * ``` 286 - */ 287 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 288 - 289 - /** 290 - * Custom naming pattern for generated query options names. The name variable is 291 - * obtained from the SDK function name. 292 - * 293 - * @default '{{name}}Options' 294 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 295 - */ 296 - name?: StringName; 297 - }; 298 - }; 299 - 300 - export type Config = Plugin.Name<'@tanstack/react-query'> & { 301 - /** 302 - * The casing convention to use for generated names. 303 - * 304 - * @default 'camelCase' 305 - */ 306 - case: StringCase; 307 - /** 308 - * Add comments from SDK functions to the generated TanStack Query code? 309 - * 310 - * @default true 311 - */ 312 - comments: boolean; 313 - /** 314 - * Should the exports from the generated files be re-exported in the index barrel file? 315 - * 316 - * @default false 317 - */ 318 - exportFromIndex: boolean; 319 - /** 320 - * Resolved configuration for generated infinite query key helpers. 321 - * 322 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 323 - */ 324 - infiniteQueryKeys: { 5 + export type UserConfig = Plugin.Name<'@tanstack/react-query'> & 6 + Plugin.Hooks & { 325 7 /** 326 8 * The casing convention to use for generated names. 327 9 * 328 10 * @default 'camelCase' 329 11 */ 330 - case: StringCase; 12 + case?: StringCase; 331 13 /** 332 - * Whether to generate infinite query key helpers. 14 + * Add comments from SDK functions to the generated TanStack Query code? 15 + * Duplicating comments this way is useful so you don't need to drill into 16 + * the underlying SDK function to learn what it does or whether it's 17 + * deprecated. You can set this option to `false` if you prefer less 18 + * comment duplication. 333 19 * 334 20 * @default true 335 21 */ 336 - enabled: boolean; 22 + comments?: boolean; 337 23 /** 338 - * Custom naming pattern for generated infinite query key names. The name variable is obtained from the SDK function name. 24 + * Should the exports from the generated files be re-exported in the index 25 + * barrel file? 339 26 * 340 - * @default '{{name}}InfiniteQueryKey' 341 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 27 + * @default false 342 28 */ 343 - name: StringName; 29 + exportFromIndex?: boolean; 344 30 /** 345 - * Whether to include operation tags in infinite query keys. 346 - * This will make query keys larger but provides better cache invalidation capabilities. 31 + * Configuration for generated infinite query key helpers. 347 32 * 348 - * @default false 349 - */ 350 - tags: boolean; 351 - }; 352 - /** 353 - * Resolved configuration for generated infinite query options helpers. 354 - * 355 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 356 - */ 357 - infiniteQueryOptions: { 358 - /** 359 - * The casing convention to use for generated names. 33 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions TanStack Query: infiniteQueryOptions} 360 34 * 361 - * @default 'camelCase' 362 - */ 363 - case: StringCase; 364 - /** 365 - * Whether to generate infinite query options helpers. 35 + * Can be: 36 + * - `boolean`: Shorthand for `{ enabled: boolean }` 37 + * - `string` or `function`: Shorthand for `{ name: string | function }` 38 + * - `object`: Full configuration object 366 39 * 367 40 * @default true 368 41 */ 369 - enabled: boolean; 42 + infiniteQueryKeys?: 43 + | boolean 44 + | StringName 45 + | { 46 + /** 47 + * The casing convention to use for generated names. 48 + * 49 + * @default 'camelCase' 50 + */ 51 + case?: StringCase; 52 + /** 53 + * Whether to generate infinite query key helpers. 54 + * 55 + * @default true 56 + */ 57 + enabled?: boolean; 58 + /** 59 + * Custom naming pattern for generated infinite query key names. The name variable is 60 + * obtained from the SDK function name. 61 + * 62 + * @default '{{name}}InfiniteQueryKey' 63 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 64 + */ 65 + name?: StringName; 66 + /** 67 + * Whether to include operation tags in infinite query keys. 68 + * This will make query keys larger but provides better cache invalidation capabilities. 69 + * 70 + * @default false 71 + */ 72 + tags?: boolean; 73 + }; 370 74 /** 371 - * Custom function to generate metadata for the operation. 372 - * Can return any valid meta object that will be included in the generated infinite query options. 75 + * Configuration for generated infinite query options helpers. 373 76 * 374 - * @param operation - The operation object containing all available metadata 375 - * @returns A meta object with any properties you want to include 77 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions TanStack Query: infiniteQueryOptions} 376 78 * 377 - * @example 378 - * ```typescript 379 - * meta: (operation) => ({ 380 - * customField: operation.id, 381 - * isDeprecated: operation.deprecated, 382 - * tags: operation.tags, 383 - * customObject: { 384 - * method: operation.method, 385 - * path: operation.path 386 - * } 387 - * }) 388 - * ``` 79 + * Can be: 80 + * - `boolean`: Shorthand for `{ enabled: boolean }` 81 + * - `string` or `function`: Shorthand for `{ name: string | function }` 82 + * - `object`: Full configuration object 83 + * 84 + * @default true 389 85 */ 390 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 86 + infiniteQueryOptions?: 87 + | boolean 88 + | StringName 89 + | { 90 + /** 91 + * The casing convention to use for generated names. 92 + * 93 + * @default 'camelCase' 94 + */ 95 + case?: StringCase; 96 + /** 97 + * Whether to generate infinite query options helpers. 98 + * 99 + * @default true 100 + */ 101 + enabled?: boolean; 102 + /** 103 + * Custom function to generate metadata for the operation. 104 + * Can return any valid meta object that will be included in the generated infinite query options. 105 + * 106 + * @param operation - The operation object containing all available metadata 107 + * @returns A meta object with any properties you want to include 108 + * 109 + * @example 110 + * ```typescript 111 + * meta: (operation) => ({ 112 + * customField: operation.id, 113 + * isDeprecated: operation.deprecated, 114 + * tags: operation.tags, 115 + * customObject: { 116 + * method: operation.method, 117 + * path: operation.path 118 + * } 119 + * }) 120 + * ``` 121 + * 122 + * @default undefined 123 + */ 124 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 125 + /** 126 + * Custom naming pattern for generated infinite query options names. The name variable is 127 + * obtained from the SDK function name. 128 + * 129 + * @default '{{name}}InfiniteOptions' 130 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 131 + */ 132 + name?: StringName; 133 + }; 391 134 /** 392 - * Custom naming pattern for generated infinite query options names. The name variable is obtained from the SDK function name. 135 + * Configuration for generated mutation options helpers. 136 + * 137 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation TanStack Query: useMutation} 393 138 * 394 - * @default '{{name}}InfiniteOptions' 395 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 139 + * Can be: 140 + * - `boolean`: Shorthand for `{ enabled: boolean }` 141 + * - `string` or `function`: Shorthand for `{ name: string | function }` 142 + * - `object`: Full configuration object 143 + * 144 + * @default true 396 145 */ 397 - name: StringName; 398 - }; 399 - /** 400 - * Resolved configuration for generated mutation options helpers. 401 - * 402 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 403 - */ 404 - mutationOptions: { 146 + mutationOptions?: 147 + | boolean 148 + | StringName 149 + | { 150 + /** 151 + * The casing convention to use for generated names. 152 + * 153 + * @default 'camelCase' 154 + */ 155 + case?: StringCase; 156 + /** 157 + * Whether to generate mutation options helpers. 158 + * 159 + * @default true 160 + */ 161 + enabled?: boolean; 162 + /** 163 + * Custom function to generate metadata for the operation. 164 + * Can return any valid meta object that will be included in the generated mutation options. 165 + * 166 + * @param operation - The operation object containing all available metadata 167 + * @returns A meta object with any properties you want to include 168 + * 169 + * @example 170 + * ```typescript 171 + * meta: (operation) => ({ 172 + * customField: operation.id, 173 + * isDeprecated: operation.deprecated, 174 + * tags: operation.tags, 175 + * customObject: { 176 + * method: operation.method, 177 + * path: operation.path 178 + * } 179 + * }) 180 + * ``` 181 + * 182 + * @default undefined 183 + */ 184 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 185 + /** 186 + * Custom naming pattern for generated mutation options names. The name variable is 187 + * obtained from the SDK function name. 188 + * 189 + * @default '{{name}}Mutation' 190 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 191 + */ 192 + name?: StringName; 193 + }; 405 194 /** 406 - * The casing convention to use for generated names. 195 + * Name of the generated file. 407 196 * 408 - * @default 'camelCase' 197 + * @default '@tanstack/react-query' 409 198 */ 410 - case: StringCase; 199 + output?: string; 411 200 /** 412 - * Whether to generate mutation options helpers. 201 + * Configuration for generated query keys. 202 + * 203 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryKey TanStack Query: queryKey} 204 + * 205 + * Can be: 206 + * - `boolean`: Shorthand for `{ enabled: boolean }` 207 + * - `string` or `function`: Shorthand for `{ name: string | function }` 208 + * - `object`: Full configuration object 413 209 * 414 210 * @default true 415 211 */ 416 - enabled: boolean; 212 + queryKeys?: 213 + | boolean 214 + | StringName 215 + | { 216 + /** 217 + * The casing convention to use for generated names. 218 + * 219 + * @default 'camelCase' 220 + */ 221 + case?: StringCase; 222 + /** 223 + * Whether to generate query keys. 224 + * 225 + * @default true 226 + */ 227 + enabled?: boolean; 228 + /** 229 + * Custom naming pattern for generated query key names. The name variable is 230 + * obtained from the SDK function name. 231 + * 232 + * @default '{{name}}QueryKey' 233 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 234 + */ 235 + name?: StringName; 236 + /** 237 + * Whether to include operation tags in query keys. 238 + * This will make query keys larger but provides better cache invalidation capabilities. 239 + * 240 + * @default false 241 + */ 242 + tags?: boolean; 243 + }; 417 244 /** 418 - * Custom function to generate metadata for the operation. 419 - * Can return any valid meta object that will be included in the generated mutation options. 245 + * Configuration for generated query options helpers. 420 246 * 421 - * @param operation - The operation object containing all available metadata 422 - * @returns A meta object with any properties you want to include 247 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions TanStack Query: queryOptions} 423 248 * 424 - * @example 425 - * ```typescript 426 - * meta: (operation) => ({ 427 - * customField: operation.id, 428 - * isDeprecated: operation.deprecated, 429 - * tags: operation.tags, 430 - * customObject: { 431 - * method: operation.method, 432 - * path: operation.path 433 - * } 434 - * }) 435 - * ``` 436 - */ 437 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 438 - /** 439 - * Custom naming pattern for generated mutation options names. The name variable is obtained from the SDK function name. 249 + * Can be: 250 + * - `boolean`: Shorthand for `{ enabled: boolean }` 251 + * - `string` or `function`: Shorthand for `{ name: string | function }` 252 + * - `object`: Full configuration object 440 253 * 441 - * @default '{{name}}Mutation' 442 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 254 + * @default true 443 255 */ 444 - name: StringName; 256 + queryOptions?: 257 + | boolean 258 + | StringName 259 + | { 260 + /** 261 + * The casing convention to use for generated names. 262 + * 263 + * @default 'camelCase' 264 + */ 265 + case?: StringCase; 266 + /** 267 + * Whether to generate query options helpers. 268 + * 269 + * @default true 270 + */ 271 + enabled?: boolean; 272 + /** 273 + * Custom function to generate metadata for the operation. 274 + * Can return any valid meta object that will be included in the generated query options. 275 + * 276 + * @param operation - The operation object containing all available metadata 277 + * @returns A meta object with any properties you want to include 278 + * 279 + * @example 280 + * ```typescript 281 + * meta: (operation) => ({ 282 + * customField: operation.id, 283 + * isDeprecated: operation.deprecated, 284 + * tags: operation.tags, 285 + * customObject: { 286 + * method: operation.method, 287 + * path: operation.path 288 + * } 289 + * }) 290 + * ``` 291 + * 292 + * @default undefined 293 + */ 294 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 295 + 296 + /** 297 + * Custom naming pattern for generated query options names. The name variable is 298 + * obtained from the SDK function name. 299 + * 300 + * @default '{{name}}Options' 301 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 302 + */ 303 + name?: StringName; 304 + }; 445 305 }; 446 - /** 447 - * Name of the generated file. 448 - * 449 - * @default '@tanstack/react-query' 450 - */ 451 - output: string; 452 - /** 453 - * Resolved configuration for generated query keys. 454 - * 455 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 456 - */ 457 - queryKeys: { 306 + 307 + export type Config = Plugin.Name<'@tanstack/react-query'> & 308 + Plugin.Hooks & { 458 309 /** 459 310 * The casing convention to use for generated names. 460 311 * ··· 462 313 */ 463 314 case: StringCase; 464 315 /** 465 - * Whether to generate query keys. 316 + * Add comments from SDK functions to the generated TanStack Query code? 466 317 * 467 318 * @default true 468 319 */ 469 - enabled: boolean; 320 + comments: boolean; 470 321 /** 471 - * Custom naming pattern for generated query key names. The name variable is obtained from the SDK function name. 322 + * Should the exports from the generated files be re-exported in the index barrel file? 472 323 * 473 - * @default '{{name}}QueryKey' 474 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 324 + * @default false 475 325 */ 476 - name: StringName; 326 + exportFromIndex: boolean; 477 327 /** 478 - * Whether to include operation tags in query keys. 479 - * This will make query keys larger but provides better cache invalidation capabilities. 328 + * Resolved configuration for generated infinite query key helpers. 480 329 * 481 - * @default false 330 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 482 331 */ 483 - tags: boolean; 484 - }; 485 - /** 486 - * Resolved configuration for generated query options helpers. 487 - * 488 - * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 489 - */ 490 - queryOptions: { 332 + infiniteQueryKeys: { 333 + /** 334 + * The casing convention to use for generated names. 335 + * 336 + * @default 'camelCase' 337 + */ 338 + case: StringCase; 339 + /** 340 + * Whether to generate infinite query key helpers. 341 + * 342 + * @default true 343 + */ 344 + enabled: boolean; 345 + /** 346 + * Custom naming pattern for generated infinite query key names. The name variable is obtained from the SDK function name. 347 + * 348 + * @default '{{name}}InfiniteQueryKey' 349 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 350 + */ 351 + name: StringName; 352 + /** 353 + * Whether to include operation tags in infinite query keys. 354 + * This will make query keys larger but provides better cache invalidation capabilities. 355 + * 356 + * @default false 357 + */ 358 + tags: boolean; 359 + }; 491 360 /** 492 - * The casing convention to use for generated names. 361 + * Resolved configuration for generated infinite query options helpers. 493 362 * 494 - * @default 'camelCase' 363 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 495 364 */ 496 - case: StringCase; 365 + infiniteQueryOptions: { 366 + /** 367 + * The casing convention to use for generated names. 368 + * 369 + * @default 'camelCase' 370 + */ 371 + case: StringCase; 372 + /** 373 + * Whether to generate infinite query options helpers. 374 + * 375 + * @default true 376 + */ 377 + enabled: boolean; 378 + /** 379 + * Custom function to generate metadata for the operation. 380 + * Can return any valid meta object that will be included in the generated infinite query options. 381 + * 382 + * @param operation - The operation object containing all available metadata 383 + * @returns A meta object with any properties you want to include 384 + * 385 + * @example 386 + * ```typescript 387 + * meta: (operation) => ({ 388 + * customField: operation.id, 389 + * isDeprecated: operation.deprecated, 390 + * tags: operation.tags, 391 + * customObject: { 392 + * method: operation.method, 393 + * path: operation.path 394 + * } 395 + * }) 396 + * ``` 397 + * 398 + * @default undefined 399 + */ 400 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 401 + /** 402 + * Custom naming pattern for generated infinite query options names. The name variable is obtained from the SDK function name. 403 + * 404 + * @default '{{name}}InfiniteOptions' 405 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 406 + */ 407 + name: StringName; 408 + }; 497 409 /** 498 - * Whether to generate query options helpers. 410 + * Resolved configuration for generated mutation options helpers. 499 411 * 500 - * @default true 412 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 501 413 */ 502 - enabled: boolean; 414 + mutationOptions: { 415 + /** 416 + * The casing convention to use for generated names. 417 + * 418 + * @default 'camelCase' 419 + */ 420 + case: StringCase; 421 + /** 422 + * Whether to generate mutation options helpers. 423 + * 424 + * @default true 425 + */ 426 + enabled: boolean; 427 + /** 428 + * Custom function to generate metadata for the operation. 429 + * Can return any valid meta object that will be included in the generated mutation options. 430 + * 431 + * @param operation - The operation object containing all available metadata 432 + * @returns A meta object with any properties you want to include 433 + * 434 + * @example 435 + * ```typescript 436 + * meta: (operation) => ({ 437 + * customField: operation.id, 438 + * isDeprecated: operation.deprecated, 439 + * tags: operation.tags, 440 + * customObject: { 441 + * method: operation.method, 442 + * path: operation.path 443 + * } 444 + * }) 445 + * ``` 446 + * 447 + * @default undefined 448 + */ 449 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 450 + /** 451 + * Custom naming pattern for generated mutation options names. The name variable is obtained from the SDK function name. 452 + * 453 + * @default '{{name}}Mutation' 454 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 455 + */ 456 + name: StringName; 457 + }; 503 458 /** 504 - * Custom function to generate metadata for the operation. 505 - * Can return any valid meta object that will be included in the generated query options. 459 + * Name of the generated file. 506 460 * 507 - * @param operation - The operation object containing all available metadata 508 - * @returns A meta object with any properties you want to include 461 + * @default '@tanstack/react-query' 462 + */ 463 + output: string; 464 + /** 465 + * Resolved configuration for generated query keys. 509 466 * 510 - * @example 511 - * ```typescript 512 - * meta: (operation) => ({ 513 - * customField: operation.id, 514 - * isDeprecated: operation.deprecated, 515 - * tags: operation.tags, 516 - * customObject: { 517 - * method: operation.method, 518 - * path: operation.path 519 - * } 520 - * }) 521 - * ``` 467 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 522 468 */ 523 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 469 + queryKeys: { 470 + /** 471 + * The casing convention to use for generated names. 472 + * 473 + * @default 'camelCase' 474 + */ 475 + case: StringCase; 476 + /** 477 + * Whether to generate query keys. 478 + * 479 + * @default true 480 + */ 481 + enabled: boolean; 482 + /** 483 + * Custom naming pattern for generated query key names. The name variable is obtained from the SDK function name. 484 + * 485 + * @default '{{name}}QueryKey' 486 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 487 + */ 488 + name: StringName; 489 + /** 490 + * Whether to include operation tags in query keys. 491 + * This will make query keys larger but provides better cache invalidation capabilities. 492 + * 493 + * @default false 494 + */ 495 + tags: boolean; 496 + }; 524 497 /** 525 - * Custom naming pattern for generated query options names. The name variable is obtained from the SDK function name. 498 + * Resolved configuration for generated query options helpers. 526 499 * 527 - * @default '{{name}}Options' 528 500 * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 529 501 */ 530 - name: StringName; 502 + queryOptions: { 503 + /** 504 + * The casing convention to use for generated names. 505 + * 506 + * @default 'camelCase' 507 + */ 508 + case: StringCase; 509 + /** 510 + * Whether to generate query options helpers. 511 + * 512 + * @default true 513 + */ 514 + enabled: boolean; 515 + /** 516 + * Custom function to generate metadata for the operation. 517 + * Can return any valid meta object that will be included in the generated query options. 518 + * 519 + * @param operation - The operation object containing all available metadata 520 + * @returns A meta object with any properties you want to include 521 + * 522 + * @example 523 + * ```typescript 524 + * meta: (operation) => ({ 525 + * customField: operation.id, 526 + * isDeprecated: operation.deprecated, 527 + * tags: operation.tags, 528 + * customObject: { 529 + * method: operation.method, 530 + * path: operation.path 531 + * } 532 + * }) 533 + * ``` 534 + * 535 + * @default undefined 536 + */ 537 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 538 + /** 539 + * Custom naming pattern for generated query options names. The name variable is obtained from the SDK function name. 540 + * 541 + * @default '{{name}}Options' 542 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 543 + */ 544 + name: StringName; 545 + }; 531 546 }; 532 - }; 533 547 534 548 export type TanStackReactQueryPlugin = DefinePlugin<UserConfig, Config>;
-3
packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts
··· 34 34 defaultValue: { 35 35 case: plugin.config.case ?? 'camelCase', 36 36 enabled: true, 37 - meta: false, 38 37 name: '{{name}}InfiniteOptions', 39 38 }, 40 39 mappers: { ··· 49 48 defaultValue: { 50 49 case: plugin.config.case ?? 'camelCase', 51 50 enabled: true, 52 - meta: false, 53 51 name: '{{name}}Mutation', 54 52 }, 55 53 mappers: { ··· 79 77 defaultValue: { 80 78 case: plugin.config.case ?? 'camelCase', 81 79 enabled: true, 82 - meta: false, 83 80 name: '{{name}}Options', 84 81 }, 85 82 mappers: {
+467 -463
packages/openapi-ts/src/plugins/@tanstack/solid-query/types.d.ts
··· 2 2 import type { StringCase, StringName } from '../../../types/case'; 3 3 import type { DefinePlugin, Plugin } from '../../types'; 4 4 5 - export type UserConfig = Plugin.Name<'@tanstack/solid-query'> & { 6 - /** 7 - * The casing convention to use for generated names. 8 - * 9 - * @default 'camelCase' 10 - */ 11 - case?: StringCase; 12 - /** 13 - * Add comments from SDK functions to the generated TanStack Query code? 14 - * 15 - * @default true 16 - */ 17 - comments?: boolean; 18 - /** 19 - * Should the exports from the generated files be re-exported in the index barrel file? 20 - * 21 - * @default false 22 - */ 23 - exportFromIndex?: boolean; 24 - /** 25 - * Configuration for generated infinite query key helpers. 26 - * 27 - * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 28 - * 29 - * Can be: 30 - * - `boolean`: Shorthand for `{ enabled: boolean }` 31 - * - `string` or `function`: Shorthand for `{ name: string | function }` 32 - * - `object`: Full configuration object 33 - * 34 - * @default true 35 - */ 36 - infiniteQueryKeys?: 37 - | boolean 38 - | StringName 39 - | { 40 - /** 41 - * The casing convention to use for generated names. 42 - * 43 - * @default 'camelCase' 44 - */ 45 - case?: StringCase; 46 - /** 47 - * Whether to generate infinite query key helpers. 48 - * 49 - * @default true 50 - */ 51 - enabled?: boolean; 52 - /** 53 - * Custom naming pattern for generated infinite query key names. The name variable is 54 - * obtained from the SDK function name. 55 - * 56 - * @default '{{name}}InfiniteQueryKey' 57 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 58 - */ 59 - name?: StringName; 60 - /** 61 - * Whether to include operation tags in infinite query keys. 62 - * This will make query keys larger but provides better cache invalidation capabilities. 63 - * 64 - * @default false 65 - */ 66 - tags?: boolean; 67 - }; 68 - /** 69 - * Configuration for generated infinite query options helpers. 70 - * 71 - * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 72 - * 73 - * Can be: 74 - * - `boolean`: Shorthand for `{ enabled: boolean }` 75 - * - `string` or `function`: Shorthand for `{ name: string | function }` 76 - * - `object`: Full configuration object 77 - * 78 - * @default true 79 - */ 80 - infiniteQueryOptions?: 81 - | boolean 82 - | StringName 83 - | { 84 - /** 85 - * The casing convention to use for generated names. 86 - * 87 - * @default 'camelCase' 88 - */ 89 - case?: StringCase; 90 - /** 91 - * Whether to generate infinite query options helpers. 92 - * 93 - * @default true 94 - */ 95 - enabled?: boolean; 96 - /** 97 - * Custom function to generate metadata for the operation. 98 - * Can return any valid meta object that will be included in the generated infinite query options. 99 - * 100 - * @param operation - The operation object containing all available metadata 101 - * @returns A meta object with any properties you want to include 102 - * 103 - * @example 104 - * ```typescript 105 - * meta: (operation) => ({ 106 - * customField: operation.id, 107 - * isDeprecated: operation.deprecated, 108 - * tags: operation.tags, 109 - * customObject: { 110 - * method: operation.method, 111 - * path: operation.path 112 - * } 113 - * }) 114 - * ``` 115 - */ 116 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 117 - /** 118 - * Custom naming pattern for generated infinite query options names. The name variable is 119 - * obtained from the SDK function name. 120 - * 121 - * @default '{{name}}InfiniteOptions' 122 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 123 - */ 124 - name?: StringName; 125 - }; 126 - /** 127 - * Configuration for generated mutation options helpers. 128 - * 129 - * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation} 130 - * 131 - * Can be: 132 - * - `boolean`: Shorthand for `{ enabled: boolean }` 133 - * - `string` or `function`: Shorthand for `{ name: string | function }` 134 - * - `object`: Full configuration object 135 - * 136 - * @default true 137 - */ 138 - mutationOptions?: 139 - | boolean 140 - | StringName 141 - | { 142 - /** 143 - * The casing convention to use for generated names. 144 - * 145 - * @default 'camelCase' 146 - */ 147 - case?: StringCase; 148 - /** 149 - * Whether to generate mutation options helpers. 150 - * 151 - * @default true 152 - */ 153 - enabled?: boolean; 154 - /** 155 - * Custom function to generate metadata for the operation. 156 - * Can return any valid meta object that will be included in the generated mutation options. 157 - * @param operation - The operation object containing all available metadata 158 - * @returns A meta object with any properties you want to include 159 - * 160 - * @example 161 - * ```typescript 162 - * meta: (operation) => ({ 163 - * customField: operation.id, 164 - * isDeprecated: operation.deprecated, 165 - * tags: operation.tags, 166 - * customObject: { 167 - * method: operation.method, 168 - * path: operation.path 169 - * } 170 - * }) 171 - * ``` 172 - * 173 - * @default false 174 - */ 175 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 176 - /** 177 - * Custom naming pattern for generated mutation options names. The name variable is 178 - * obtained from the SDK function name. 179 - * 180 - * @default '{{name}}Mutation' 181 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 182 - */ 183 - name?: StringName; 184 - }; 185 - /** 186 - * Name of the generated file. 187 - * 188 - * @default '@tanstack/solid-query' 189 - */ 190 - output?: string; 191 - /** 192 - * Configuration for generated query keys. 193 - * 194 - * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey} 195 - * 196 - * Can be: 197 - * - `boolean`: Shorthand for `{ enabled: boolean }` 198 - * - `string` or `function`: Shorthand for `{ name: string | function }` 199 - * - `object`: Full configuration object 200 - * 201 - * @default true 202 - */ 203 - queryKeys?: 204 - | boolean 205 - | StringName 206 - | { 207 - /** 208 - * The casing convention to use for generated names. 209 - * 210 - * @default 'camelCase' 211 - */ 212 - case?: StringCase; 213 - /** 214 - * Whether to generate query keys. 215 - * 216 - * @default true 217 - */ 218 - enabled?: boolean; 219 - /** 220 - * Custom naming pattern for generated query key names. The name variable is 221 - * obtained from the SDK function name. 222 - * 223 - * @default '{{name}}QueryKey' 224 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 225 - */ 226 - name?: StringName; 227 - /** 228 - * Whether to include operation tags in query keys. 229 - * This will make query keys larger but provides better cache invalidation capabilities. 230 - * 231 - * @default false 232 - */ 233 - tags?: boolean; 234 - }; 235 - /** 236 - * Configuration for generated query options helpers. 237 - * 238 - * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery} 239 - * 240 - * Can be: 241 - * - `boolean`: Shorthand for `{ enabled: boolean }` 242 - * - `string` or `function`: Shorthand for `{ name: string | function }` 243 - * - `object`: Full configuration object 244 - * 245 - * @default true 246 - */ 247 - queryOptions?: 248 - | boolean 249 - | StringName 250 - | { 251 - /** 252 - * The casing convention to use for generated names. 253 - * 254 - * @default 'camelCase' 255 - */ 256 - case?: StringCase; 257 - /** 258 - * Whether to generate query options helpers. 259 - * 260 - * @default true 261 - */ 262 - enabled?: boolean; 263 - /** 264 - * Custom function to generate metadata for the operation. 265 - * Can return any valid meta object that will be included in the generated query options. 266 - * @param operation - The operation object containing all available metadata 267 - * @returns A meta object with any properties you want to include 268 - * 269 - * @example 270 - * ```typescript 271 - * meta: (operation) => ({ 272 - * customField: operation.id, 273 - * isDeprecated: operation.deprecated, 274 - * tags: operation.tags, 275 - * customObject: { 276 - * method: operation.method, 277 - * path: operation.path 278 - * } 279 - * }) 280 - * ``` 281 - * 282 - * @default false 283 - */ 284 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 285 - /** 286 - * Custom naming pattern for generated query options names. The name variable is 287 - * obtained from the SDK function name. 288 - * 289 - * @default '{{name}}Options' 290 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 291 - */ 292 - name?: StringName; 293 - }; 294 - }; 295 - 296 - export type Config = Plugin.Name<'@tanstack/solid-query'> & { 297 - /** 298 - * The casing convention to use for generated names. 299 - * 300 - * @default 'camelCase' 301 - */ 302 - case: StringCase; 303 - /** 304 - * Add comments from SDK functions to the generated TanStack Query code? 305 - * 306 - * @default true 307 - */ 308 - comments: boolean; 309 - /** 310 - * Should the exports from the generated files be re-exported in the index barrel file? 311 - * 312 - * @default false 313 - */ 314 - exportFromIndex: boolean; 315 - /** 316 - * Resolved configuration for generated infinite query key helpers. 317 - * 318 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 319 - */ 320 - infiniteQueryKeys: { 5 + export type UserConfig = Plugin.Name<'@tanstack/solid-query'> & 6 + Plugin.Hooks & { 321 7 /** 322 8 * The casing convention to use for generated names. 323 9 * 324 10 * @default 'camelCase' 325 11 */ 326 - case: StringCase; 12 + case?: StringCase; 327 13 /** 328 - * Whether to generate infinite query key helpers. 14 + * Add comments from SDK functions to the generated TanStack Query code? 329 15 * 330 16 * @default true 331 17 */ 332 - enabled: boolean; 18 + comments?: boolean; 333 19 /** 334 - * Custom naming pattern for generated infinite query key names. The name variable is 335 - * obtained from the SDK function name. 336 - * 337 - * @default '{{name}}InfiniteQueryKey' 338 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 339 - */ 340 - name: StringName; 341 - /** 342 - * Whether to include operation tags in infinite query keys. 343 - * This will make query keys larger but provides better cache invalidation capabilities. 20 + * Should the exports from the generated files be re-exported in the index barrel file? 344 21 * 345 22 * @default false 346 23 */ 347 - tags: boolean; 348 - }; 349 - /** 350 - * Resolved configuration for generated infinite query options helpers. 351 - * 352 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 353 - */ 354 - infiniteQueryOptions: { 24 + exportFromIndex?: boolean; 355 25 /** 356 - * The casing convention to use for generated names. 26 + * Configuration for generated infinite query key helpers. 357 27 * 358 - * @default 'camelCase' 359 - */ 360 - case: StringCase; 361 - /** 362 - * Whether to generate infinite query options helpers. 28 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 29 + * 30 + * Can be: 31 + * - `boolean`: Shorthand for `{ enabled: boolean }` 32 + * - `string` or `function`: Shorthand for `{ name: string | function }` 33 + * - `object`: Full configuration object 363 34 * 364 35 * @default true 365 36 */ 366 - enabled: boolean; 37 + infiniteQueryKeys?: 38 + | boolean 39 + | StringName 40 + | { 41 + /** 42 + * The casing convention to use for generated names. 43 + * 44 + * @default 'camelCase' 45 + */ 46 + case?: StringCase; 47 + /** 48 + * Whether to generate infinite query key helpers. 49 + * 50 + * @default true 51 + */ 52 + enabled?: boolean; 53 + /** 54 + * Custom naming pattern for generated infinite query key names. The name variable is 55 + * obtained from the SDK function name. 56 + * 57 + * @default '{{name}}InfiniteQueryKey' 58 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 59 + */ 60 + name?: StringName; 61 + /** 62 + * Whether to include operation tags in infinite query keys. 63 + * This will make query keys larger but provides better cache invalidation capabilities. 64 + * 65 + * @default false 66 + */ 67 + tags?: boolean; 68 + }; 367 69 /** 368 - * Custom function to generate metadata for the operation. 369 - * Can return any valid meta object that will be included in the generated infinite query options. 370 - * @param operation - The operation object containing all available metadata 371 - * @returns A meta object with any properties you want to include 70 + * Configuration for generated infinite query options helpers. 372 71 * 373 - * @example 374 - * ```typescript 375 - * meta: (operation) => ({ 376 - * customField: operation.id, 377 - * isDeprecated: operation.deprecated, 378 - * tags: operation.tags, 379 - * customObject: { 380 - * method: operation.method, 381 - * path: operation.path 382 - * } 383 - * }) 384 - * ``` 72 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 385 73 * 386 - * @default false 74 + * Can be: 75 + * - `boolean`: Shorthand for `{ enabled: boolean }` 76 + * - `string` or `function`: Shorthand for `{ name: string | function }` 77 + * - `object`: Full configuration object 78 + * 79 + * @default true 387 80 */ 388 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 81 + infiniteQueryOptions?: 82 + | boolean 83 + | StringName 84 + | { 85 + /** 86 + * The casing convention to use for generated names. 87 + * 88 + * @default 'camelCase' 89 + */ 90 + case?: StringCase; 91 + /** 92 + * Whether to generate infinite query options helpers. 93 + * 94 + * @default true 95 + */ 96 + enabled?: boolean; 97 + /** 98 + * Custom function to generate metadata for the operation. 99 + * Can return any valid meta object that will be included in the generated infinite query options. 100 + * 101 + * @param operation - The operation object containing all available metadata 102 + * @returns A meta object with any properties you want to include 103 + * 104 + * @example 105 + * ```typescript 106 + * meta: (operation) => ({ 107 + * customField: operation.id, 108 + * isDeprecated: operation.deprecated, 109 + * tags: operation.tags, 110 + * customObject: { 111 + * method: operation.method, 112 + * path: operation.path 113 + * } 114 + * }) 115 + * ``` 116 + * 117 + * @default undefined 118 + */ 119 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 120 + /** 121 + * Custom naming pattern for generated infinite query options names. The name variable is 122 + * obtained from the SDK function name. 123 + * 124 + * @default '{{name}}InfiniteOptions' 125 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 126 + */ 127 + name?: StringName; 128 + }; 389 129 /** 390 - * Custom naming pattern for generated infinite query options names. The name variable is 391 - * obtained from the SDK function name. 130 + * Configuration for generated mutation options helpers. 131 + * 132 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation} 133 + * 134 + * Can be: 135 + * - `boolean`: Shorthand for `{ enabled: boolean }` 136 + * - `string` or `function`: Shorthand for `{ name: string | function }` 137 + * - `object`: Full configuration object 392 138 * 393 - * @default '{{name}}InfiniteOptions' 394 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 139 + * @default true 395 140 */ 396 - name: StringName; 397 - }; 398 - /** 399 - * Resolved configuration for generated mutation options helpers. 400 - * 401 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 402 - */ 403 - mutationOptions: { 141 + mutationOptions?: 142 + | boolean 143 + | StringName 144 + | { 145 + /** 146 + * The casing convention to use for generated names. 147 + * 148 + * @default 'camelCase' 149 + */ 150 + case?: StringCase; 151 + /** 152 + * Whether to generate mutation options helpers. 153 + * 154 + * @default true 155 + */ 156 + enabled?: boolean; 157 + /** 158 + * Custom function to generate metadata for the operation. 159 + * Can return any valid meta object that will be included in the generated mutation options. 160 + * @param operation - The operation object containing all available metadata 161 + * @returns A meta object with any properties you want to include 162 + * 163 + * @example 164 + * ```typescript 165 + * meta: (operation) => ({ 166 + * customField: operation.id, 167 + * isDeprecated: operation.deprecated, 168 + * tags: operation.tags, 169 + * customObject: { 170 + * method: operation.method, 171 + * path: operation.path 172 + * } 173 + * }) 174 + * ``` 175 + * 176 + * @default undefined 177 + */ 178 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 179 + /** 180 + * Custom naming pattern for generated mutation options names. The name variable is 181 + * obtained from the SDK function name. 182 + * 183 + * @default '{{name}}Mutation' 184 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 185 + */ 186 + name?: StringName; 187 + }; 404 188 /** 405 - * The casing convention to use for generated names. 189 + * Name of the generated file. 406 190 * 407 - * @default 'camelCase' 191 + * @default '@tanstack/solid-query' 408 192 */ 409 - case: StringCase; 193 + output?: string; 410 194 /** 411 - * Whether to generate mutation options helpers. 195 + * Configuration for generated query keys. 196 + * 197 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey} 198 + * 199 + * Can be: 200 + * - `boolean`: Shorthand for `{ enabled: boolean }` 201 + * - `string` or `function`: Shorthand for `{ name: string | function }` 202 + * - `object`: Full configuration object 412 203 * 413 204 * @default true 414 205 */ 415 - enabled: boolean; 206 + queryKeys?: 207 + | boolean 208 + | StringName 209 + | { 210 + /** 211 + * The casing convention to use for generated names. 212 + * 213 + * @default 'camelCase' 214 + */ 215 + case?: StringCase; 216 + /** 217 + * Whether to generate query keys. 218 + * 219 + * @default true 220 + */ 221 + enabled?: boolean; 222 + /** 223 + * Custom naming pattern for generated query key names. The name variable is 224 + * obtained from the SDK function name. 225 + * 226 + * @default '{{name}}QueryKey' 227 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 228 + */ 229 + name?: StringName; 230 + /** 231 + * Whether to include operation tags in query keys. 232 + * This will make query keys larger but provides better cache invalidation capabilities. 233 + * 234 + * @default false 235 + */ 236 + tags?: boolean; 237 + }; 416 238 /** 417 - * Custom function to generate metadata for the operation. 418 - * Can return any valid meta object that will be included in the generated mutation options. 419 - * @param operation - The operation object containing all available metadata 420 - * @returns A meta object with any properties you want to include 239 + * Configuration for generated query options helpers. 421 240 * 422 - * @example 423 - * ```typescript 424 - * meta: (operation) => ({ 425 - * customField: operation.id, 426 - * isDeprecated: operation.deprecated, 427 - * tags: operation.tags, 428 - * customObject: { 429 - * method: operation.method, 430 - * path: operation.path 431 - * } 432 - * }) 433 - * ``` 241 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery} 434 242 * 435 - * @default false 436 - */ 437 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 438 - /** 439 - * Custom naming pattern for generated mutation options names. The name variable is 440 - * obtained from the SDK function name. 243 + * Can be: 244 + * - `boolean`: Shorthand for `{ enabled: boolean }` 245 + * - `string` or `function`: Shorthand for `{ name: string | function }` 246 + * - `object`: Full configuration object 441 247 * 442 - * @default '{{name}}Mutation' 443 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 248 + * @default true 444 249 */ 445 - name: StringName; 250 + queryOptions?: 251 + | boolean 252 + | StringName 253 + | { 254 + /** 255 + * The casing convention to use for generated names. 256 + * 257 + * @default 'camelCase' 258 + */ 259 + case?: StringCase; 260 + /** 261 + * Whether to generate query options helpers. 262 + * 263 + * @default true 264 + */ 265 + enabled?: boolean; 266 + /** 267 + * Custom function to generate metadata for the operation. 268 + * Can return any valid meta object that will be included in the generated query options. 269 + * @param operation - The operation object containing all available metadata 270 + * @returns A meta object with any properties you want to include 271 + * 272 + * @example 273 + * ```typescript 274 + * meta: (operation) => ({ 275 + * customField: operation.id, 276 + * isDeprecated: operation.deprecated, 277 + * tags: operation.tags, 278 + * customObject: { 279 + * method: operation.method, 280 + * path: operation.path 281 + * } 282 + * }) 283 + * ``` 284 + * 285 + * @default undefined 286 + */ 287 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 288 + /** 289 + * Custom naming pattern for generated query options names. The name variable is 290 + * obtained from the SDK function name. 291 + * 292 + * @default '{{name}}Options' 293 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 294 + */ 295 + name?: StringName; 296 + }; 446 297 }; 447 - /** 448 - * Name of the generated file. 449 - * 450 - * @default '@tanstack/solid-query' 451 - */ 452 - output: string; 453 - /** 454 - * Resolved configuration for generated query keys. 455 - * 456 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 457 - */ 458 - queryKeys: { 298 + 299 + export type Config = Plugin.Name<'@tanstack/solid-query'> & 300 + Plugin.Hooks & { 459 301 /** 460 302 * The casing convention to use for generated names. 461 303 * ··· 463 305 */ 464 306 case: StringCase; 465 307 /** 466 - * Whether to generate query keys. 308 + * Add comments from SDK functions to the generated TanStack Query code? 467 309 * 468 310 * @default true 469 311 */ 470 - enabled: boolean; 312 + comments: boolean; 471 313 /** 472 - * Custom naming pattern for generated query key names. The name variable is 473 - * obtained from the SDK function name. 314 + * Should the exports from the generated files be re-exported in the index barrel file? 474 315 * 475 - * @default '{{name}}QueryKey' 476 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 316 + * @default false 477 317 */ 478 - name: StringName; 318 + exportFromIndex: boolean; 479 319 /** 480 - * Whether to include operation tags in query keys. 481 - * This will make query keys larger but provides better cache invalidation capabilities. 320 + * Resolved configuration for generated infinite query key helpers. 482 321 * 483 - * @default false 322 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 484 323 */ 485 - tags: boolean; 486 - }; 487 - /** 488 - * Resolved configuration for generated query options helpers. 489 - * 490 - * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 491 - */ 492 - queryOptions: { 324 + infiniteQueryKeys: { 325 + /** 326 + * The casing convention to use for generated names. 327 + * 328 + * @default 'camelCase' 329 + */ 330 + case: StringCase; 331 + /** 332 + * Whether to generate infinite query key helpers. 333 + * 334 + * @default true 335 + */ 336 + enabled: boolean; 337 + /** 338 + * Custom naming pattern for generated infinite query key names. The name variable is 339 + * obtained from the SDK function name. 340 + * 341 + * @default '{{name}}InfiniteQueryKey' 342 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 343 + */ 344 + name: StringName; 345 + /** 346 + * Whether to include operation tags in infinite query keys. 347 + * This will make query keys larger but provides better cache invalidation capabilities. 348 + * 349 + * @default false 350 + */ 351 + tags: boolean; 352 + }; 493 353 /** 494 - * The casing convention to use for generated names. 354 + * Resolved configuration for generated infinite query options helpers. 495 355 * 496 - * @default 'camelCase' 356 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 497 357 */ 498 - case: StringCase; 358 + infiniteQueryOptions: { 359 + /** 360 + * The casing convention to use for generated names. 361 + * 362 + * @default 'camelCase' 363 + */ 364 + case: StringCase; 365 + /** 366 + * Whether to generate infinite query options helpers. 367 + * 368 + * @default true 369 + */ 370 + enabled: boolean; 371 + /** 372 + * Custom function to generate metadata for the operation. 373 + * Can return any valid meta object that will be included in the generated infinite query options. 374 + * @param operation - The operation object containing all available metadata 375 + * @returns A meta object with any properties you want to include 376 + * 377 + * @example 378 + * ```typescript 379 + * meta: (operation) => ({ 380 + * customField: operation.id, 381 + * isDeprecated: operation.deprecated, 382 + * tags: operation.tags, 383 + * customObject: { 384 + * method: operation.method, 385 + * path: operation.path 386 + * } 387 + * }) 388 + * ``` 389 + * 390 + * @default undefined 391 + */ 392 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 393 + /** 394 + * Custom naming pattern for generated infinite query options names. The name variable is 395 + * obtained from the SDK function name. 396 + * 397 + * @default '{{name}}InfiniteOptions' 398 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 399 + */ 400 + name: StringName; 401 + }; 499 402 /** 500 - * Whether to generate query options helpers. 403 + * Resolved configuration for generated mutation options helpers. 501 404 * 502 - * @default true 405 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 503 406 */ 504 - enabled: boolean; 407 + mutationOptions: { 408 + /** 409 + * The casing convention to use for generated names. 410 + * 411 + * @default 'camelCase' 412 + */ 413 + case: StringCase; 414 + /** 415 + * Whether to generate mutation options helpers. 416 + * 417 + * @default true 418 + */ 419 + enabled: boolean; 420 + /** 421 + * Custom function to generate metadata for the operation. 422 + * Can return any valid meta object that will be included in the generated mutation options. 423 + * @param operation - The operation object containing all available metadata 424 + * @returns A meta object with any properties you want to include 425 + * 426 + * @example 427 + * ```typescript 428 + * meta: (operation) => ({ 429 + * customField: operation.id, 430 + * isDeprecated: operation.deprecated, 431 + * tags: operation.tags, 432 + * customObject: { 433 + * method: operation.method, 434 + * path: operation.path 435 + * } 436 + * }) 437 + * ``` 438 + * 439 + * @default undefined 440 + */ 441 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 442 + /** 443 + * Custom naming pattern for generated mutation options names. The name variable is 444 + * obtained from the SDK function name. 445 + * 446 + * @default '{{name}}Mutation' 447 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 448 + */ 449 + name: StringName; 450 + }; 505 451 /** 506 - * Custom function to generate metadata for the operation. 507 - * Can return any valid meta object that will be included in the generated query options. 508 - * @param operation - The operation object containing all available metadata 509 - * @returns A meta object with any properties you want to include 452 + * Name of the generated file. 510 453 * 511 - * @example 512 - * ```typescript 513 - * meta: (operation) => ({ 514 - * customField: operation.id, 515 - * isDeprecated: operation.deprecated, 516 - * tags: operation.tags, 517 - * customObject: { 518 - * method: operation.method, 519 - * path: operation.path 520 - * } 521 - * }) 522 - * ``` 454 + * @default '@tanstack/solid-query' 455 + */ 456 + output: string; 457 + /** 458 + * Resolved configuration for generated query keys. 523 459 * 524 - * @default false 460 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 525 461 */ 526 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 462 + queryKeys: { 463 + /** 464 + * The casing convention to use for generated names. 465 + * 466 + * @default 'camelCase' 467 + */ 468 + case: StringCase; 469 + /** 470 + * Whether to generate query keys. 471 + * 472 + * @default true 473 + */ 474 + enabled: boolean; 475 + /** 476 + * Custom naming pattern for generated query key names. The name variable is 477 + * obtained from the SDK function name. 478 + * 479 + * @default '{{name}}QueryKey' 480 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 481 + */ 482 + name: StringName; 483 + /** 484 + * Whether to include operation tags in query keys. 485 + * This will make query keys larger but provides better cache invalidation capabilities. 486 + * 487 + * @default false 488 + */ 489 + tags: boolean; 490 + }; 527 491 /** 528 - * Custom naming pattern for generated query options names. The name variable is 529 - * obtained from the SDK function name. 492 + * Resolved configuration for generated query options helpers. 530 493 * 531 - * @default '{{name}}Options' 532 494 * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 533 495 */ 534 - name: StringName; 496 + queryOptions: { 497 + /** 498 + * The casing convention to use for generated names. 499 + * 500 + * @default 'camelCase' 501 + */ 502 + case: StringCase; 503 + /** 504 + * Whether to generate query options helpers. 505 + * 506 + * @default true 507 + */ 508 + enabled: boolean; 509 + /** 510 + * Custom function to generate metadata for the operation. 511 + * Can return any valid meta object that will be included in the generated query options. 512 + * @param operation - The operation object containing all available metadata 513 + * @returns A meta object with any properties you want to include 514 + * 515 + * @example 516 + * ```typescript 517 + * meta: (operation) => ({ 518 + * customField: operation.id, 519 + * isDeprecated: operation.deprecated, 520 + * tags: operation.tags, 521 + * customObject: { 522 + * method: operation.method, 523 + * path: operation.path 524 + * } 525 + * }) 526 + * ``` 527 + * 528 + * @default undefined 529 + */ 530 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 531 + /** 532 + * Custom naming pattern for generated query options names. The name variable is 533 + * obtained from the SDK function name. 534 + * 535 + * @default '{{name}}Options' 536 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 537 + */ 538 + name: StringName; 539 + }; 535 540 }; 536 - }; 537 541 538 542 export type TanStackSolidQueryPlugin = DefinePlugin<UserConfig, Config>;
-3
packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts
··· 34 34 defaultValue: { 35 35 case: plugin.config.case ?? 'camelCase', 36 36 enabled: true, 37 - meta: false, 38 37 name: '{{name}}InfiniteOptions', 39 38 }, 40 39 mappers: { ··· 49 48 defaultValue: { 50 49 case: plugin.config.case ?? 'camelCase', 51 50 enabled: true, 52 - meta: false, 53 51 name: '{{name}}Mutation', 54 52 }, 55 53 mappers: { ··· 79 77 defaultValue: { 80 78 case: plugin.config.case ?? 'camelCase', 81 79 enabled: true, 82 - meta: false, 83 80 name: '{{name}}Options', 84 81 }, 85 82 mappers: {
+466 -464
packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.d.ts
··· 2 2 import type { StringCase, StringName } from '../../../types/case'; 3 3 import type { DefinePlugin, Plugin } from '../../types'; 4 4 5 - export type UserConfig = Plugin.Name<'@tanstack/svelte-query'> & { 6 - /** 7 - * The casing convention to use for generated names. 8 - * 9 - * @default 'camelCase' 10 - */ 11 - case?: StringCase; 12 - /** 13 - * Add comments from SDK functions to the generated TanStack Query code? 14 - * 15 - * @default true 16 - */ 17 - comments?: boolean; 18 - /** 19 - * Should the exports from the generated files be re-exported in the index barrel file? 20 - * 21 - * @default false 22 - */ 23 - exportFromIndex?: boolean; 24 - /** 25 - * Configuration for generated infinite query key helpers. 26 - * 27 - * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery} 28 - * 29 - * Can be: 30 - * - `boolean`: Shorthand for `{ enabled: boolean }` 31 - * - `string` or `function`: Shorthand for `{ name: string | function }` 32 - * - `object`: Full configuration object 33 - * 34 - * @default true 35 - */ 36 - infiniteQueryKeys?: 37 - | boolean 38 - | StringName 39 - | { 40 - /** 41 - * The casing convention to use for generated names. 42 - * 43 - * @default 'camelCase' 44 - */ 45 - case?: StringCase; 46 - /** 47 - * Whether to generate infinite query key helpers. 48 - * 49 - * @default true 50 - */ 51 - enabled?: boolean; 52 - /** 53 - * Custom naming pattern for generated infinite query key names. The name variable is 54 - * obtained from the SDK function name. 55 - * 56 - * @default '{{name}}InfiniteQueryKey' 57 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 58 - */ 59 - name?: StringName; 60 - /** 61 - * Whether to include operation tags in infinite query keys. 62 - * This will make query keys larger but provides better cache invalidation capabilities. 63 - * 64 - * @default false 65 - */ 66 - tags?: boolean; 67 - }; 68 - /** 69 - * Configuration for generated infinite query options helpers. 70 - * 71 - * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery} 72 - * 73 - * Can be: 74 - * - `boolean`: Shorthand for `{ enabled: boolean }` 75 - * - `string` or `function`: Shorthand for `{ name: string | function }` 76 - * - `object`: Full configuration object 77 - * 78 - * @default true 79 - */ 80 - infiniteQueryOptions?: 81 - | boolean 82 - | StringName 83 - | { 84 - /** 85 - * The casing convention to use for generated names. 86 - * 87 - * @default 'camelCase' 88 - */ 89 - case?: StringCase; 90 - /** 91 - * Whether to generate infinite query options helpers. 92 - * 93 - * @default true 94 - */ 95 - enabled?: boolean; 96 - /** 97 - * Custom function to generate metadata for the operation. 98 - * Can return any valid meta object that will be included in the generated infinite query options. 99 - * @param operation - The operation object containing all available metadata 100 - * @returns A meta object with any properties you want to include 101 - * 102 - * @example 103 - * ```typescript 104 - * meta: (operation) => ({ 105 - * customField: operation.id, 106 - * isDeprecated: operation.deprecated, 107 - * tags: operation.tags, 108 - * customObject: { 109 - * method: operation.method, 110 - * path: operation.path 111 - * } 112 - * }) 113 - * ``` 114 - * 115 - * @default false 116 - */ 117 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 118 - /** 119 - * Custom naming pattern for generated infinite query options names. The name variable is 120 - * obtained from the SDK function name. 121 - * 122 - * @default '{{name}}InfiniteOptions' 123 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 124 - */ 125 - name?: StringName; 126 - }; 127 - /** 128 - * Configuration for generated mutation options helpers. 129 - * 130 - * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation} 131 - * 132 - * Can be: 133 - * - `boolean`: Shorthand for `{ enabled: boolean }` 134 - * - `string` or `function`: Shorthand for `{ name: string | function }` 135 - * - `object`: Full configuration object 136 - * 137 - * @default true 138 - */ 139 - mutationOptions?: 140 - | boolean 141 - | StringName 142 - | { 143 - /** 144 - * The casing convention to use for generated names. 145 - * 146 - * @default 'camelCase' 147 - */ 148 - case?: StringCase; 149 - /** 150 - * Whether to generate mutation options helpers. 151 - * 152 - * @default true 153 - */ 154 - enabled?: boolean; 155 - /** 156 - * Custom function to generate metadata for the operation. 157 - * Can return any valid meta object that will be included in the generated mutation options. 158 - * @param operation - The operation object containing all available metadata 159 - * @returns A meta object with any properties you want to include 160 - * 161 - * @example 162 - * ```typescript 163 - * meta: (operation) => ({ 164 - * customField: operation.id, 165 - * isDeprecated: operation.deprecated, 166 - * tags: operation.tags, 167 - * customObject: { 168 - * method: operation.method, 169 - * path: operation.path 170 - * } 171 - * }) 172 - * ``` 173 - * 174 - * @default false 175 - */ 176 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 177 - /** 178 - * Custom naming pattern for generated mutation options names. The name variable is 179 - * obtained from the SDK function name. 180 - * 181 - * @default '{{name}}Mutation' 182 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation 183 - */ 184 - name?: StringName; 185 - }; 186 - /** 187 - * Name of the generated file. 188 - * 189 - * @default '@tanstack/svelte-query' 190 - */ 191 - output?: string; 192 - /** 193 - * Configuration for generated query keys. 194 - * 195 - * See {@link https://tanstack.com/query/v5/docs/framework/react/guides/query-keys} 196 - * 197 - * Can be: 198 - * - `boolean`: Shorthand for `{ enabled: boolean }` 199 - * - `string` or `function`: Shorthand for `{ name: string | function }` 200 - * - `object`: Full configuration object 201 - * 202 - * @default true 203 - */ 204 - queryKeys?: 205 - | boolean 206 - | StringName 207 - | { 208 - /** 209 - * The casing convention to use for generated names. 210 - * 211 - * @default 'camelCase' 212 - */ 213 - case?: StringCase; 214 - /** 215 - * Whether to generate query keys. 216 - * 217 - * @default true 218 - */ 219 - enabled?: boolean; 220 - /** 221 - * Custom naming pattern for generated query key names. The name variable is 222 - * obtained from the SDK function name. 223 - * 224 - * @default '{{name}}QueryKey' 225 - * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-keys 226 - */ 227 - name?: StringName; 228 - /** 229 - * Whether to include operation tags in query keys. 230 - * This will make query keys larger but provides better cache invalidation capabilities. 231 - * 232 - * @default false 233 - */ 234 - tags?: boolean; 235 - }; 236 - /** 237 - * Configuration for generated query options helpers. 238 - * 239 - * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery} 240 - * 241 - * Can be: 242 - * - `boolean`: Shorthand for `{ enabled: boolean }` 243 - * - `string` or `function`: Shorthand for `{ name: string | function }` 244 - * - `object`: Full configuration object 245 - * 246 - * @default true 247 - */ 248 - queryOptions?: 249 - | boolean 250 - | StringName 251 - | { 252 - /** 253 - * The casing convention to use for generated names. 254 - * 255 - * @default 'camelCase' 256 - */ 257 - case?: StringCase; 258 - /** 259 - * Whether to generate query options helpers. 260 - * 261 - * @default true 262 - */ 263 - enabled?: boolean; 264 - /** 265 - * Custom function to generate metadata for the operation. 266 - * Can return any valid meta object that will be included in the generated query options. 267 - * @param operation - The operation object containing all available metadata 268 - * @returns A meta object with any properties you want to include 269 - * 270 - * @example 271 - * ```typescript 272 - * meta: (operation) => ({ 273 - * customField: operation.id, 274 - * isDeprecated: operation.deprecated, 275 - * tags: operation.tags, 276 - * customObject: { 277 - * method: operation.method, 278 - * path: operation.path 279 - * } 280 - * }) 281 - * ``` 282 - * 283 - * @default false 284 - */ 285 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 286 - /** 287 - * Custom naming pattern for generated query options names. The name variable is 288 - * obtained from the SDK function name. 289 - * 290 - * @default '{{name}}Options' 291 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery 292 - */ 293 - name?: StringName; 294 - }; 295 - }; 296 - 297 - export type Config = Plugin.Name<'@tanstack/svelte-query'> & { 298 - /** 299 - * The casing convention to use for generated names. 300 - * 301 - * @default 'camelCase' 302 - */ 303 - case: StringCase; 304 - /** 305 - * Add comments from SDK functions to the generated TanStack Query code? 306 - * 307 - * @default true 308 - */ 309 - comments: boolean; 310 - /** 311 - * Should the exports from the generated files be re-exported in the index barrel file? 312 - * 313 - * @default false 314 - */ 315 - exportFromIndex: boolean; 316 - /** 317 - * Resolved configuration for generated infinite query key helpers. 318 - * 319 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 320 - */ 321 - infiniteQueryKeys: { 5 + export type UserConfig = Plugin.Name<'@tanstack/svelte-query'> & 6 + Plugin.Hooks & { 322 7 /** 323 8 * The casing convention to use for generated names. 324 9 * 325 10 * @default 'camelCase' 326 11 */ 327 - case: StringCase; 12 + case?: StringCase; 328 13 /** 329 - * Whether to generate infinite query key helpers. 14 + * Add comments from SDK functions to the generated TanStack Query code? 330 15 * 331 16 * @default true 332 17 */ 333 - enabled: boolean; 18 + comments?: boolean; 334 19 /** 335 - * Custom naming pattern for generated infinite query key names. The name variable is 336 - * obtained from the SDK function name. 337 - * 338 - * @default '{{name}}InfiniteQueryKey' 339 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 340 - */ 341 - name: StringName; 342 - /** 343 - * Whether to include operation tags in infinite query keys. 344 - * This will make query keys larger but provides better cache invalidation capabilities. 20 + * Should the exports from the generated files be re-exported in the index barrel file? 345 21 * 346 22 * @default false 347 23 */ 348 - tags: boolean; 349 - }; 350 - /** 351 - * Resolved configuration for generated infinite query options helpers. 352 - * 353 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 354 - */ 355 - infiniteQueryOptions: { 24 + exportFromIndex?: boolean; 356 25 /** 357 - * The casing convention to use for generated names. 26 + * Configuration for generated infinite query key helpers. 358 27 * 359 - * @default 'camelCase' 360 - */ 361 - case: StringCase; 362 - /** 363 - * Whether to generate infinite query options helpers. 28 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery} 29 + * 30 + * Can be: 31 + * - `boolean`: Shorthand for `{ enabled: boolean }` 32 + * - `string` or `function`: Shorthand for `{ name: string | function }` 33 + * - `object`: Full configuration object 364 34 * 365 35 * @default true 366 36 */ 367 - enabled: boolean; 37 + infiniteQueryKeys?: 38 + | boolean 39 + | StringName 40 + | { 41 + /** 42 + * The casing convention to use for generated names. 43 + * 44 + * @default 'camelCase' 45 + */ 46 + case?: StringCase; 47 + /** 48 + * Whether to generate infinite query key helpers. 49 + * 50 + * @default true 51 + */ 52 + enabled?: boolean; 53 + /** 54 + * Custom naming pattern for generated infinite query key names. The name variable is 55 + * obtained from the SDK function name. 56 + * 57 + * @default '{{name}}InfiniteQueryKey' 58 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 59 + */ 60 + name?: StringName; 61 + /** 62 + * Whether to include operation tags in infinite query keys. 63 + * This will make query keys larger but provides better cache invalidation capabilities. 64 + * 65 + * @default false 66 + */ 67 + tags?: boolean; 68 + }; 368 69 /** 369 - * Custom function to generate metadata for the operation. 370 - * Can return any valid meta object that will be included in the generated infinite query options. 371 - * @param operation - The operation object containing all available metadata 372 - * @returns A meta object with any properties you want to include 70 + * Configuration for generated infinite query options helpers. 373 71 * 374 - * @example 375 - * ```typescript 376 - * meta: (operation) => ({ 377 - * customField: operation.id, 378 - * isDeprecated: operation.deprecated, 379 - * tags: operation.tags, 380 - * customObject: { 381 - * method: operation.method, 382 - * path: operation.path 383 - * } 384 - * }) 385 - * ``` 72 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery} 386 73 * 387 - * @default false 74 + * Can be: 75 + * - `boolean`: Shorthand for `{ enabled: boolean }` 76 + * - `string` or `function`: Shorthand for `{ name: string | function }` 77 + * - `object`: Full configuration object 78 + * 79 + * @default true 388 80 */ 389 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 81 + infiniteQueryOptions?: 82 + | boolean 83 + | StringName 84 + | { 85 + /** 86 + * The casing convention to use for generated names. 87 + * 88 + * @default 'camelCase' 89 + */ 90 + case?: StringCase; 91 + /** 92 + * Whether to generate infinite query options helpers. 93 + * 94 + * @default true 95 + */ 96 + enabled?: boolean; 97 + /** 98 + * Custom function to generate metadata for the operation. 99 + * Can return any valid meta object that will be included in the generated infinite query options. 100 + * @param operation - The operation object containing all available metadata 101 + * @returns A meta object with any properties you want to include 102 + * 103 + * @example 104 + * ```typescript 105 + * meta: (operation) => ({ 106 + * customField: operation.id, 107 + * isDeprecated: operation.deprecated, 108 + * tags: operation.tags, 109 + * customObject: { 110 + * method: operation.method, 111 + * path: operation.path 112 + * } 113 + * }) 114 + * ``` 115 + * 116 + * @default undefined 117 + */ 118 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 119 + /** 120 + * Custom naming pattern for generated infinite query options names. The name variable is 121 + * obtained from the SDK function name. 122 + * 123 + * @default '{{name}}InfiniteOptions' 124 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 125 + */ 126 + name?: StringName; 127 + }; 390 128 /** 391 - * Custom naming pattern for generated infinite query options names. The name variable is 392 - * obtained from the SDK function name. 129 + * Configuration for generated mutation options helpers. 130 + * 131 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation} 132 + * 133 + * Can be: 134 + * - `boolean`: Shorthand for `{ enabled: boolean }` 135 + * - `string` or `function`: Shorthand for `{ name: string | function }` 136 + * - `object`: Full configuration object 393 137 * 394 - * @default '{{name}}InfiniteOptions' 395 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 138 + * @default true 396 139 */ 397 - name: StringName; 398 - }; 399 - /** 400 - * Resolved configuration for generated mutation options helpers. 401 - * 402 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation 403 - */ 404 - mutationOptions: { 140 + mutationOptions?: 141 + | boolean 142 + | StringName 143 + | { 144 + /** 145 + * The casing convention to use for generated names. 146 + * 147 + * @default 'camelCase' 148 + */ 149 + case?: StringCase; 150 + /** 151 + * Whether to generate mutation options helpers. 152 + * 153 + * @default true 154 + */ 155 + enabled?: boolean; 156 + /** 157 + * Custom function to generate metadata for the operation. 158 + * Can return any valid meta object that will be included in the generated mutation options. 159 + * @param operation - The operation object containing all available metadata 160 + * @returns A meta object with any properties you want to include 161 + * 162 + * @example 163 + * ```typescript 164 + * meta: (operation) => ({ 165 + * customField: operation.id, 166 + * isDeprecated: operation.deprecated, 167 + * tags: operation.tags, 168 + * customObject: { 169 + * method: operation.method, 170 + * path: operation.path 171 + * } 172 + * }) 173 + * ``` 174 + * 175 + * @default undefined 176 + */ 177 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 178 + /** 179 + * Custom naming pattern for generated mutation options names. The name variable is 180 + * obtained from the SDK function name. 181 + * 182 + * @default '{{name}}Mutation' 183 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation 184 + */ 185 + name?: StringName; 186 + }; 405 187 /** 406 - * The casing convention to use for generated names. 188 + * Name of the generated file. 407 189 * 408 - * @default 'camelCase' 190 + * @default '@tanstack/svelte-query' 409 191 */ 410 - case: StringCase; 192 + output?: string; 411 193 /** 412 - * Whether to generate mutation options helpers. 194 + * Configuration for generated query keys. 195 + * 196 + * See {@link https://tanstack.com/query/v5/docs/framework/react/guides/query-keys} 197 + * 198 + * Can be: 199 + * - `boolean`: Shorthand for `{ enabled: boolean }` 200 + * - `string` or `function`: Shorthand for `{ name: string | function }` 201 + * - `object`: Full configuration object 413 202 * 414 203 * @default true 415 204 */ 416 - enabled: boolean; 205 + queryKeys?: 206 + | boolean 207 + | StringName 208 + | { 209 + /** 210 + * The casing convention to use for generated names. 211 + * 212 + * @default 'camelCase' 213 + */ 214 + case?: StringCase; 215 + /** 216 + * Whether to generate query keys. 217 + * 218 + * @default true 219 + */ 220 + enabled?: boolean; 221 + /** 222 + * Custom naming pattern for generated query key names. The name variable is 223 + * obtained from the SDK function name. 224 + * 225 + * @default '{{name}}QueryKey' 226 + * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-keys 227 + */ 228 + name?: StringName; 229 + /** 230 + * Whether to include operation tags in query keys. 231 + * This will make query keys larger but provides better cache invalidation capabilities. 232 + * 233 + * @default false 234 + */ 235 + tags?: boolean; 236 + }; 417 237 /** 418 - * Custom function to generate metadata for the operation. 419 - * Can return any valid meta object that will be included in the generated mutation options. 420 - * @param operation - The operation object containing all available metadata 421 - * @returns A meta object with any properties you want to include 238 + * Configuration for generated query options helpers. 422 239 * 423 - * @example 424 - * ```typescript 425 - * meta: (operation) => ({ 426 - * customField: operation.id, 427 - * isDeprecated: operation.deprecated, 428 - * tags: operation.tags, 429 - * customObject: { 430 - * method: operation.method, 431 - * path: operation.path 432 - * } 433 - * }) 434 - * ``` 240 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery} 435 241 * 436 - * @default false 437 - */ 438 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 439 - /** 440 - * Custom naming pattern for generated mutation options names. The name variable is 441 - * obtained from the SDK function name. 242 + * Can be: 243 + * - `boolean`: Shorthand for `{ enabled: boolean }` 244 + * - `string` or `function`: Shorthand for `{ name: string | function }` 245 + * - `object`: Full configuration object 442 246 * 443 - * @default '{{name}}Mutation' 444 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation 247 + * @default true 445 248 */ 446 - name: StringName; 249 + queryOptions?: 250 + | boolean 251 + | StringName 252 + | { 253 + /** 254 + * The casing convention to use for generated names. 255 + * 256 + * @default 'camelCase' 257 + */ 258 + case?: StringCase; 259 + /** 260 + * Whether to generate query options helpers. 261 + * 262 + * @default true 263 + */ 264 + enabled?: boolean; 265 + /** 266 + * Custom function to generate metadata for the operation. 267 + * Can return any valid meta object that will be included in the generated query options. 268 + * @param operation - The operation object containing all available metadata 269 + * @returns A meta object with any properties you want to include 270 + * 271 + * @example 272 + * ```typescript 273 + * meta: (operation) => ({ 274 + * customField: operation.id, 275 + * isDeprecated: operation.deprecated, 276 + * tags: operation.tags, 277 + * customObject: { 278 + * method: operation.method, 279 + * path: operation.path 280 + * } 281 + * }) 282 + * ``` 283 + * 284 + * @default undefined 285 + */ 286 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 287 + /** 288 + * Custom naming pattern for generated query options names. The name variable is 289 + * obtained from the SDK function name. 290 + * 291 + * @default '{{name}}Options' 292 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery 293 + */ 294 + name?: StringName; 295 + }; 447 296 }; 448 - /** 449 - * Name of the generated file. 450 - * 451 - * @default '@tanstack/svelte-query' 452 - */ 453 - output: string; 454 - /** 455 - * Resolved configuration for generated query keys. 456 - * 457 - * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-keys 458 - */ 459 - queryKeys: { 297 + 298 + export type Config = Plugin.Name<'@tanstack/svelte-query'> & 299 + Plugin.Hooks & { 460 300 /** 461 301 * The casing convention to use for generated names. 462 302 * ··· 464 304 */ 465 305 case: StringCase; 466 306 /** 467 - * Whether to generate query keys. 307 + * Add comments from SDK functions to the generated TanStack Query code? 468 308 * 469 309 * @default true 470 310 */ 471 - enabled: boolean; 311 + comments: boolean; 472 312 /** 473 - * Custom naming pattern for generated query key names. The name variable is 474 - * obtained from the SDK function name. 313 + * Should the exports from the generated files be re-exported in the index barrel file? 475 314 * 476 - * @default '{{name}}QueryKey' 477 - * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-keys 315 + * @default false 478 316 */ 479 - name: StringName; 317 + exportFromIndex: boolean; 480 318 /** 481 - * Whether to include operation tags in query keys. 482 - * This will make query keys larger but provides better cache invalidation capabilities. 319 + * Resolved configuration for generated infinite query key helpers. 483 320 * 484 - * @default false 321 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 485 322 */ 486 - tags: boolean; 487 - }; 488 - /** 489 - * Resolved configuration for generated query options helpers. 490 - * 491 - * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery 492 - */ 493 - queryOptions: { 323 + infiniteQueryKeys: { 324 + /** 325 + * The casing convention to use for generated names. 326 + * 327 + * @default 'camelCase' 328 + */ 329 + case: StringCase; 330 + /** 331 + * Whether to generate infinite query key helpers. 332 + * 333 + * @default true 334 + */ 335 + enabled: boolean; 336 + /** 337 + * Custom naming pattern for generated infinite query key names. The name variable is 338 + * obtained from the SDK function name. 339 + * 340 + * @default '{{name}}InfiniteQueryKey' 341 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 342 + */ 343 + name: StringName; 344 + /** 345 + * Whether to include operation tags in infinite query keys. 346 + * This will make query keys larger but provides better cache invalidation capabilities. 347 + * 348 + * @default false 349 + */ 350 + tags: boolean; 351 + }; 494 352 /** 495 - * The casing convention to use for generated names. 353 + * Resolved configuration for generated infinite query options helpers. 496 354 * 497 - * @default 'camelCase' 355 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 498 356 */ 499 - case: StringCase; 357 + infiniteQueryOptions: { 358 + /** 359 + * The casing convention to use for generated names. 360 + * 361 + * @default 'camelCase' 362 + */ 363 + case: StringCase; 364 + /** 365 + * Whether to generate infinite query options helpers. 366 + * 367 + * @default true 368 + */ 369 + enabled: boolean; 370 + /** 371 + * Custom function to generate metadata for the operation. 372 + * Can return any valid meta object that will be included in the generated infinite query options. 373 + * @param operation - The operation object containing all available metadata 374 + * @returns A meta object with any properties you want to include 375 + * 376 + * @example 377 + * ```typescript 378 + * meta: (operation) => ({ 379 + * customField: operation.id, 380 + * isDeprecated: operation.deprecated, 381 + * tags: operation.tags, 382 + * customObject: { 383 + * method: operation.method, 384 + * path: operation.path 385 + * } 386 + * }) 387 + * ``` 388 + * 389 + * @default undefined 390 + */ 391 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 392 + /** 393 + * Custom naming pattern for generated infinite query options names. The name variable is 394 + * obtained from the SDK function name. 395 + * 396 + * @default '{{name}}InfiniteOptions' 397 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createinfinitequery 398 + */ 399 + name: StringName; 400 + }; 500 401 /** 501 - * Whether to generate query options helpers. 402 + * Resolved configuration for generated mutation options helpers. 502 403 * 503 - * @default true 404 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation 504 405 */ 505 - enabled: boolean; 406 + mutationOptions: { 407 + /** 408 + * The casing convention to use for generated names. 409 + * 410 + * @default 'camelCase' 411 + */ 412 + case: StringCase; 413 + /** 414 + * Whether to generate mutation options helpers. 415 + * 416 + * @default true 417 + */ 418 + enabled: boolean; 419 + /** 420 + * Custom function to generate metadata for the operation. 421 + * Can return any valid meta object that will be included in the generated mutation options. 422 + * @param operation - The operation object containing all available metadata 423 + * @returns A meta object with any properties you want to include 424 + * 425 + * @example 426 + * ```typescript 427 + * meta: (operation) => ({ 428 + * customField: operation.id, 429 + * isDeprecated: operation.deprecated, 430 + * tags: operation.tags, 431 + * customObject: { 432 + * method: operation.method, 433 + * path: operation.path 434 + * } 435 + * }) 436 + * ``` 437 + * 438 + * @default undefined 439 + */ 440 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 441 + /** 442 + * Custom naming pattern for generated mutation options names. The name variable is 443 + * obtained from the SDK function name. 444 + * 445 + * @default '{{name}}Mutation' 446 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation 447 + */ 448 + name: StringName; 449 + }; 506 450 /** 507 - * Custom function to generate metadata for the operation. 508 - * Can return any valid meta object that will be included in the generated query options. 509 - * @param operation - The operation object containing all available metadata 510 - * @returns A meta object with any properties you want to include 451 + * Name of the generated file. 511 452 * 512 - * @example 513 - * ```typescript 514 - * meta: (operation) => ({ 515 - * customField: operation.id, 516 - * isDeprecated: operation.deprecated, 517 - * tags: operation.tags, 518 - * customObject: { 519 - * method: operation.method, 520 - * path: operation.path 521 - * } 522 - * }) 523 - * ``` 453 + * @default '@tanstack/svelte-query' 454 + */ 455 + output: string; 456 + /** 457 + * Resolved configuration for generated query keys. 524 458 * 525 - * @default false 459 + * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-keys 526 460 */ 527 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 461 + queryKeys: { 462 + /** 463 + * The casing convention to use for generated names. 464 + * 465 + * @default 'camelCase' 466 + */ 467 + case: StringCase; 468 + /** 469 + * Whether to generate query keys. 470 + * 471 + * @default true 472 + */ 473 + enabled: boolean; 474 + /** 475 + * Custom naming pattern for generated query key names. The name variable is 476 + * obtained from the SDK function name. 477 + * 478 + * @default '{{name}}QueryKey' 479 + * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-keys 480 + */ 481 + name: StringName; 482 + /** 483 + * Whether to include operation tags in query keys. 484 + * This will make query keys larger but provides better cache invalidation capabilities. 485 + * 486 + * @default false 487 + */ 488 + tags: boolean; 489 + }; 528 490 /** 529 - * Custom naming pattern for generated query options names. The name variable is 530 - * obtained from the SDK function name. 491 + * Resolved configuration for generated query options helpers. 531 492 * 532 - * @default '{{name}}Options' 533 493 * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery 534 494 */ 535 - name: StringName; 495 + queryOptions: { 496 + /** 497 + * The casing convention to use for generated names. 498 + * 499 + * @default 'camelCase' 500 + */ 501 + case: StringCase; 502 + /** 503 + * Whether to generate query options helpers. 504 + * 505 + * @default true 506 + */ 507 + enabled: boolean; 508 + /** 509 + * Custom function to generate metadata for the operation. 510 + * Can return any valid meta object that will be included in the generated query options. 511 + * @param operation - The operation object containing all available metadata 512 + * @returns A meta object with any properties you want to include 513 + * 514 + * @example 515 + * ```typescript 516 + * meta: (operation) => ({ 517 + * customField: operation.id, 518 + * isDeprecated: operation.deprecated, 519 + * tags: operation.tags, 520 + * customObject: { 521 + * method: operation.method, 522 + * path: operation.path 523 + * } 524 + * }) 525 + * ``` 526 + * 527 + * @default undefined 528 + */ 529 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 530 + /** 531 + * Custom naming pattern for generated query options names. The name variable is 532 + * obtained from the SDK function name. 533 + * 534 + * @default '{{name}}Options' 535 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery 536 + */ 537 + name: StringName; 538 + }; 536 539 }; 537 - }; 538 540 539 541 export type TanStackSvelteQueryPlugin = DefinePlugin<UserConfig, Config>;
-3
packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts
··· 34 34 defaultValue: { 35 35 case: plugin.config.case ?? 'camelCase', 36 36 enabled: true, 37 - meta: false, 38 37 name: '{{name}}InfiniteOptions', 39 38 }, 40 39 mappers: { ··· 49 48 defaultValue: { 50 49 case: plugin.config.case ?? 'camelCase', 51 50 enabled: true, 52 - meta: false, 53 51 name: '{{name}}Mutation', 54 52 }, 55 53 mappers: { ··· 79 77 defaultValue: { 80 78 case: plugin.config.case ?? 'camelCase', 81 79 enabled: true, 82 - meta: false, 83 80 name: '{{name}}Options', 84 81 }, 85 82 mappers: {
+472 -458
packages/openapi-ts/src/plugins/@tanstack/vue-query/types.d.ts
··· 2 2 import type { StringCase, StringName } from '../../../types/case'; 3 3 import type { DefinePlugin, Plugin } from '../../types'; 4 4 5 - export type UserConfig = Plugin.Name<'@tanstack/vue-query'> & { 6 - /** 7 - * The casing convention to use for generated names. 8 - * 9 - * @default 'camelCase' 10 - */ 11 - case?: StringCase; 12 - /** 13 - * Add comments from SDK functions to the generated TanStack Query code? 14 - * 15 - * @default true 16 - */ 17 - comments?: boolean; 18 - /** 19 - * Should the exports from the generated files be re-exported in the index barrel file? 20 - * 21 - * @default false 22 - */ 23 - exportFromIndex?: boolean; 24 - /** 25 - * Configuration for generated infinite query key helpers. 26 - * 27 - * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 28 - * 29 - * Can be: 30 - * - `boolean`: Shorthand for `{ enabled: boolean }` 31 - * - `string` or `function`: Shorthand for `{ name: string | function }` 32 - * - `object`: Full configuration object 33 - * 34 - * @default true 35 - */ 36 - infiniteQueryKeys?: 37 - | boolean 38 - | StringName 39 - | { 40 - /** 41 - * The casing convention to use for generated names. 42 - * 43 - * @default 'camelCase' 44 - */ 45 - case?: StringCase; 46 - /** 47 - * Whether to generate infinite query key helpers. 48 - * 49 - * @default true 50 - */ 51 - enabled?: boolean; 52 - /** 53 - * Custom naming pattern for generated infinite query key names. The name variable is 54 - * obtained from the SDK function name. 55 - * 56 - * @default '{{name}}InfiniteQueryKey' 57 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 58 - */ 59 - name?: StringName; 60 - /** 61 - * Whether to include operation tags in infinite query keys. 62 - * This will make query keys larger but provides better cache invalidation capabilities. 63 - * 64 - * @default false 65 - */ 66 - tags?: boolean; 67 - }; 68 - /** 69 - * Configuration for generated infinite query options helpers. 70 - * 71 - * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 72 - * 73 - * Can be: 74 - * - `boolean`: Shorthand for `{ enabled: boolean }` 75 - * - `string` or `function`: Shorthand for `{ name: string | function }` 76 - * - `object`: Full configuration object 77 - * 78 - * @default true 79 - */ 80 - infiniteQueryOptions?: 81 - | boolean 82 - | StringName 83 - | { 84 - /** 85 - * The casing convention to use for generated names. 86 - * 87 - * @default 'camelCase' 88 - */ 89 - case?: StringCase; 90 - /** 91 - * Whether to generate infinite query options helpers. 92 - * 93 - * @default true 94 - */ 95 - enabled?: boolean; 96 - /** 97 - * Custom function to generate metadata for the operation. 98 - * Can return any valid meta object that will be included in the generated infinite query options. 99 - * 100 - * @param operation - The operation object containing all available metadata 101 - * @returns A meta object with any properties you want to include 102 - * 103 - * @example 104 - * ```typescript 105 - * meta: (operation) => ({ 106 - * customField: operation.id, 107 - * isDeprecated: operation.deprecated, 108 - * tags: operation.tags, 109 - * customObject: { 110 - * method: operation.method, 111 - * path: operation.path 112 - * } 113 - * }) 114 - * ``` 115 - */ 116 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 117 - /** 118 - * Custom naming pattern for generated infinite query options names. The name variable is 119 - * obtained from the SDK function name. 120 - * 121 - * @default '{{name}}InfiniteOptions' 122 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 123 - */ 124 - name?: StringName; 125 - }; 126 - /** 127 - * Configuration for generated mutation options helpers. 128 - * 129 - * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation} 130 - * 131 - * Can be: 132 - * - `boolean`: Shorthand for `{ enabled: boolean }` 133 - * - `string` or `function`: Shorthand for `{ name: string | function }` 134 - * - `object`: Full configuration object 135 - * 136 - * @default true 137 - */ 138 - mutationOptions?: 139 - | boolean 140 - | StringName 141 - | { 142 - /** 143 - * The casing convention to use for generated names. 144 - * 145 - * @default 'camelCase' 146 - */ 147 - case?: StringCase; 148 - /** 149 - * Whether to generate mutation options helpers. 150 - * 151 - * @default true 152 - */ 153 - enabled?: boolean; 154 - /** 155 - * Custom function to generate metadata for the operation. 156 - * Can return any valid meta object that will be included in the generated mutation options. 157 - * 158 - * @param operation - The operation object containing all available metadata 159 - * @returns A meta object with any properties you want to include 160 - * 161 - * @example 162 - * ```typescript 163 - * meta: (operation) => ({ 164 - * customField: operation.id, 165 - * isDeprecated: operation.deprecated, 166 - * tags: operation.tags, 167 - * customObject: { 168 - * method: operation.method, 169 - * path: operation.path 170 - * } 171 - * }) 172 - * ``` 173 - */ 174 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 175 - /** 176 - * Custom naming pattern for generated mutation options names. The name variable is 177 - * obtained from the SDK function name. 178 - * 179 - * @default '{{name}}Mutation' 180 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 181 - */ 182 - name?: StringName; 183 - }; 184 - /** 185 - * Name of the generated file. 186 - * 187 - * @default '@tanstack/vue-query' 188 - */ 189 - output?: string; 190 - /** 191 - * Configuration for generated query keys. 192 - * 193 - * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey} 194 - * 195 - * Can be: 196 - * - `boolean`: Shorthand for `{ enabled: boolean }` 197 - * - `string` or `function`: Shorthand for `{ name: string | function }` 198 - * - `object`: Full configuration object 199 - * 200 - * @default true 201 - */ 202 - queryKeys?: 203 - | boolean 204 - | StringName 205 - | { 206 - /** 207 - * The casing convention to use for generated names. 208 - * 209 - * @default 'camelCase' 210 - */ 211 - case?: StringCase; 212 - /** 213 - * Whether to generate query keys. 214 - * 215 - * @default true 216 - */ 217 - enabled?: boolean; 218 - /** 219 - * Custom naming pattern for generated query key names. The name variable is 220 - * obtained from the SDK function name. 221 - * 222 - * @default '{{name}}QueryKey' 223 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 224 - */ 225 - name?: StringName; 226 - /** 227 - * Whether to include operation tags in query keys. 228 - * This will make query keys larger but provides better cache invalidation capabilities. 229 - * 230 - * @default false 231 - */ 232 - tags?: boolean; 233 - }; 234 - /** 235 - * Configuration for generated query options helpers. 236 - * 237 - * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions} 238 - * 239 - * Can be: 240 - * - `boolean`: Shorthand for `{ enabled: boolean }` 241 - * - `string` or `function`: Shorthand for `{ name: string | function }` 242 - * - `object`: Full configuration object 243 - * 244 - * @default true 245 - */ 246 - queryOptions?: 247 - | boolean 248 - | StringName 249 - | { 250 - /** 251 - * The casing convention to use for generated names. 252 - * 253 - * @default 'camelCase' 254 - */ 255 - case?: StringCase; 256 - /** 257 - * Whether to generate query options helpers. 258 - * 259 - * @default true 260 - */ 261 - enabled?: boolean; 262 - /** 263 - * Custom function to generate metadata for the operation. 264 - * Can return any valid meta object that will be included in the generated query options. 265 - * 266 - * @param operation - The operation object containing all available metadata 267 - * @returns A meta object with any properties you want to include 268 - * 269 - * @example 270 - * ```typescript 271 - * meta: (operation) => ({ 272 - * customField: operation.id, 273 - * isDeprecated: operation.deprecated, 274 - * tags: operation.tags, 275 - * customObject: { 276 - * method: operation.method, 277 - * path: operation.path 278 - * } 279 - * }) 280 - * ``` 281 - */ 282 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 283 - /** 284 - * Custom naming pattern for generated query options names. The name variable is 285 - * obtained from the SDK function name. 286 - * 287 - * @default '{{name}}Options' 288 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 289 - */ 290 - name?: StringName; 291 - }; 292 - }; 293 - 294 - export type Config = Plugin.Name<'@tanstack/vue-query'> & { 295 - /** 296 - * The casing convention to use for generated names. 297 - * 298 - * @default 'camelCase' 299 - */ 300 - case: StringCase; 301 - /** 302 - * Add comments from SDK functions to the generated TanStack Query code? 303 - * 304 - * @default true 305 - */ 306 - comments: boolean; 307 - /** 308 - * Should the exports from the generated files be re-exported in the index barrel file? 309 - * 310 - * @default false 311 - */ 312 - exportFromIndex: boolean; 313 - /** 314 - * Resolved configuration for generated infinite query key helpers. 315 - * 316 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 317 - */ 318 - infiniteQueryKeys: { 5 + export type UserConfig = Plugin.Name<'@tanstack/vue-query'> & 6 + Plugin.Hooks & { 319 7 /** 320 8 * The casing convention to use for generated names. 321 9 * 322 10 * @default 'camelCase' 323 11 */ 324 - case: StringCase; 12 + case?: StringCase; 325 13 /** 326 - * Whether to generate infinite query key helpers. 14 + * Add comments from SDK functions to the generated TanStack Query code? 327 15 * 328 16 * @default true 329 17 */ 330 - enabled: boolean; 18 + comments?: boolean; 331 19 /** 332 - * Custom naming pattern for generated infinite query key names. The name variable is 333 - * obtained from the SDK function name. 334 - * 335 - * @default '{{name}}InfiniteQueryKey' 336 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 337 - */ 338 - name: StringName; 339 - /** 340 - * Whether to include operation tags in infinite query keys. 341 - * This will make query keys larger but provides better cache invalidation capabilities. 20 + * Should the exports from the generated files be re-exported in the index barrel file? 342 21 * 343 22 * @default false 344 23 */ 345 - tags: boolean; 346 - }; 347 - /** 348 - * Resolved configuration for generated infinite query options helpers. 349 - * 350 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 351 - */ 352 - infiniteQueryOptions: { 24 + exportFromIndex?: boolean; 353 25 /** 354 - * The casing convention to use for generated names. 26 + * Configuration for generated infinite query key helpers. 355 27 * 356 - * @default 'camelCase' 357 - */ 358 - case: StringCase; 359 - /** 360 - * Whether to generate infinite query options helpers. 28 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 29 + * 30 + * Can be: 31 + * - `boolean`: Shorthand for `{ enabled: boolean }` 32 + * - `string` or `function`: Shorthand for `{ name: string | function }` 33 + * - `object`: Full configuration object 361 34 * 362 35 * @default true 363 36 */ 364 - enabled: boolean; 37 + infiniteQueryKeys?: 38 + | boolean 39 + | StringName 40 + | { 41 + /** 42 + * The casing convention to use for generated names. 43 + * 44 + * @default 'camelCase' 45 + */ 46 + case?: StringCase; 47 + /** 48 + * Whether to generate infinite query key helpers. 49 + * 50 + * @default true 51 + */ 52 + enabled?: boolean; 53 + /** 54 + * Custom naming pattern for generated infinite query key names. The name variable is 55 + * obtained from the SDK function name. 56 + * 57 + * @default '{{name}}InfiniteQueryKey' 58 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 59 + */ 60 + name?: StringName; 61 + /** 62 + * Whether to include operation tags in infinite query keys. 63 + * This will make query keys larger but provides better cache invalidation capabilities. 64 + * 65 + * @default false 66 + */ 67 + tags?: boolean; 68 + }; 365 69 /** 366 - * Custom function to generate metadata for the operation. 367 - * Can return any valid meta object that will be included in the generated infinite query options. 70 + * Configuration for generated infinite query options helpers. 368 71 * 369 - * @param operation - The operation object containing all available metadata 370 - * @returns A meta object with any properties you want to include 72 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 371 73 * 372 - * @example 373 - * ```typescript 374 - * meta: (operation) => ({ 375 - * customField: operation.id, 376 - * isDeprecated: operation.deprecated, 377 - * tags: operation.tags, 378 - * customObject: { 379 - * method: operation.method, 380 - * path: operation.path 381 - * } 382 - * }) 383 - * ``` 74 + * Can be: 75 + * - `boolean`: Shorthand for `{ enabled: boolean }` 76 + * - `string` or `function`: Shorthand for `{ name: string | function }` 77 + * - `object`: Full configuration object 78 + * 79 + * @default true 384 80 */ 385 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 81 + infiniteQueryOptions?: 82 + | boolean 83 + | StringName 84 + | { 85 + /** 86 + * The casing convention to use for generated names. 87 + * 88 + * @default 'camelCase' 89 + */ 90 + case?: StringCase; 91 + /** 92 + * Whether to generate infinite query options helpers. 93 + * 94 + * @default true 95 + */ 96 + enabled?: boolean; 97 + /** 98 + * Custom function to generate metadata for the operation. 99 + * Can return any valid meta object that will be included in the generated infinite query options. 100 + * 101 + * @param operation - The operation object containing all available metadata 102 + * @returns A meta object with any properties you want to include 103 + * 104 + * @example 105 + * ```typescript 106 + * meta: (operation) => ({ 107 + * customField: operation.id, 108 + * isDeprecated: operation.deprecated, 109 + * tags: operation.tags, 110 + * customObject: { 111 + * method: operation.method, 112 + * path: operation.path 113 + * } 114 + * }) 115 + * ``` 116 + * 117 + * @default undefined 118 + */ 119 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 120 + /** 121 + * Custom naming pattern for generated infinite query options names. The name variable is 122 + * obtained from the SDK function name. 123 + * 124 + * @default '{{name}}InfiniteOptions' 125 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 126 + */ 127 + name?: StringName; 128 + }; 386 129 /** 387 - * Custom naming pattern for generated infinite query options names. The name variable is 388 - * obtained from the SDK function name. 130 + * Configuration for generated mutation options helpers. 389 131 * 390 - * @default '{{name}}InfiniteOptions' 391 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 132 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation} 133 + * 134 + * Can be: 135 + * - `boolean`: Shorthand for `{ enabled: boolean }` 136 + * - `string` or `function`: Shorthand for `{ name: string | function }` 137 + * - `object`: Full configuration object 138 + * 139 + * @default true 392 140 */ 393 - name: StringName; 394 - }; 395 - /** 396 - * Resolved configuration for generated mutation options helpers. 397 - * 398 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 399 - */ 400 - mutationOptions: { 141 + mutationOptions?: 142 + | boolean 143 + | StringName 144 + | { 145 + /** 146 + * The casing convention to use for generated names. 147 + * 148 + * @default 'camelCase' 149 + */ 150 + case?: StringCase; 151 + /** 152 + * Whether to generate mutation options helpers. 153 + * 154 + * @default true 155 + */ 156 + enabled?: boolean; 157 + /** 158 + * Custom function to generate metadata for the operation. 159 + * Can return any valid meta object that will be included in the generated mutation options. 160 + * 161 + * @param operation - The operation object containing all available metadata 162 + * @returns A meta object with any properties you want to include 163 + * 164 + * @example 165 + * ```typescript 166 + * meta: (operation) => ({ 167 + * customField: operation.id, 168 + * isDeprecated: operation.deprecated, 169 + * tags: operation.tags, 170 + * customObject: { 171 + * method: operation.method, 172 + * path: operation.path 173 + * } 174 + * }) 175 + * ``` 176 + * 177 + * @default undefined 178 + */ 179 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 180 + /** 181 + * Custom naming pattern for generated mutation options names. The name variable is 182 + * obtained from the SDK function name. 183 + * 184 + * @default '{{name}}Mutation' 185 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 186 + */ 187 + name?: StringName; 188 + }; 401 189 /** 402 - * The casing convention to use for generated names. 190 + * Name of the generated file. 403 191 * 404 - * @default 'camelCase' 192 + * @default '@tanstack/vue-query' 405 193 */ 406 - case: StringCase; 194 + output?: string; 407 195 /** 408 - * Whether to generate mutation options helpers. 196 + * Configuration for generated query keys. 197 + * 198 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey} 199 + * 200 + * Can be: 201 + * - `boolean`: Shorthand for `{ enabled: boolean }` 202 + * - `string` or `function`: Shorthand for `{ name: string | function }` 203 + * - `object`: Full configuration object 409 204 * 410 205 * @default true 411 206 */ 412 - enabled: boolean; 207 + queryKeys?: 208 + | boolean 209 + | StringName 210 + | { 211 + /** 212 + * The casing convention to use for generated names. 213 + * 214 + * @default 'camelCase' 215 + */ 216 + case?: StringCase; 217 + /** 218 + * Whether to generate query keys. 219 + * 220 + * @default true 221 + */ 222 + enabled?: boolean; 223 + /** 224 + * Custom naming pattern for generated query key names. The name variable is 225 + * obtained from the SDK function name. 226 + * 227 + * @default '{{name}}QueryKey' 228 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 229 + */ 230 + name?: StringName; 231 + /** 232 + * Whether to include operation tags in query keys. 233 + * This will make query keys larger but provides better cache invalidation capabilities. 234 + * 235 + * @default false 236 + */ 237 + tags?: boolean; 238 + }; 413 239 /** 414 - * Custom function to generate metadata for the operation. 415 - * Can return any valid meta object that will be included in the generated mutation options. 240 + * Configuration for generated query options helpers. 416 241 * 417 - * @param operation - The operation object containing all available metadata 418 - * @returns A meta object with any properties you want to include 242 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions} 419 243 * 420 - * @example 421 - * ```typescript 422 - * meta: (operation) => ({ 423 - * customField: operation.id, 424 - * isDeprecated: operation.deprecated, 425 - * tags: operation.tags, 426 - * customObject: { 427 - * method: operation.method, 428 - * path: operation.path 429 - * } 430 - * }) 431 - * ``` 432 - */ 433 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 434 - /** 435 - * Custom naming pattern for generated mutation options names. The name variable is 436 - * obtained from the SDK function name. 244 + * Can be: 245 + * - `boolean`: Shorthand for `{ enabled: boolean }` 246 + * - `string` or `function`: Shorthand for `{ name: string | function }` 247 + * - `object`: Full configuration object 437 248 * 438 - * @default '{{name}}Mutation' 439 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 249 + * @default true 440 250 */ 441 - name: StringName; 251 + queryOptions?: 252 + | boolean 253 + | StringName 254 + | { 255 + /** 256 + * The casing convention to use for generated names. 257 + * 258 + * @default 'camelCase' 259 + */ 260 + case?: StringCase; 261 + /** 262 + * Whether to generate query options helpers. 263 + * 264 + * @default true 265 + */ 266 + enabled?: boolean; 267 + /** 268 + * Custom function to generate metadata for the operation. 269 + * Can return any valid meta object that will be included in the generated query options. 270 + * 271 + * @param operation - The operation object containing all available metadata 272 + * @returns A meta object with any properties you want to include 273 + * 274 + * @example 275 + * ```typescript 276 + * meta: (operation) => ({ 277 + * customField: operation.id, 278 + * isDeprecated: operation.deprecated, 279 + * tags: operation.tags, 280 + * customObject: { 281 + * method: operation.method, 282 + * path: operation.path 283 + * } 284 + * }) 285 + * ``` 286 + * 287 + * @default undefined 288 + */ 289 + meta?: (operation: IR.OperationObject) => Record<string, unknown>; 290 + /** 291 + * Custom naming pattern for generated query options names. The name variable is 292 + * obtained from the SDK function name. 293 + * 294 + * @default '{{name}}Options' 295 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 296 + */ 297 + name?: StringName; 298 + }; 442 299 }; 443 - /** 444 - * Name of the generated file. 445 - * 446 - * @default '@tanstack/vue-query' 447 - */ 448 - output: string; 449 - /** 450 - * Resolved configuration for generated query keys. 451 - * 452 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 453 - */ 454 - queryKeys: { 300 + 301 + export type Config = Plugin.Name<'@tanstack/vue-query'> & 302 + Plugin.Hooks & { 455 303 /** 456 304 * The casing convention to use for generated names. 457 305 * ··· 459 307 */ 460 308 case: StringCase; 461 309 /** 462 - * Whether to generate query keys. 310 + * Add comments from SDK functions to the generated TanStack Query code? 463 311 * 464 312 * @default true 465 313 */ 466 - enabled: boolean; 314 + comments: boolean; 467 315 /** 468 - * Custom naming pattern for generated query key names. The name variable is 469 - * obtained from the SDK function name. 316 + * Should the exports from the generated files be re-exported in the index barrel file? 470 317 * 471 - * @default '{{name}}QueryKey' 472 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 318 + * @default false 473 319 */ 474 - name: StringName; 320 + exportFromIndex: boolean; 475 321 /** 476 - * Whether to include operation tags in query keys. 477 - * This will make query keys larger but provides better cache invalidation capabilities. 322 + * Resolved configuration for generated infinite query key helpers. 478 323 * 479 - * @default false 324 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 480 325 */ 481 - tags: boolean; 482 - }; 483 - /** 484 - * Resolved configuration for generated query options helpers. 485 - * 486 - * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 487 - */ 488 - queryOptions: { 326 + infiniteQueryKeys: { 327 + /** 328 + * The casing convention to use for generated names. 329 + * 330 + * @default 'camelCase' 331 + */ 332 + case: StringCase; 333 + /** 334 + * Whether to generate infinite query key helpers. 335 + * 336 + * @default true 337 + */ 338 + enabled: boolean; 339 + /** 340 + * Custom naming pattern for generated infinite query key names. The name variable is 341 + * obtained from the SDK function name. 342 + * 343 + * @default '{{name}}InfiniteQueryKey' 344 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 345 + */ 346 + name: StringName; 347 + /** 348 + * Whether to include operation tags in infinite query keys. 349 + * This will make query keys larger but provides better cache invalidation capabilities. 350 + * 351 + * @default false 352 + */ 353 + tags: boolean; 354 + }; 489 355 /** 490 - * The casing convention to use for generated names. 356 + * Resolved configuration for generated infinite query options helpers. 491 357 * 492 - * @default 'camelCase' 358 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 493 359 */ 494 - case: StringCase; 360 + infiniteQueryOptions: { 361 + /** 362 + * The casing convention to use for generated names. 363 + * 364 + * @default 'camelCase' 365 + */ 366 + case: StringCase; 367 + /** 368 + * Whether to generate infinite query options helpers. 369 + * 370 + * @default true 371 + */ 372 + enabled: boolean; 373 + /** 374 + * Custom function to generate metadata for the operation. 375 + * Can return any valid meta object that will be included in the generated infinite query options. 376 + * 377 + * @param operation - The operation object containing all available metadata 378 + * @returns A meta object with any properties you want to include 379 + * 380 + * @example 381 + * ```typescript 382 + * meta: (operation) => ({ 383 + * customField: operation.id, 384 + * isDeprecated: operation.deprecated, 385 + * tags: operation.tags, 386 + * customObject: { 387 + * method: operation.method, 388 + * path: operation.path 389 + * } 390 + * }) 391 + * ``` 392 + * 393 + * @default undefined 394 + */ 395 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 396 + /** 397 + * Custom naming pattern for generated infinite query options names. The name variable is 398 + * obtained from the SDK function name. 399 + * 400 + * @default '{{name}}InfiniteOptions' 401 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 402 + */ 403 + name: StringName; 404 + }; 495 405 /** 496 - * Whether to generate query options helpers. 406 + * Resolved configuration for generated mutation options helpers. 497 407 * 498 - * @default true 408 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 499 409 */ 500 - enabled: boolean; 410 + mutationOptions: { 411 + /** 412 + * The casing convention to use for generated names. 413 + * 414 + * @default 'camelCase' 415 + */ 416 + case: StringCase; 417 + /** 418 + * Whether to generate mutation options helpers. 419 + * 420 + * @default true 421 + */ 422 + enabled: boolean; 423 + /** 424 + * Custom function to generate metadata for the operation. 425 + * Can return any valid meta object that will be included in the generated mutation options. 426 + * 427 + * @param operation - The operation object containing all available metadata 428 + * @returns A meta object with any properties you want to include 429 + * 430 + * @example 431 + * ```typescript 432 + * meta: (operation) => ({ 433 + * customField: operation.id, 434 + * isDeprecated: operation.deprecated, 435 + * tags: operation.tags, 436 + * customObject: { 437 + * method: operation.method, 438 + * path: operation.path 439 + * } 440 + * }) 441 + * ``` 442 + * 443 + * @default undefined 444 + */ 445 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 446 + /** 447 + * Custom naming pattern for generated mutation options names. The name variable is 448 + * obtained from the SDK function name. 449 + * 450 + * @default '{{name}}Mutation' 451 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 452 + */ 453 + name: StringName; 454 + }; 501 455 /** 502 - * Custom function to generate metadata for the operation. 503 - * Can return any valid meta object that will be included in the generated query options. 456 + * Name of the generated file. 504 457 * 505 - * @param operation - The operation object containing all available metadata 506 - * @returns A meta object with any properties you want to include 458 + * @default '@tanstack/vue-query' 459 + */ 460 + output: string; 461 + /** 462 + * Resolved configuration for generated query keys. 507 463 * 508 - * @example 509 - * ```typescript 510 - * meta: (operation) => ({ 511 - * customField: operation.id, 512 - * isDeprecated: operation.deprecated, 513 - * tags: operation.tags, 514 - * customObject: { 515 - * method: operation.method, 516 - * path: operation.path 517 - * } 518 - * }) 519 - * ``` 464 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 520 465 */ 521 - meta?: false | ((operation: IR.OperationObject) => Record<string, any>); 466 + queryKeys: { 467 + /** 468 + * The casing convention to use for generated names. 469 + * 470 + * @default 'camelCase' 471 + */ 472 + case: StringCase; 473 + /** 474 + * Whether to generate query keys. 475 + * 476 + * @default true 477 + */ 478 + enabled: boolean; 479 + /** 480 + * Custom naming pattern for generated query key names. The name variable is 481 + * obtained from the SDK function name. 482 + * 483 + * @default '{{name}}QueryKey' 484 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 485 + */ 486 + name: StringName; 487 + /** 488 + * Whether to include operation tags in query keys. 489 + * This will make query keys larger but provides better cache invalidation capabilities. 490 + * 491 + * @default false 492 + */ 493 + tags: boolean; 494 + }; 522 495 /** 523 - * Custom naming pattern for generated query options names. The name variable is 524 - * obtained from the SDK function name. 496 + * Resolved configuration for generated query options helpers. 525 497 * 526 - * @default '{{name}}Options' 527 498 * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 528 499 */ 529 - name: StringName; 500 + queryOptions: { 501 + /** 502 + * The casing convention to use for generated names. 503 + * 504 + * @default 'camelCase' 505 + */ 506 + case: StringCase; 507 + /** 508 + * Whether to generate query options helpers. 509 + * 510 + * @default true 511 + */ 512 + enabled: boolean; 513 + /** 514 + * Custom function to generate metadata for the operation. 515 + * Can return any valid meta object that will be included in the generated query options. 516 + * 517 + * @param operation - The operation object containing all available metadata 518 + * @returns A meta object with any properties you want to include 519 + * 520 + * @example 521 + * ```typescript 522 + * meta: (operation) => ({ 523 + * customField: operation.id, 524 + * isDeprecated: operation.deprecated, 525 + * tags: operation.tags, 526 + * customObject: { 527 + * method: operation.method, 528 + * path: operation.path 529 + * } 530 + * }) 531 + * ``` 532 + * 533 + * @default undefined 534 + */ 535 + meta: (operation: IR.OperationObject) => Record<string, unknown>; 536 + /** 537 + * Custom naming pattern for generated query options names. The name variable is 538 + * obtained from the SDK function name. 539 + * 540 + * @default '{{name}}Options' 541 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 542 + */ 543 + name: StringName; 544 + }; 530 545 }; 531 - }; 532 546 533 547 export type TanStackVueQueryPlugin = DefinePlugin<UserConfig, Config>;
+61 -12
packages/openapi-ts/src/plugins/shared/utils/instance.ts
··· 5 5 import type { Plugin } from '../../types'; 6 6 import type { WalkEvent, WalkEventType } from '../types/instance'; 7 7 8 + const defaultGetKind: Required<Required<IR.Hooks>['operations']>['getKind'] = ( 9 + operation, 10 + ) => { 11 + switch (operation.method) { 12 + case 'delete': 13 + case 'patch': 14 + case 'post': 15 + case 'put': 16 + return ['mutation']; 17 + case 'get': 18 + return ['query']; 19 + default: 20 + return []; 21 + } 22 + }; 23 + 8 24 export class PluginInstance<T extends Plugin.Types = Plugin.Types> { 9 - public api: T['api']; 10 - public config: Omit<T['resolvedConfig'], 'name' | 'output'>; 11 - public context: IR.Context; 12 - public dependencies: Required<Plugin.Config<T>>['dependencies'] = []; 25 + api: T['api']; 26 + config: Omit<T['resolvedConfig'], 'name' | 'output'>; 27 + context: IR.Context; 28 + dependencies: Required<Plugin.Config<T>>['dependencies'] = []; 13 29 private handler: Plugin.Config<T>['handler']; 14 - public name: T['resolvedConfig']['name']; 15 - public output: Required<T['config']>['output']; 30 + name: T['resolvedConfig']['name']; 31 + output: Required<T['config']>['output']; 16 32 /** 17 33 * The package metadata and utilities for the current context, constructed 18 34 * from the provided dependencies. Used for managing package-related 19 35 * information such as name, version, and dependency resolution during 20 36 * code generation. 21 37 */ 22 - public package: IR.Context['package']; 38 + package: IR.Context['package']; 23 39 24 - public constructor( 40 + constructor( 25 41 props: Pick< 26 42 Required<Plugin.Config<T>>, 27 43 'config' | 'dependencies' | 'handler' ··· 42 58 this.package = props.context.package; 43 59 } 44 60 45 - public createFile(file: IR.ContextFile) { 61 + createFile(file: IR.ContextFile) { 46 62 return this.context.createFile({ 47 63 exportFromIndex: this.config.exportFromIndex, 48 64 ...file, ··· 71 87 * } 72 88 * }); 73 89 */ 74 - public forEach<T extends WalkEventType = WalkEventType>( 90 + forEach<T extends WalkEventType = WalkEventType>( 75 91 ...args: [ 76 92 ...events: ReadonlyArray<T>, 77 93 callback: (event: WalkEvent<T>) => void, ··· 216 232 * @param name Plugin name as defined in the configuration. 217 233 * @returns The plugin instance if found, undefined otherwise. 218 234 */ 219 - public getPlugin<T extends keyof PluginConfigMap>( 235 + getPlugin<T extends keyof PluginConfigMap>( 220 236 name: T, 221 237 ): T extends any ? PluginInstance<PluginConfigMap[T]> | undefined : never { 222 238 return this.context.plugins[name] as any; 223 239 } 224 240 241 + hooks = { 242 + operation: { 243 + isMutation: (operation: IR.OperationObject): boolean => { 244 + const isMutation = 245 + this.config['~hooks']?.operations?.isMutation ?? 246 + this.context.config.parser.hooks.operations?.isMutation; 247 + const isMutationResult = isMutation?.(operation); 248 + if (isMutationResult !== undefined) { 249 + return isMutationResult; 250 + } 251 + const getKind = 252 + this.config['~hooks']?.operations?.getKind ?? 253 + this.context.config.parser.hooks.operations?.getKind ?? 254 + defaultGetKind; 255 + return getKind(operation).includes('mutation'); 256 + }, 257 + isQuery: (operation: IR.OperationObject): boolean => { 258 + const isQuery = 259 + this.config['~hooks']?.operations?.isQuery ?? 260 + this.context.config.parser.hooks.operations?.isQuery; 261 + const isQueryResult = isQuery?.(operation); 262 + if (isQueryResult !== undefined) { 263 + return isQueryResult; 264 + } 265 + const getKind = 266 + this.config['~hooks']?.operations?.getKind ?? 267 + this.context.config.parser.hooks.operations?.getKind ?? 268 + defaultGetKind; 269 + return getKind(operation).includes('query'); 270 + }, 271 + }, 272 + }; 273 + 225 274 /** 226 275 * Executes plugin's handler function. 227 276 */ 228 - public async run() { 277 + async run() { 229 278 await this.handler({ plugin: this }); 230 279 } 231 280 }
+13
packages/openapi-ts/src/plugins/types.d.ts
··· 1 1 import type { ValueToObject } from '../config/utils/config'; 2 2 import type { Package } from '../config/utils/package'; 3 + import type { IR } from '../ir/types'; 3 4 import type { OpenApi as LegacyOpenApi } from '../openApi'; 4 5 import type { Client as LegacyClient } from '../types/client'; 5 6 import type { Files } from '../types/utils'; ··· 61 62 exportFromIndex?: boolean; 62 63 name: AnyPluginName; 63 64 output?: string; 65 + /** 66 + * Optional hooks to override default plugin behavior. 67 + * 68 + * Use these to classify resources, control which outputs are generated, 69 + * or provide custom behavior for specific resources. 70 + */ 71 + '~hooks'?: IR.Hooks; 64 72 }; 65 73 66 74 /** ··· 116 124 */ 117 125 name: any; 118 126 }; 127 + 128 + /** 129 + * Generic wrapper for plugin hooks. 130 + */ 131 + export type Hooks = Pick<BaseConfig, '~hooks'>; 119 132 120 133 export interface Name<Name extends PluginNames> { 121 134 name: Name;
+15
packages/openapi-ts/src/types/parser.d.ts
··· 1 + import type { IR } from '../ir/types'; 1 2 import type { 2 3 OpenApiMetaObject, 3 4 OpenApiOperationObject, ··· 16 17 * to plugins. 17 18 */ 18 19 filters?: Filters; 20 + /** 21 + * Optional hooks to override default plugin behavior. 22 + * 23 + * Use these to classify resources, control which outputs are generated, 24 + * or provide custom behavior for specific resources. 25 + */ 26 + hooks?: IR.Hooks; 19 27 /** 20 28 * Pagination configuration. 21 29 */ ··· 178 186 * to plugins. 179 187 */ 180 188 filters?: Filters; 189 + /** 190 + * Optional hooks to override default plugin behavior. 191 + * 192 + * Use these to classify resources, control which outputs are generated, 193 + * or provide custom behavior for specific resources. 194 + */ 195 + hooks: IR.Hooks; 181 196 /** 182 197 * Pagination configuration. 183 198 */
+9
packages/openapi-ts/src/types/utils.d.ts
··· 1 1 import type { GeneratedFile } from '../generate/file'; 2 2 3 + /** Recursively make all non-function properties optional */ 4 + export type DeepPartial<T> = { 5 + [K in keyof T]?: T[K] extends (...args: any[]) => any 6 + ? T[K] 7 + : T[K] extends object 8 + ? DeepPartial<T[K]> 9 + : T[K]; 10 + }; 11 + 3 12 export type Files = Record<string, GeneratedFile>;