Skip to content

Commit

Permalink
feat(edge): flatten getWithOptions
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

This changes the return shape of `getWithOptions`.
There is no `options` property anymore, all properties
that were previously under `options` can be directly accessed now.
  • Loading branch information
balazsorban44 committed Oct 19, 2022
1 parent 1d27f0c commit 5e4e75a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/next/server/web/spec-extension/cookies.ts
Expand Up @@ -2,10 +2,9 @@ import type { CookieSerializeOptions } from '../types'

import cookie from 'next/dist/compiled/cookie'

type GetWithOptionsOutput = {
export interface Cookie extends CookieSerializeOptions {
/** A `string` representing the value of the cookie. */
value: string | undefined
options: CookieSerializeOptions
}

const normalizeCookieOptions = (options: CookieSerializeOptions) => {
Expand Down Expand Up @@ -72,18 +71,17 @@ export class NextCookies extends Cookies {
get(...args: Parameters<Cookies['get']>) {
return this.getWithOptions(...args).value
}
getAll(): GetWithOptionsOutput[] {
const all: GetWithOptionsOutput[] = []
getAll(): Cookie[] {
const all: Cookie[] = []
for (const key of this.keys()) {
all.push(this.getWithOptions(key))
}
return all
}
getWithOptions(...args: Parameters<Cookies['get']>): GetWithOptionsOutput {
getWithOptions(...args: Parameters<Cookies['get']>): Cookie {
const raw = super.get(...args)
if (typeof raw !== 'string') return { value: raw, options: {} }
const { [args[0]]: value, ...options } = cookie.parse(raw)
return { value, options }
if (typeof raw !== 'string') return { value: raw }
return cookie.parse(raw) as unknown as Cookie
}
set(...args: Parameters<Cookies['set']>) {
const isAlreadyAdded = super.has(args[0])
Expand Down

0 comments on commit 5e4e75a

Please sign in to comment.