Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up usage of null/undefined #377

Closed
wants to merge 13 commits into from
Closed

clean up usage of null/undefined #377

wants to merge 13 commits into from

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Mar 1, 2024

This standardizes most of our methods to accept both null and undefined, and mostly return a value or undefined. Exceptions that I noticed are canonicalDomain, getPublicSuffix, permuteDomain, and domainMatch, which all return null. I don't remember why I skipped them when I originally did this, so I figured I'd just leave them for now. (I did most of this work a while ago, and evidently never pushed!)

This also introduces a helper type Nullable<T> for readability.

secure: boolean | undefined
httpOnly: boolean | undefined
extensions: string[] | null | undefined
key: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of these props seem to have | undefined, but not actually need it, because none of the cookieDefaults are undefined.

creationIndex: number
hostOnly: boolean | null
pathIsDefault: boolean | null
lastAccessed: Date | 'Infinity' | null
sameSite: string | undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sameSite does actually use undefined to mean "no value". Which is anomalous, but more of a change than I'd want to deal with, here.

Comment on lines +426 to +439
this.key = options.key ?? cookieDefaults.key
this.value = options.value ?? cookieDefaults.value
this.expires = options.expires ?? cookieDefaults.expires
this.maxAge = options.maxAge ?? cookieDefaults.maxAge
this.domain = options.domain ?? cookieDefaults.domain
this.path = options.path ?? cookieDefaults.path
this.secure = options.secure ?? cookieDefaults.secure
this.httpOnly = options.httpOnly ?? cookieDefaults.httpOnly
this.extensions = options.extensions ?? cookieDefaults.extensions
this.creation = options.creation ?? cookieDefaults.creation
this.hostOnly = options.hostOnly ?? cookieDefaults.hostOnly
this.pathIsDefault = options.pathIsDefault ?? cookieDefaults.pathIsDefault
this.lastAccessed = options.lastAccessed ?? cookieDefaults.lastAccessed
this.sameSite = options.sameSite ?? cookieDefaults.sameSite
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TypeScript complains if we use Object.assign, so I just made it all explicit.

@colincasey
Copy link
Contributor

@wjhsf I'm finding this PR a bit too hard to review. Now that we've done most of the major cleanup with the migration to TypeScript I think this would be easier to review as separate, smaller PRs for each of the included changes such as:

  • Clean up cookie creation options
  • Prefer promiseCallback.resolve where possible
  • Introduction and usage of the Nullable type
  • etc.

@wjhsf
Copy link
Contributor Author

wjhsf commented Mar 13, 2024

Replaced by #380 #381.

@wjhsf wjhsf closed this Mar 13, 2024
@wjhsf wjhsf deleted the null-undefined branch March 19, 2024 19:55
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.

None yet

2 participants