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

BREAKING CHANGE: feat(edge): split NextCookies to RequestCookies and ResponseCookies #41526

Merged
merged 74 commits into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
918a55a
feat(edge): add `getAll`, better types for `NextCookies`
balazsorban44 Oct 18, 2022
d638c7a
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 18, 2022
1d27f0c
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 19, 2022
e965fc0
feat(edge): flatten `getWithOptions`
balazsorban44 Oct 19, 2022
990b514
add `name`
balazsorban44 Oct 19, 2022
6f127fa
add `getAll` to `ReadOnlyNextCookies`
balazsorban44 Oct 19, 2022
52e76cd
update tests/docs
balazsorban44 Oct 19, 2022
acc8fa8
do not destructure
balazsorban44 Oct 19, 2022
3f6c20d
revert
balazsorban44 Oct 19, 2022
03b31b0
fix tests
balazsorban44 Oct 19, 2022
a82325c
align `next-codemod` structure with other packages
balazsorban44 Oct 21, 2022
72edcfa
strongly type `next/jest` config
balazsorban44 Oct 21, 2022
c928ef2
simplify test running
balazsorban44 Oct 21, 2022
08e1c47
revert testfixture changes
balazsorban44 Oct 21, 2022
d7e9805
revert textfitures
balazsorban44 Oct 21, 2022
33948f6
prettierignore
balazsorban44 Oct 21, 2022
f905ca2
fix failing tests
balazsorban44 Oct 21, 2022
d42c01e
wip
balazsorban44 Oct 22, 2022
98187ac
alias `NextCookies` with `@edge-runtime/cookies`#ResponseCookies
balazsorban44 Oct 22, 2022
6a9202f
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 22, 2022
c9835d4
fix merge
balazsorban44 Oct 22, 2022
697cb9b
remove unused type export
balazsorban44 Oct 22, 2022
608b960
fix build
balazsorban44 Oct 22, 2022
a1f740a
revert
balazsorban44 Oct 22, 2022
46f24f5
revert
balazsorban44 Oct 22, 2022
6d3d1e3
fix formatting
balazsorban44 Oct 22, 2022
d2d6617
rename
balazsorban44 Oct 22, 2022
21681f9
fix tests
balazsorban44 Oct 22, 2022
5a0195f
use `CookieStore` for `NextCookies`
balazsorban44 Oct 22, 2022
3db6664
revert refactor
balazsorban44 Oct 23, 2022
8c02ab3
`RequestCookies` & `ResponseCookies` instead of `NextCookies`
balazsorban44 Oct 23, 2022
232c32c
rename test file
balazsorban44 Oct 23, 2022
f6b8449
revert jest
balazsorban44 Oct 23, 2022
b3a1c27
document `RequestCookies` and `ResponseCookies`
balazsorban44 Oct 23, 2022
3deeca2
preocmpile cookies
balazsorban44 Oct 24, 2022
9c9ada6
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 24, 2022
32b2dff
lock file
balazsorban44 Oct 24, 2022
bda1b39
fix typos
balazsorban44 Oct 24, 2022
d0e3d98
delete unnecessary tests
balazsorban44 Oct 24, 2022
5a4a18d
revert codemod
balazsorban44 Oct 24, 2022
f905f9c
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 24, 2022
0f9fc7e
fix tests
balazsorban44 Oct 24, 2022
e23bdff
Merge branch 'feat/extend-nextcookies' of github.com:vercel/next.js i…
balazsorban44 Oct 24, 2022
a38627d
remove `ResponseCookies#clear`
balazsorban44 Oct 24, 2022
5492eec
fix test
balazsorban44 Oct 24, 2022
c390ef5
fix test
balazsorban44 Oct 24, 2022
625df69
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 24, 2022
c96fc9a
fix remaining tests
balazsorban44 Oct 24, 2022
f19595c
do not prebundle `@edge-runtime/cookies`
balazsorban44 Oct 24, 2022
907917e
Apply suggestions from code review
balazsorban44 Oct 24, 2022
4010ddd
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 24, 2022
ab15dbc
move log in middleware docs
balazsorban44 Oct 24, 2022
722f77c
Merge branch 'feat/extend-nextcookies' of github.com:vercel/next.js i…
balazsorban44 Oct 24, 2022
0437582
add link to spec
balazsorban44 Oct 24, 2022
075afd5
fix test and types
balazsorban44 Oct 24, 2022
e857d8d
Apply suggestions from code review
balazsorban44 Oct 24, 2022
72b8ec7
upgrae @edge-runtime/cookies
balazsorban44 Oct 24, 2022
267774a
Merge branch 'feat/extend-nextcookies' of github.com:vercel/next.js i…
balazsorban44 Oct 24, 2022
a96d299
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 24, 2022
e62cf63
prebundle `@edge-runtime/cookies`
balazsorban44 Oct 24, 2022
9bcf858
Merge branch 'feat/extend-nextcookies' of github.com:vercel/next.js i…
balazsorban44 Oct 24, 2022
f2ba008
support .has
balazsorban44 Oct 25, 2022
6fd2bfe
bump `@edge-runtime/cookies`
balazsorban44 Oct 25, 2022
c8c64e9
remove .only
balazsorban44 Oct 25, 2022
711b89f
fix test
balazsorban44 Oct 25, 2022
2eede08
use `@edge-runtime/cookies` code directly for now
balazsorban44 Oct 25, 2022
eaa1b22
fix lock file
balazsorban44 Oct 25, 2022
54be68a
fix ts
balazsorban44 Oct 25, 2022
95a4ec5
fix type
balazsorban44 Oct 25, 2022
f7cc401
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 25, 2022
199f28f
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 26, 2022
d7d7fdc
Merge branch 'canary' into feat/extend-nextcookies
balazsorban44 Oct 26, 2022
afc4dd5
Merge branch 'canary' into feat/extend-nextcookies
ijjk Oct 27, 2022
1104720
Merge branch 'canary' into feat/extend-nextcookies
kodiakhq[bot] Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/next/server/web/spec-extension/cookies.ts
Expand Up @@ -3,8 +3,9 @@ import type { CookieSerializeOptions } from '../types'
import cookie from 'next/dist/compiled/cookie'

type GetWithOptionsOutput = {
/** A `string` representing the value of the cookie. */
value: string | undefined
options: { [key: string]: string }
options: CookieSerializeOptions
}

const normalizeCookieOptions = (options: CookieSerializeOptions) => {
Expand Down Expand Up @@ -68,18 +69,23 @@ export class NextCookies extends Cookies {
super(response.headers.get('cookie'))
this.response = response
}
get = (...args: Parameters<Cookies['get']>) => {
get(...args: Parameters<Cookies['get']>) {
return this.getWithOptions(...args).value
}
getWithOptions = (
...args: Parameters<Cookies['get']>
): GetWithOptionsOutput => {
getAll(): GetWithOptionsOutput[] {
const all: GetWithOptionsOutput[] = []
for (const key of this.keys()) {
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
all.push(this.getWithOptions(key))
}
return all
}
getWithOptions(...args: Parameters<Cookies['get']>): GetWithOptionsOutput {
const raw = super.get(...args)
if (typeof raw !== 'string') return { value: raw, options: {} }
const { [args[0]]: value, ...options } = cookie.parse(raw)
return { value, options }
}
set = (...args: Parameters<Cookies['set']>) => {
set(...args: Parameters<Cookies['set']>) {
const isAlreadyAdded = super.has(args[0])

super.set(...args)
Expand Down Expand Up @@ -112,7 +118,7 @@ export class NextCookies extends Cookies {

return this
}
delete = (key: string, options: CookieSerializeOptions = {}) => {
delete(key: string, options: CookieSerializeOptions = {}) {
const isDeleted = super.delete(key)

if (isDeleted) {
Expand All @@ -130,7 +136,7 @@ export class NextCookies extends Cookies {

return isDeleted
}
clear = (options: CookieSerializeOptions = {}) => {
clear(options: CookieSerializeOptions = {}) {
const expiredCookies = Array.from(super.keys())
.map((key) => serializeExpiredCookie(key, options))
.join(', ')
Expand Down
12 changes: 1 addition & 11 deletions packages/next/server/web/types.ts
Expand Up @@ -3,22 +3,12 @@ import type { NextRequest } from '../web/spec-extension/request'
import type { NextFetchEvent } from '../web/spec-extension/fetch-event'
import type { NextResponse } from './spec-extension/response'
import type { ClonableBody } from '../body-streams'
export type { CookieSerializeOptions } from 'next/dist/compiled/cookie'

export interface NodeHeaders {
[header: string]: string | string[] | undefined
}

export interface CookieSerializeOptions {
domain?: string
encode?(val: string): string
expires?: Date
httpOnly?: boolean
maxAge?: number
path?: string
sameSite?: boolean | 'lax' | 'strict' | 'none'
secure?: boolean
}

export interface RequestData {
geo?: {
city?: string
Expand Down