import { CodeBlock } from '~/features/ui/CodeBlock/CodeBlock' import Link from 'next/link' import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Heading, } from 'ui' import { ReferenceBetaMarkdown } from './ReferenceBeta.markdown' import { ReferenceBetaPageTemplate } from './ReferenceBeta.pageTemplate' import type { Parameter } from './ReferenceBeta.schema' import { definitionLabels, parameterLabels, referenceBetaHref, type Definition, } from './ReferenceBeta.utils' /** * How parameters are grouped depends on the kind of definition. Methods, * classes, types and constants get a single list; commands and endpoints split * by where the value is passed. */ const PARAMETER_GROUPS: Record = { method: [], class: [], type: [], constant: [], command: [ ['positional', 'Arguments'], ['flag', 'Flags'], ], endpoint: [ ['path', 'Path parameters'], ['query', 'Query parameters'], ['header', 'Headers'], ['body', 'Body'], ], } function groupParameters({ kind, parameters }: Definition['meta']) { if (PARAMETER_GROUPS[kind].length === 0) { const label = kind === 'class' ? 'Constructor parameters' : 'Parameters' return [{ label, parameters }].filter((group) => group.parameters.length > 0) } const known = PARAMETER_GROUPS[kind].map(([location]) => location) return [ ...PARAMETER_GROUPS[kind].map(([location, label]) => ({ label, parameters: parameters.filter((p) => p.location === location), })), { label: 'Other parameters', parameters: parameters.filter((p) => !p.location || !known.includes(p.location)), }, ].filter((group) => group.parameters.length > 0) } const formatValue = (value: unknown) => (typeof value === 'string' ? value : JSON.stringify(value)) type HiddenLabels = ReadonlySet function ParameterList({ parameters, hidden }: { parameters: Parameter[]; hidden: HiddenLabels }) { return ( ) } const slugify = (label: string) => label.toLowerCase().replaceAll(/[^a-z0-9]+/g, '-') const Section = ({ title, children }: { title: string; children: React.ReactNode }) => (
{title} {children}
) /** A single definition: signature, parameters, returns, notes and examples. */ export function ReferenceBetaDefinitionLayout({ definition }: { definition: Definition }) { const { library, meta, content } = definition const hidden: HiddenLabels = new Set(library.meta.hidden_labels) const symbolLabel = meta.symbol && meta.symbol !== meta.title const labels = definitionLabels(meta, hidden) return (
Reference {library.meta.title} {meta.title}

{meta.title}

{meta.summary}

{symbolLabel || labels.length > 0 || meta.since ? (

{symbolLabel && {meta.symbol}} {labels.map((label) => ` ${label}`)} {meta.since && ` since ${meta.since}`}

) : null} } > {meta.description && {meta.description}} {meta.http && ( )} {meta.signature && } {meta.usage && } {meta.requires && meta.requires.length > 0 && (
    {meta.requires.map((requirement) => (
  • {requirement}
  • ))}
)} {meta.auth && (
    {meta.auth.scopes.length > 0 &&
  • OAuth scopes: {meta.auth.scopes.join(', ')}
  • } {meta.auth.permissions.length > 0 && (
  • Token permissions: {meta.auth.permissions.join(', ')}
  • )}
)} {groupParameters(meta).map(({ label, parameters }) => (
))} {meta.properties.length > 0 && (
)} {meta.returns && (

{meta.returns.type}

{meta.returns.description && ( {meta.returns.description} )}
)} {meta.responses && meta.responses.length > 0 && (
    {meta.responses.map((response) => (
  • {response.status} {response.description && ` ${response.description}`}
  • ))}
)} {meta.throws.length > 0 && (
    {meta.throws.map((thrown, i) => (
  • {thrown.type && {thrown.type}} {thrown.description && (thrown.type ? ( ` ${thrown.description}` ) : ( {thrown.description} ))}
  • ))}
)} {content && (
{content}
)} {meta.examples.length > 0 && (
{meta.examples.map((example) => (
{example.title} {example.description && ( {example.description} )} {example.response && ( <>

Response

)}
))}
)}
) }