Skip to content

Commit

Permalink
Clean up cookie creation options.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhsf committed Mar 13, 2024
1 parent f5c4b99 commit 60b0e3f
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/cookie/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@ function fromJSON(str: unknown) {
return c
}

type CreateCookieOptions = Omit<
{
// Assume that all non-method attributes on the class can be configured, except creationIndex.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[K in keyof Cookie as Cookie[K] extends (...args: any[]) => any
? never
: K]?: Cookie[K]
},
'creationIndex'
>

const cookieDefaults = {
// the order in which the RFC has them:
key: '',
Expand All @@ -382,25 +393,7 @@ const cookieDefaults = {
creation: null,
lastAccessed: null,
sameSite: undefined,
}

type CreateCookieOptions = {
key?: string
value?: string
expires?: Date | 'Infinity' | null
maxAge?: number | 'Infinity' | '-Infinity'
domain?: string | null
path?: string | null
secure?: boolean
httpOnly?: boolean
extensions?: string[] | null
creation?: Date | 'Infinity' | null
creationIndex?: number
hostOnly?: boolean | null
pathIsDefault?: boolean | null
lastAccessed?: Date | 'Infinity' | null
sameSite?: string | undefined
}
} as const satisfies Required<CreateCookieOptions>

export class Cookie {
key: string
Expand Down

0 comments on commit 60b0e3f

Please sign in to comment.