-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcache-types.cts
58 lines (48 loc) · 1.95 KB
/
cache-types.cts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type {
CacheHandlerValue,
IncrementalCache,
} from 'next/dist/server/lib/incremental-cache/index.js'
import type {
CachedRouteValue,
IncrementalCachedAppPageValue,
IncrementalCacheValue,
} from 'next/dist/server/response-cache/types.js'
export type {
CacheHandler,
CacheHandlerContext,
IncrementalCache,
} from 'next/dist/server/lib/incremental-cache/index.js'
export type NetlifyCachedRouteValue = Omit<CachedRouteValue, 'body'> & {
// Next.js stores body as buffer, while we store it as base64 encoded string
body: string
// Next.js doesn't produce cache-control tag we use to generate cdn cache control
// so store needed values as part of cached response data
revalidate: Parameters<IncrementalCache['set']>[2]['revalidate']
}
export type NetlifyCachedAppPageValue = Omit<IncrementalCachedAppPageValue, 'rscData'> & {
// Next.js stores rscData as buffer, while we store it as base64 encoded string
rscData: string | undefined
revalidate?: Parameters<IncrementalCache['set']>[2]['revalidate']
}
type CachedPageValue = Extract<IncrementalCacheValue, { kind: 'PAGE' }>
export type NetlifyCachedPageValue = CachedPageValue & {
revalidate?: Parameters<IncrementalCache['set']>[2]['revalidate']
}
export type CachedFetchValue = Extract<IncrementalCacheValue, { kind: 'FETCH' }>
export type NetlifyIncrementalCacheValue =
| Exclude<
IncrementalCacheValue,
CachedRouteValue | CachedPageValue | IncrementalCachedAppPageValue
>
| NetlifyCachedRouteValue
| NetlifyCachedPageValue
| NetlifyCachedAppPageValue
type CachedRouteValueToNetlify<T> = T extends CachedRouteValue
? NetlifyCachedRouteValue
: T extends CachedPageValue
? NetlifyCachedPageValue
: T extends IncrementalCachedAppPageValue
? NetlifyCachedAppPageValue
: T
type MapCachedRouteValueToNetlify<T> = { [K in keyof T]: CachedRouteValueToNetlify<T[K]> }
export type NetlifyCacheHandlerValue = MapCachedRouteValueToNetlify<CacheHandlerValue>