fix: align parseCookieHeader return type with getAll cookie method#239
Open
TheSeydiCharyyev wants to merge 1 commit into
Open
fix: align parseCookieHeader return type with getAll cookie method#239TheSeydiCharyyev wants to merge 1 commit into
TheSeydiCharyyev wants to merge 1 commit into
Conversation
parseCookieHeader returned an optional value type, which is incompatible with the getAll cookie method (GetAllCookies) that requires a string. This broke the documented server pattern getAll() { return parseCookieHeader(...) }. Normalize the value to a string, mirroring the library's own documentCookieGetAll.
Fixes supabase#115
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.
Description
parseCookieHeaderreturns{ name: string; value?: string }[], but thegetAllcookie method (GetAllCookiesinCookieMethodsServer) requires{ name: string; value: string }[]. As a result, the documented server pattern fails to type-check:Fix
Normalize the value with
?? ""and drop the optional from the return type, soparseCookieHeaderis directly assignable togetAll. This mirrors the library's owndocumentCookieGetAll, which already usesparsed[name] ?? "".For a key returned by
Object.keys(parsed)the value is always a string at runtime, so this is a no-op for normal cookies and normalizes a valueless cookie (a=) to""— consistent withdocumentCookieGetAll. Narrowing the return type fromstring | undefinedtostringis not a breaking change for consumers reading the value.Testing
helpers.spec.tsthat asserts the returned values are strings and thatparseCookieHeadersatisfies theGetAllCookiescontract at compile time (const getAll: GetAllCookies = () => parseCookieHeader("a=b")), so a future regression failstsc.pnpm build(tsc),pnpm test(87 passed),pnpm exec prettier --check,pnpm exec eslint— all pass. Existing snapshots unchanged.Fixes #115