refactor: split src/db/queries/ by responsibility — close #406 cluster#411
Merged
Conversation
…server-action files Auth-guard helpers (requireSession / requireUser / requireAdmin) and the API-key request validator (validateApiKey) are HTTP-boundary concerns, not database queries. They were sitting in src/db/queries/ behind a misleading directory name. Relocated next to responses.mjs and methodNotAllowed.mjs: - src/db/queries/_authGuards.mjs → src/shared/utils/api/authGuards.mjs - src/db/queries/validateApiKey.mjs → src/shared/utils/api/validateApiKey.mjs Also removes (without replacement in this commit) the three server-action files that move to feature directories in follow-up commits. Their consumers still reference the old paths through HEAD~1; the next two commits in this branch land the merged feature files and update every consumer in lockstep. Reviewing as a series is cleaner than reviewing each commit standalone. Removed (relocated in commits 2 + 3): - src/db/queries/admin.mjs (7 admin actions → features/admin/actions.mjs) - src/db/queries/api.mjs (3 API key actions → features/account/actions.mjs) - src/db/queries/account.mjs (2 user lifecycle actions → features/account/actions.mjs) Updated importers in this commit (only the two outside the relocation set): - src/features/archives/reseedSeason.mjs (requireAdmin) - src/app/api/h1/rebroadcast/route.js (validateApiKey) Plus two test files and the two docs MDX pages. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…/actions.mjs The 7 admin server actions previously in src/db/queries/admin.mjs (getAllUsers, updateUserRole, toggleUserBan, adminGetUserApiKeys, adminRevokeApiKey, getSystemStats, getAllApiKeys) merge into the existing src/features/admin/actions.mjs alongside sendTestNotification. Each action's logic is byte-for-byte identical — only the file location changed; auth-guard imports now point to the new src/shared/utils/api/authGuards.mjs path. Updates 4 admin component importers + the unit test file. Closes the admin_ac design_coherence finding (admin actions previously split between db/queries/admin.mjs and features/admin/actions.mjs with no clear rule for which goes where). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…features/account/actions.mjs
Merges what was previously two separate server-action files into one
co-located actions module next to the components that call them:
- src/db/queries/api.mjs (3 API-key management actions)
- src/db/queries/account.mjs (2 user lifecycle actions)
↓
src/features/account/actions.mjs
The new file has two clearly-headed sections (API key management /
User data lifecycle). Each action's logic is byte-for-byte identical
— only location changed; auth-guard imports now point to
src/shared/utils/api/authGuards.mjs.
Updates 3 component importers (ApiForm, ApiDashboard, AccountActions)
and 4 test files (2 unit tests still in /unit/queries/ for now, 2
jsx component tests with vi.mock paths updated).
Closes the db_queri high_level_elegance finding (src/db/queries/ now
contains only pure data-access: get*/upsert*/the rebroadcast wire-
format reconstruction).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced May 24, 2026
Open
elfensky
added a commit
that referenced
this pull request
May 24, 2026
…e review (0.51.7) PR #411 (db/queries split) + PR #412 (validator unification) went through a 5-angle code review that surfaced 23 candidates; verification confirmed 23, ranked the 15 most severe, and this branch fixes all 15. Highlights: - Critical: admin Revoke API key button was completely broken (form-action arity mismatch) - 3x TOCTOU races wrapped in db.\$transaction with Serializable isolation - validateApiKey DB outages no longer surface as 401 Unauthorized (now 503) - 4 UI consumers now handle result.errors envelopes explicitly - deleteUserAccount: Zod-validates input, reorders revoke/delete, fires revalidatePath - authGuards.mjs: dropped unnecessary 'use server' RPC surface - docs/data-flow: code samples now use correct .safeParse() form Verification: lint clean, typecheck clean, 1419/1419 unit tests pass, build compiles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the
db-queries-actions-splitcluster from /desloppify (issue #406). Thesrc/db/queries/directory had drifted into a misleading mix of three different concerns behind one label:getCampaign,getCascadeLeaderboard,getCrossSeasonStats,upsertEvent,upsertSeason, ...) — stays.validateApiKey, the auth guards) — moves tosrc/shared/utils/api/.After this PR, each layer lives next to its consumer.
What changed
Boundary helpers →
src/shared/utils/api/src/db/queries/_authGuards.mjssrc/shared/utils/api/authGuards.mjssrc/db/queries/validateApiKey.mjssrc/shared/utils/api/validateApiKey.mjsAdmin server actions →
src/features/admin/actions.mjs(merged)The 7 actions previously in
src/db/queries/admin.mjs(getAllUsers,updateUserRole,toggleUserBan,adminGetUserApiKeys,adminRevokeApiKey,getSystemStats,getAllApiKeys) merge into the existing file alongsidesendTestNotification. The file now has clear section headers (User management / Admin API key management / System overview / Push notifications).Account server actions →
src/features/account/actions.mjs(new, consolidated)Two separate files merge into one new module:
src/db/queries/api.mjs→ API key management section (3 actions)src/db/queries/account.mjs→ User data lifecycle section (2 actions)Updated importers
reseedSeason.mjs,rebroadcast/route.js)/docs/authentication,/docs/database)What's left in
src/db/queries/Pure data-access only:
```
getCampaign.mjs
getCascadeLeaderboard.mjs
getCrossSeasonStats.mjs
getKillsTrend.mjs ← has 'use server' but is a query, called from RSC pages
getPlayersAvg24h.mjs ← ditto
rebroadcast.mjs ← wire-format reconstruction extracted in #409
upsertEvent.mjs
upsertEventProgress.mjs
upsertSeason.mjs
upsertStatistic.mjs
upsertStatus.mjs
```
Behavior changes
None. Pure relocation — every action's logic is byte-for-byte identical. Only file paths and import paths changed.
Verification
npm run lint✅ (0 errors, 2 pre-existing React Compiler warnings)npm run typecheck✅npm run test:unit✅ — 1416 tests pass (133 files)npm run build✅Commits
Branched into 4 logical commits for readability:
shared/utils/api/; remove the three soon-to-be-relocated server-action files (their replacements land in the next two commits)db/queries/admin.mjscontent intofeatures/admin/actions.mjs; update 4 importers + testfeatures/account/actions.mjsfromdb/queries/api.mjs+account.mjs; update 3 importers + 4 tests(Reviewing as a series rather than per-commit is recommended — commits 2-3 fix the orphaned imports temporarily introduced by commit 1, in the same branch.)
Test plan
npm run lintnpm run typechecknpm run test:unitnpm run buildCloses
🤖 Generated with Claude Code