File size: 813 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * `app` -> app dir
 * `pages` -> pages dir
 * `root` -> middleware / instrumentation
 * `assets` -> assets
 */
export type EntryKeyType = 'app' | 'pages' | 'root' | 'assets'
export type EntryKeySide = 'client' | 'server'

// custom type to make sure you can't accidentally use a "generic" string
export type EntryKey =
  `{"type":"${EntryKeyType}","side":"${EntryKeyType}","page":"${string}"}`

/**
 * Get a key that's unique across all entrypoints.
 */
export function getEntryKey(
  type: EntryKeyType,
  side: EntryKeySide,
  page: string
): EntryKey {
  return JSON.stringify({ type, side, page }) as EntryKey
}

/**
 * Split an `EntryKey` up into its components.
 */
export function splitEntryKey(key: EntryKey): {
  type: EntryKeyType
  side: EntryKeySide
  page: string
} {
  return JSON.parse(key)
}