Skip to content

feat: introduce CookiePath nominal type#598

Open
colincasey wants to merge 6 commits into
masterfrom
cookie-path-type
Open

feat: introduce CookiePath nominal type#598
colincasey wants to merge 6 commits into
masterfrom
cookie-path-type

Conversation

@colincasey

Copy link
Copy Markdown
Contributor

Summary

  • Adds a CookiePath branded type and const object with ROOT, parse, parentPath, defaultPath, match, and permute
  • Enforces the RFC 6265 §5.1.4 /-prefix invariant at compile time via a nominal type pattern
  • Purely additive — no changes to existing code

Part 1 of 3 for #582. Stacked on master.

Next: #cookie-path-deprecate-wrappers (deprecates existing wrapper functions)

Comment thread lib/cookie/cookiePath.ts Outdated
Comment thread lib/cookie/cookiePath.ts Outdated
Comment thread lib/cookie/cookiePath.ts Outdated
Comment thread lib/cookie/cookiePath.ts Outdated
Comment thread lib/cookie/cookiePath.ts Outdated
Comment thread lib/cookie/cookiePath.ts Outdated
Comment thread lib/__tests__/cookiePath.spec.ts Outdated
Comment thread lib/__tests__/cookiePath.spec.ts Outdated
Comment thread lib/__tests__/cookiePath.spec.ts
Comment on lines +3 to +6
import { defaultPathCases } from './data/defaultPathCases.js'
import { pathMatchCases } from './data/pathMatchCases.js'
import { permutePathCases } from './data/permutePathCases.js'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird to have some test cases in a file and some inlined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extracted files (defaultPathCases, permutePathCases, pathMatchCases) are the ones shared with the deprecated wrapper specs later in the stack — pulling them into data files lets both the CookiePath.* spec and the defaultPath/pathMatch/permutePath wrapper specs verify against the same corpus. The cases that stay inline (parse, parentPath) are unique to CookiePath and aren't reused, so there was no reason to extract them. I added header comments to each shared file noting this.

@colincasey colincasey marked this pull request as ready for review June 4, 2026 20:02
@colincasey colincasey requested a review from awaterma as a code owner June 4, 2026 20:02
@colincasey colincasey requested a review from wjhsf June 4, 2026 20:03
Replace the `CookiePath` const-object with flat `export function`s and a
`ROOT` const, matching the rest of lib/cookie (defaultPath, pathMatch,
permutePath) and lib/validators. The branded `CookiePath` type is unchanged,
so internal consumers use it via `import * as CookiePath`.

Mark the module `@internal`: CookiePath is a seam for migrating to stronger
types behind the existing loose public API, not a new public surface.

Also simplifies `match` (drops the redundant indexOf/startsWith duplication
while preserving the identical-path early return), tidies `parse`/`permute`,
removes pointless spread copies in the spec, and documents the shared test
fixtures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants