refactor: deduplicate JSDoc typedefs in generator-components#1770
refactor: deduplicate JSDoc typedefs in generator-components#1770Kartikayy007 wants to merge 5 commits intoasyncapi:masterfrom
Conversation
🦋 Changeset detectedLatest commit: 7f78ff9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
What reviewer looks at during PR reviewThe following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.
|
WalkthroughCentralizes duplicated JSDoc typedefs by adding Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/components/src/components/CloseConnection.js (1)
3-6: CentralLanguagetypedef import is correct; note existing config shape mismatchSwitching to
@typedef {import('../types').Language}is aligned with the sharedtypes.jsmodule and matches the languages used inwebsocketCloseConfig. One minor, pre‑existing nit: the JSDoc onwebsocketCloseConfig(Record<Language, { methodDocs?: string, methodLogic: string }>on Line 17) doesn’t quite describe the nestedjava: { quarkus: { ... } }shape. Not blocking here, but worth aligning when you revisit typings or move this to TypeScript.packages/components/src/types.js (2)
1-24: Centralized typedefs align well with the refactor goalsThe shared
Language,SupportedLanguage,Format, andQueryParamCodeBlocktypedefs look consistent and remove the prior duplication across components. KeepingSupportedLanguageas an alias for backward compatibility is a good touch.If you want to push this a bit further, you could optionally introduce a small helper typedef for the repeated
{ text: string, indent?: number, newLines?: number }shape used by allQueryParamCodeBlockfields, but that’s purely a readability/DRY improvement and not required for this PR.
26-26: Address Sonar warning onexport {}in a typedef‑only moduleSonar is flagging the bare
export {};as “export statement without specifiers is not allowed”. Since this file only contains JSDoc typedefs and has no runtime exports, you can safely drop that line and rely on the re‑export fromindex.js(or imports of this file) to treat it as a module where needed.Suggestion: remove the empty export line to keep Sonar happy without changing behavior.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
.changeset/dedupe-jsdoc-typedefs.md(1 hunks)packages/components/src/components/CloseConnection.js(1 hunks)packages/components/src/components/Connect.js(1 hunks)packages/components/src/components/DependencyProvider.js(1 hunks)packages/components/src/components/FileHeaderInfo.js(1 hunks)packages/components/src/components/HandleMessage.js(1 hunks)packages/components/src/components/MethodGenerator.js(1 hunks)packages/components/src/components/Models.js(1 hunks)packages/components/src/components/OnClose.js(1 hunks)packages/components/src/components/OnError.js(1 hunks)packages/components/src/components/OnMessage.js(1 hunks)packages/components/src/components/OnOpen.js(1 hunks)packages/components/src/components/QueryParamsVariables.js(1 hunks)packages/components/src/components/RegisterErrorHandler.js(1 hunks)packages/components/src/components/RegisterMessageHandler.js(1 hunks)packages/components/src/components/SendOperations.js(1 hunks)packages/components/src/index.js(1 hunks)packages/components/src/types.js(1 hunks)
🧰 Additional context used
🪛 GitHub Check: SonarCloud Code Analysis
packages/components/src/types.js
[warning] 26-26: export statement without specifiers is not allowed.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Test generator as dependency with Node 18
- GitHub Check: Test generator as dependency with Node 20
- GitHub Check: Acceptance tests for generated templates
- GitHub Check: Test NodeJS PR - windows-latest
- GitHub Check: Test NodeJS PR - ubuntu-latest
- GitHub Check: Test NodeJS PR - macos-latest
🔇 Additional comments (15)
packages/components/src/components/QueryParamsVariables.js (1)
5-11: Centralizing typedefs for query param generation looks goodUsing
@typedef {import('../types').SupportedLanguage}andQueryParamCodeBlockhere is consistent with the new sharedtypes.jsmodule and removes local duplication without touching runtime behavior..changeset/dedupe-jsdoc-typedefs.md (1)
1-5: Changeset description matches the implemented refactorThe changeset clearly documents the JSDoc typedef deduplication into
types.jsand correctly uses a patch release for this non‑runtime change.packages/components/src/components/DependencyProvider.js (1)
4-7: SharedLanguagetypedef import is consistent with usageSwitching
Languageto@typedef {import('../types').Language}keeps this file aligned with the centralized type definition and matches the languages used independenciesConfig(python,javascript,dart,java).packages/components/src/index.js (1)
15-17: Re-exportingtypes.jsthrough the index is appropriateAdding
export * from './types.js';cleanly surfaces the shared typedefs at the package level while preserving existing named exports. This is a safe, backward‑compatible enhancement.packages/components/src/components/SendOperations.js (1)
4-7: SharedSupportedLanguagetypedef import fits the send-operations configUsing
@typedef {import('../types').SupportedLanguage}here removes the local union and keeps thelanguageprop aligned with the centralized type used across components.packages/components/src/components/RegisterErrorHandler.js (1)
3-6: Typedef import forLanguageis correctly centralizedReferencing
Languageviaimport('../types').Languageremoves local duplication and stays consistent with the keys used inwebsocketErrorRegisterConfig.packages/components/src/components/FileHeaderInfo.js (1)
3-6: SharedLanguagetypedef is good; ensure it covers all header languagesImporting
Languagefrom../typesis consistent with the PR’s deduplication. GivencommentConfigsupportspython,javascript,typescript,java,csharp,rust, anddart, just confirm theLanguagetypedef intypes.jsincludes this full set so the JSDoc stays accurate for tooling and any future TypeScript migration.packages/components/src/components/OnOpen.js (1)
3-6: Centralized typedef usage looks correctUsing
@typedef {import('../types').SupportedLanguage}here matches the new shared types module and keeps the prop / map typings consistent. No further changes needed in this file.packages/components/src/components/MethodGenerator.js (1)
3-6: Language typedef import aligns with shared typesThe switch to
@typedef {import('../types').Language}cleanly centralizes the language union while keeping existingRecord<Language, …>annotations intact. Looks good.packages/components/src/components/RegisterMessageHandler.js (1)
3-6: Shared Language typedef applied consistentlyReferencing
Languagefrom../typeshere keeps the message‑handler config in sync with the centralized language definition. No issues from this refactor.packages/components/src/components/HandleMessage.js (1)
3-6: HandleMessage now correctly reuses the shared Language typedefThe new
@typedef {import('../types').Language}centralizes the language union without affecting runtime logic. All usages in this file remain type‑compatible.packages/components/src/components/OnMessage.js (1)
3-6: OnMessage typedef now correctly references centralized SupportedLanguageThe change to
@typedef {import('../types').SupportedLanguage}matches the shared types module and keeps the handler map and prop typings aligned. Looks good.packages/components/src/components/OnClose.js (1)
3-6: Shared SupportedLanguage typedef correctly adoptedImporting
SupportedLanguagefrom../typeshere aligns the OnClose typings with the centralized definitions and other components. No further adjustments needed.packages/components/src/components/Connect.js (1)
7-10: Connect component now correctly reuses centralized SupportedLanguageThe typedef
@typedef {import('../types').SupportedLanguage}cleanly replaces the inline union and keeps the language‑indexed config and props documentation in sync with the shared type.packages/components/src/components/OnError.js (1)
3-6: OnError typedef centralization is consistent with the rest of the handlersUsing
@typedef {import('../types').SupportedLanguage}here aligns this file with the shared types and other handler components, with no impact on runtime behavior.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/components/src/components/Models.js(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Test generator as dependency with Node 18
- GitHub Check: Acceptance tests for generated templates
- GitHub Check: Test generator as dependency with Node 20
- GitHub Check: Test NodeJS PR - macos-latest
- GitHub Check: Test NodeJS PR - windows-latest
- GitHub Check: Test NodeJS PR - ubuntu-latest
|



Description
This PR eliminates JSDoc typedef duplication by centralizing all type definitions in a shared
types.jsfile.Previously, the same typedefs (Language, SupportedLanguage, Format, QueryParamCodeBlock) were duplicated across 15 component files, causing maintenance overhead and risk of type drift.
Changes:
packages/components/src/types.jsas single source of truth for all shared typedefs@typedef {import('../types').TypeName}syntax instead of inline definitionsindex.jsfor package-level accessTesting:
Related issue(s)
Fixes #1724
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.