File size: 923 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
import { extractInfoFromServerReferenceId } from '../shared/lib/server-reference-info'

// Only contains the properties we're interested in.
export interface ServerReference {
  $$typeof: Symbol
  $$id: string
}

export type ServerFunction = ServerReference &
  ((...args: unknown[]) => Promise<unknown>)

export function isServerReference<T>(
  value: T & Partial<ServerReference>
): value is T & ServerFunction {
  return value.$$typeof === Symbol.for('react.server.reference')
}

export function isUseCacheFunction<T>(
  value: T & Partial<ServerReference>
): value is T & ServerFunction {
  if (!isServerReference(value)) {
    return false
  }

  const { type } = extractInfoFromServerReferenceId(value.$$id)

  return type === 'use-cache'
}

export function isClientReference(mod: any): boolean {
  const defaultExport = mod?.default || mod
  return defaultExport?.$$typeof === Symbol.for('react.client.reference')
}