Conversation
- implement paginate() against the 1-based contract in its test (data/total/ totalPages/page/pageSize), covering partial, out-of-range and empty cases - match uppercase HTTP method in auth public-route allow-list so POST /users is public as intended (was failing closed due to case mismatch) - import badRequest in users route so invalid POSTs return 400, not a 500 - rename User.userName -> username to match API payloads and DB usage across both packages - add types: ["bun-types"] to tsconfig so bun:test and process resolve under tsc --noEmit
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
Fixes all failing tests and eliminates all
tsc --noEmittype errors across theapiandsharedpackages. Bugs spanned both packages plus root config.Before: 9 failing / 13 passing tests, 14 type errors.
After: ✅ 22/22 tests pass,
tsc --noEmitclean (exit 0).Fixes
packages/shared/src/utils/pagination.ts) — implemented thepaginate<T>()stub against the contract in its test: 1-based paging,data/total/totalPages/page/pageSizefields, correct partial-last-page, out-of-range (empty data), and empty-array (totalPages: 0) behaviour.packages/api/src/middleware/auth.ts) — the public-route method allow-list compared against lowercase method names whilec.req.methodis uppercase, soPOST /userswas failing closed (401) instead of being public. Matched the uppercase method. Verified no new bypass: PUT/DELETE/PATCH still require a token.packages/api/src/routes/users.ts) —badRequestwas used but never imported (would throw at runtime); added the import so invalid POSTs return 400 rather than a 500. Also corrected theusernamefield reference (see type alignment below).Usertype (packages/shared/src/types.ts) — renameduserName→usernameto match the API payloads and DB layer.userNamenow appears nowhere in the repo; both packages agree.tsconfig.json) — added"types": ["bun-types"]sobun:testandprocessresolve undertsc --noEmit.@types/nodereaches the compiler transitively via bun-types' internal/// <reference types="node" />.Verification
Constraints honoured
bun-typeswas already in devDependencies).Assumptions & notes
usernamerename went into the shared type (not the tests) because the tests are the fixed point and assertusername.paginate()was implemented to exactly the asserted contract. It has no input guards forpage <= 0/size <= 0— intentional scope-limiting (tests don't exercise it and there is no caller inapitoday). Follow-up recommended: clamp inputs before wiring to user-controlled query params..replace("Bearer ", "")rather than a strict prefix strip, so theBearerscheme is effectively optional. Out of scope — flagging for awareness.