refactor: simplify keyset init and extract duplicated filter helper#720
refactor: simplify keyset init and extract duplicated filter helper#720kamilwronka wants to merge 1 commit intodevelopfrom
Conversation
- verify-jwt.ts: replace mutable `let` + two `if` blocks with a const ternary chain, making the keyset assignment clearer and preventing accidental overwrites - activities-query.service.ts: extract duplicated StringNullableFilter construction into buildNonEmptyNullableFilter() private helper, used by suggestWorlds and suggestClanNames Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughTwo files underwent refactoring: one extracts duplicated Prisma filter-building logic into a private helper method for "suggestWorlds" and "suggestClanNames", and the other simplifies JWT keyset initialization by replacing mutable variable assignments with a const expression. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
packages/api-helpers/src/lib/auth/utils/verify-jwt.ts (1)
11-15: Replace chained ternary withif/else iffor keyset initialization.Line 11 to Line 15 currently use a nested ternary, which hurts readability and conflicts with project style.
Proposed refactor (behavior-preserving)
- const keyset = jwks - ? createLocalJWKSet(jwks) - : jwksUri - ? createRemoteJWKSet(new URL(jwksUri)) - : undefined; + let keyset; + if (jwks) { + keyset = createLocalJWKSet(jwks); + } else if (jwksUri) { + keyset = createRemoteJWKSet(new URL(jwksUri)); + }As per coding guidelines, "Avoid nested (chained) ternary expressions — use early returns or
if/else ifinstead".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/api-helpers/src/lib/auth/utils/verify-jwt.ts` around lines 11 - 15, Replace the nested ternary that initializes keyset with an explicit if/else if block: declare keyset (let keyset = undefined), then if (jwks) set keyset = createLocalJWKSet(jwks), else if (jwksUri) set keyset = createRemoteJWKSet(new URL(jwksUri)); keep the same behavior when neither is present (keyset stays undefined) and update references in verify-jwt.ts accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/api-helpers/src/lib/auth/utils/verify-jwt.ts`:
- Around line 11-15: Replace the nested ternary that initializes keyset with an
explicit if/else if block: declare keyset (let keyset = undefined), then if
(jwks) set keyset = createLocalJWKSet(jwks), else if (jwksUri) set keyset =
createRemoteJWKSet(new URL(jwksUri)); keep the same behavior when neither is
present (keyset stays undefined) and update references in verify-jwt.ts
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 834a8fac-a61b-4307-a84b-c417926af9cb
📒 Files selected for processing (2)
apps/activity/src/activities/services/activities-query.service.tspackages/api-helpers/src/lib/auth/utils/verify-jwt.ts
Summary
let+ twoifblocks with a singleconstternary chain for keyset initialization. This makes the intent clearer and prevents the secondiffrom silently overwriting the first assignment.StringNullableFilterconstruction (used by bothsuggestWorldsandsuggestClanNames) into a privatebuildNonEmptyNullableFilter()helper method.Both changes are behavior-preserving and localized to the same module.
Residual risks
activities.controller.spec.ts(cannot resolve@lootlog/nest-shared) is unrelated — same failure occurs ondevelop.Test plan
api-helperspackage builds successfully🤖 Generated with Claude Code
Summary by CodeRabbit