Skip to content

Commit adab060

Browse files
7noheclaude
andcommitted
fix: restore v2-compatible Options type and operation JSDoc in generated hooks
- Import Options from ../requests/sdk.gen instead of ../requests/client; the sdk.gen Options is extended with `client` and `meta`, which v2 hooks accepted (per-request client override would fail to typecheck otherwise) - Emit the operation's JSDoc (description and @deprecated) on every generated hook, matching v2 output With this, regenerated output for all 5 example apps is semantically identical to v2.2.0 — remaining diffs are import statement merging and blank lines only. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 07ed7a2 commit adab060

6 files changed

Lines changed: 328 additions & 31 deletions

File tree

src/tsmorph/buildMutationHooks.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export function buildUseMutationHook(
5454

5555
return {
5656
kind: StructureKind.VariableStatement,
57+
// Copy the operation's JSDoc (description and @deprecated) from the SDK function
58+
leadingTrivia: op.jsDoc ? `${op.jsDoc}\n` : undefined,
5759
isExported: true,
5860
declarationKind: VariableDeclarationKind.Const,
5961
declarations: [

src/tsmorph/buildQueryHooks.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export function buildUseQueryHook(
106106

107107
return {
108108
kind: StructureKind.VariableStatement,
109+
// Copy the operation's JSDoc (description and @deprecated) from the SDK function
110+
leadingTrivia: op.jsDoc ? `${op.jsDoc}\n` : undefined,
109111
isExported: true,
110112
declarationKind: VariableDeclarationKind.Const,
111113
declarations: [
@@ -137,6 +139,8 @@ export function buildUseSuspenseQueryHook(
137139

138140
return {
139141
kind: StructureKind.VariableStatement,
142+
// Copy the operation's JSDoc (description and @deprecated) from the SDK function
143+
leadingTrivia: op.jsDoc ? `${op.jsDoc}\n` : undefined,
140144
isExported: true,
141145
declarationKind: VariableDeclarationKind.Const,
142146
declarations: [
@@ -196,6 +200,8 @@ export function buildUseInfiniteQueryHook(
196200

197201
return {
198202
kind: StructureKind.VariableStatement,
203+
// Copy the operation's JSDoc (description and @deprecated) from the SDK function
204+
leadingTrivia: op.jsDoc ? `${op.jsDoc}\n` : undefined,
199205
isExported: true,
200206
declarationKind: VariableDeclarationKind.Const,
201207
declarations: [
@@ -240,6 +246,8 @@ export function buildPrefetchFn(
240246

241247
return {
242248
kind: StructureKind.VariableStatement,
249+
// Copy the operation's JSDoc (description and @deprecated) from the SDK function
250+
leadingTrivia: op.jsDoc ? `${op.jsDoc}\n` : undefined,
243251
isExported: true,
244252
declarationKind: VariableDeclarationKind.Const,
245253
declarations: [
@@ -284,6 +292,8 @@ export function buildEnsureQueryDataFn(
284292

285293
return {
286294
kind: StructureKind.VariableStatement,
295+
// Copy the operation's JSDoc (description and @deprecated) from the SDK function
296+
leadingTrivia: op.jsDoc ? `${op.jsDoc}\n` : undefined,
287297
isExported: true,
288298
declarationKind: VariableDeclarationKind.Const,
289299
declarations: [

src/tsmorph/projectFactory.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ export function createGenerationProject(): Project {
2828
}
2929

3030
/**
31-
* Build import structure for client library.
32-
* In v0.73+, Options type is exported from the generated client file.
31+
* Build import structure for the Options type.
32+
* sdk.gen re-exports Options extended with `client` and `meta`, which the
33+
* base client Options lacks; hooks must accept those properties.
3334
*/
3435
export function buildClientImport(
3536
_ctx: GenerationContext,
3637
): ImportDeclarationStructure {
3738
return {
3839
kind: StructureKind.ImportDeclaration,
39-
moduleSpecifier: "../requests/client",
40+
moduleSpecifier: "../requests/sdk.gen",
4041
namedImports: [{ name: "Options", isTypeOnly: true }],
4142
};
4243
}

0 commit comments

Comments
 (0)