The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
refactor(docs): convert management api reference to app router (#29146)
Charis33ede6f89300
diff --git a/apps/docs/app/reference/[...slug]/page.tsx b/apps/docs/app/reference/[...slug]/page.tsxindex 5859b8f563d..58dcdb621e3 100644--- a/apps/docs/app/reference/[...slug]/page.tsx+++ b/apps/docs/app/reference/[...slug]/page.tsx@@ -1,6 +1,7 @@import { redirect } from 'next/navigation'import { REFERENCES } from '~/content/navigation.references'+import { ApiReferencePage } from '~/features/docs/Reference.apiPage'import { CliReferencePage } from '~/features/docs/Reference.cliPage'import { ClientSdkReferencePage } from '~/features/docs/Reference.sdkPage'import {@@ -23,6 +24,8 @@ export default async function ReferencePage({const parsedPath = parseReferencePath(slug)const isClientSdkReference = parsedPath.__type === 'clientSdk'const isCliReference = parsedPath.__type === 'cli'+ const isApiReference = parsedPath.__type === 'api'+if (isClientSdkReference) {const { sdkId, maybeVersion, path } = parsedPath@@ -35,6 +38,8 @@ export default async function ReferencePage({return <ClientSdkReferencePage sdkId={sdkId} libVersion={version} />} else if (isCliReference) {return <CliReferencePage />+ } else if (isApiReference) {+ return <ApiReferencePage />} else {// Unimplemented -- eventually APIredirect(notFoundLink(slug.join('/')))diff --git a/apps/docs/components/ApiSchema.tsx b/apps/docs/components/ApiSchema.tsxindex 42a5b195566..d7a32797e71 100644--- a/apps/docs/components/ApiSchema.tsx+++ b/apps/docs/components/ApiSchema.tsx@@ -7,21 +7,15 @@ type IParamProps = anyconst ApiSchema = ({ schema, id }: IParamProps) => {const example = sample(schema, { skipReadOnly: true, quiet: true })return (- <Tabs- scrollable- size="small"- type="underlined"- defaultActiveId="example"- queryGroup="response-status"- >- <TabPanel key={`${id}-example`} id="example" label="example">+ <Tabs scrollable size="small" type="underlined" defaultActiveId="example">+ <TabPanel key={`${id ?? ''}-example`} id="example" label="example"><div className="mt-8"><CodeBlock language="bash" className="relative">{JSON.stringify(example, null, 2)}</CodeBlock></div></TabPanel>- <TabPanel key={`${id}-schema`} id="schema" label="schema">+ <TabPanel key={`${id ?? ''}-schema`} id="schema" label="schema"><div className="mt-8"><CodeBlock language="bash" className="relative">{JSON.stringify(schema, null, 2)}diff --git a/apps/docs/content/navigation.references.ts b/apps/docs/content/navigation.references.tsindex 9239014cf15..782255eab1c 100644--- a/apps/docs/content/navigation.references.ts+++ b/apps/docs/content/navigation.references.ts@@ -114,6 +114,7 @@ export const REFERENCES = {api: {type: 'api',name: 'API',+ libPath: 'api',versions: [],icon: 'reference-api',},diff --git a/apps/docs/features/docs/Reference.api.utils.ts b/apps/docs/features/docs/Reference.api.utils.tsnew file mode 100644index 00000000000..1aeaeee85a7--- /dev/null+++ b/apps/docs/features/docs/Reference.api.utils.ts@@ -0,0 +1,177 @@+export interface IApiEndPoint {+ id: string+ path: string+ method: 'get' | 'post' | 'put' | 'delete' | 'patch'+ summary?: string+ description?: string+ parameters: Array<{+ name: string+ required: boolean+ in: 'path' | 'query' | 'body'+ description?: string+ schema: ISchema+ }>+ requestBody?: {+ required: boolean+ content: IApiRequestBody+ }+ responses: {+ [key: string]: {+ description: string+ content?: IApiJsonDTO+ }+ }+ tags?: Array<string>+ security?: Array<ISecurityOption>+}++export type ISchema =+ | ISchemaString+ | ISchemaInteger+ | ISchemaObject+ | ISchemaEnum+ | ISchemaBoolean+ | ISchemaNumber+ | ISchemaArray+ | ISchemaAllOf+ | ISchemaAnyOf+ | ISchemaOneOf++interface ISchemaBase {+ description?: string+ example?: unknown+ deprecated?: boolean+ nullable?: boolean+}++interface ISchemaBoolean extends ISchemaBase {+ type: 'boolean'+}++interface ISchemaInteger extends ISchemaBase {+ type: 'integer'+ minimum?: number+ maximum?: number+}++interface ISchemaNumber extends ISchemaBase {+ type: 'number'+ minimum?: number+ maximum?: number+}++interface ISchemaString extends ISchemaBase {+ type: 'string'+ minLength?: number+ maxLength?: number+ pattern?: string+}++interface ISchemaObject extends ISchemaBase {+ type: 'object'+ properties?: { [key: string]: ISchema }+ additionalProperties?: ISchema+ required?: Array<string>+}++interface ISchemaArray extends ISchemaBase {+ type: 'array'+ items: ISchema+}++interface ISchemaEnum extends ISchemaBase {+ type: string+ enum: Array<unknown>+}++interface ISchemaAllOf extends ISchemaBase {+ allOf: Array<ISchema>+}++interface ISchemaAnyOf extends ISchemaBase {+ anyOf: Array<ISchema>+}++interface ISchemaOneOf extends ISchemaBase {+ oneOf: Array<ISchema>+}++interface IApiRequestBody extends IApiJsonDTO, IApiFormUrlEncodedDTO {}++interface IApiJsonDTO {+ 'application/json': {+ schema: ISchema+ }+}++interface IApiFormUrlEncodedDTO {+ 'application/x-www-form-urlencoded': {+ schema: ISchema+ }+}++type ISecurityOption = IBearerSecurity | IOAuth2Security++interface IBearerSecurity {+ bearer: []+}++interface IOAuth2Security {+ oauth2: Array<'read' | 'write'>+}++export function getTypeDisplayFromSchema(schema: ISchema) {+ if ('allOf' in schema) {+ if (schema.allOf.length === 1) {+ return getTypeDisplayFromSchema(schema.allOf[0])+ } else {+ return {+ displayName: 'all of the following options',+ }+ }+ } else if ('oneOf' in schema) {+ if (schema.oneOf.length === 1) {+ return getTypeDisplayFromSchema(schema.oneOf[0])+ } else {+ return {+ displayName: 'one of the following options',+ }+ }+ } else if ('anyOf' in schema) {+ if (schema.anyOf.length === 1) {+ return getTypeDisplayFromSchema(schema.anyOf[0])+ } else {+ return {+ displayName: 'any of the following options',+ }+ }+ } else if ('enum' in schema) {+ return {+ displayName: 'enum',+ }+ } else if (schema.type === 'boolean') {+ return {+ displayName: 'boolean',+ }+ } else if (schema.type === 'integer') {+ return {+ displayName: 'integer',+ }+ } else if (schema.type === 'number') {+ return {+ displayName: 'number',+ }+ } else if (schema.type === 'string') {+ return {+ displayName: 'string',+ }+ } else if (schema.type === 'array') {+ return {+ displayName: `Array<${getTypeDisplayFromSchema(schema.items).displayName}>`,+ }+ } else if (schema.type === 'object') {+ return {+ displayName: 'object',+ }+ }+}diff --git a/apps/docs/features/docs/Reference.apiPage.tsx b/apps/docs/features/docs/Reference.apiPage.tsxnew file mode 100644index 00000000000..3e77558f3e6--- /dev/null+++ b/apps/docs/features/docs/Reference.apiPage.tsx@@ -0,0 +1,40 @@+import { MenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu'+import { reference_api } from '~/components/Navigation/NavigationMenu/NavigationMenu.constants'+import { ClientLibIntroduction } from '~/features/docs/Reference.introduction'+import { ReferenceNavigation } from '~/features/docs/Reference.navigation'+import { ReferenceContentScrollHandler } from '~/features/docs/Reference.navigation.client'+import { RefSections } from '~/features/docs/Reference.sections'+import { LayoutMainContent } from '~/layouts/DefaultLayout'+import { SidebarSkeleton } from '~/layouts/MainSkeleton'++export async function ApiReferencePage() {+ return (+ <ReferenceContentScrollHandler libPath="api" version="latest" isLatestVersion={true}>+ <SidebarSkeleton+ menuId={MenuId.RefApi}+ NavigationMenu={+ <ReferenceNavigation+ libraryId="api"+ name="Management API"+ menuData={reference_api}+ libPath="api"+ version="latest"+ isLatestVersion={true}+ />+ }+ >+ <LayoutMainContent>+ <article className="@container/article">+ <ClientLibIntroduction+ libPath="api"+ version="latest"+ isLatestVersion={true}+ className="max-w-[unset]"+ />+ <RefSections libraryId="api" version="latest" />+ </article>+ </LayoutMainContent>+ </SidebarSkeleton>+ </ReferenceContentScrollHandler>+ )+}diff --git a/apps/docs/features/docs/Reference.generated.script.ts b/apps/docs/features/docs/Reference.generated.script.tsindex 87678489ea3..3345bd6bd2e 100644--- a/apps/docs/features/docs/Reference.generated.script.ts+++ b/apps/docs/features/docs/Reference.generated.script.ts@@ -9,8 +9,11 @@ import { parseTypeSpec } from '~/features/docs/Reference.typeSpec'import type { AbbrevApiReferenceSection } from '~/features/docs/Reference.utils'import { deepFilterRec } from '~/features/helpers.fn'import type { Json } from '~/features/helpers.types'+import apiCommonSections from '~/spec/common-api-sections.json' assert { type: 'json' }import cliCommonSections from '~/spec/common-cli-sections.json' assert { type: 'json' }import commonClientLibSections from '~/spec/common-client-libs-sections.json' assert { type: 'json' }+import openApiSpec from '~/spec/transforms/api_v1_openapi_deparsed.json' assert { type: 'json' }+import { IApiEndPoint } from './Reference.api.utils'const DOCS_DIRECTORY = join(dirname(fileURLToPath(import.meta.url)), '../..')const SPEC_DIRECTORY = join(DOCS_DIRECTORY, 'spec')@@ -33,6 +36,24 @@ async function parseFnsList(rawSpec: Json): Promise<Array<{ id: unknown }>> {return []}+function mapEndpointsById(spec: typeof openApiSpec): Map<string, IApiEndPoint> {+ const endpoints = spec.paths+ const endpointsById = new Map<string, IApiEndPoint>()++ Object.entries(endpoints).forEach(([path, methods]) => {+ Object.entries(methods).forEach(([method, details]) => {+ endpointsById.set(details.operationId, {+ id: details.operationId,+ path,+ method,+ ...details,+ })+ })+ })++ return endpointsById+}+function genClientSdkSectionTree(fns: Array<{ id: unknown }>, excludeName: string) {const validSections = deepFilterRec(commonClientLibSections as Array<AbbrevApiReferenceSection>,@@ -59,6 +80,15 @@ async function genCliSectionTree() {return validSections}+function genApiSectionTree(endpointsById: Map<string, IApiEndPoint>) {+ const validSections = deepFilterRec(+ apiCommonSections as Array<AbbrevApiReferenceSection>,+ 'items',+ (section) => (section.type === 'operation' ? endpointsById.has(section.id) : true)+ )+ return validSections+}+export function flattenCommonClientLibSections(tree: Array<AbbrevApiReferenceSection>) {return tree.reduce((acc, elem) => {if ('items' in elem) {@@ -89,7 +119,7 @@ async function writeTypes() {)}-async function writeReferenceSections() {+async function writeSdkReferenceSections() {return Promise.all(clientSdkIds.flatMap((sdkId) => {@@ -117,57 +147,103 @@ async function writeReferenceSections() {JSON.stringify(sdkSectionTree))- const cliSectionTree = await genCliSectionTree()- const pendingCliSectionTreeWrite = writeFile(- join(GENERATED_DIRECTORY, 'cli.latest.sections.json'),- JSON.stringify(cliSectionTree)- )-const flattenedSdkSections = flattenCommonClientLibSections(sdkSectionTree)const pendingFlattenedSdkSectionsWrite = writeFile(join(GENERATED_DIRECTORY, `${sdkId}.${version}.flat.json`),JSON.stringify(flattenedSdkSections))- const flattenedCliSections = flattenCommonClientLibSections(cliSectionTree)- const pendingFlattenedCliSectionsWrite = writeFile(- join(GENERATED_DIRECTORY, 'cli.latest.flat.json'),- JSON.stringify(flattenedCliSections)- )-const sdkSectionsBySlug = keyBy(flattenedSdkSections, (section) => section.slug)const pendingSdkSlugDictionaryWrite = writeFile(join(GENERATED_DIRECTORY, `${sdkId}.${version}.bySlug.json`),JSON.stringify(sdkSectionsBySlug))- const cliSectionsBySlug = keyBy(- flattenedCliSections.filter(({ slug }) => !!slug),- (section) => section.slug- )- const pendingCliSlugDictionaryWrite = writeFile(- join(GENERATED_DIRECTORY, 'cli.latest.bySlug.json'),- JSON.stringify(cliSectionsBySlug)- )-return [pendingFnListWrite,pendingSdkSectionTreeWrite,- pendingCliSectionTreeWrite,pendingFlattenedSdkSectionsWrite,- pendingFlattenedCliSectionsWrite,pendingSdkSlugDictionaryWrite,- pendingCliSlugDictionaryWrite,]}))}+async function writeCliReferenceSections() {+ const cliSectionTree = await genCliSectionTree()+ const pendingCliSectionTreeWrite = writeFile(+ join(GENERATED_DIRECTORY, 'cli.latest.sections.json'),+ JSON.stringify(cliSectionTree)+ )++ const flattenedCliSections = flattenCommonClientLibSections(cliSectionTree)+ const pendingFlattenedCliSectionsWrite = writeFile(+ join(GENERATED_DIRECTORY, 'cli.latest.flat.json'),+ JSON.stringify(flattenedCliSections)+ )++ const cliSectionsBySlug = keyBy(+ flattenedCliSections.filter(({ slug }) => !!slug),+ (section) => section.slug+ )+ const pendingCliSlugDictionaryWrite = writeFile(+ join(GENERATED_DIRECTORY, 'cli.latest.bySlug.json'),+ JSON.stringify(cliSectionsBySlug)+ )++ return Promise.all([+ pendingCliSectionTreeWrite,+ pendingFlattenedCliSectionsWrite,+ pendingCliSlugDictionaryWrite,+ ])+}++async function writeApiReferenceSections() {+ const endpointsById = mapEndpointsById(openApiSpec)+ const pendingEndpointsByIdWrite = writeFile(+ join(GENERATED_DIRECTORY, 'api.latest.endpointsById.json'),+ JSON.stringify(Array.from(endpointsById.entries()))+ )++ const apiSectionTree = genApiSectionTree(endpointsById)+ const pendingApiSectionTreeWrite = writeFile(+ join(GENERATED_DIRECTORY, 'api.latest.sections.json'),+ JSON.stringify(apiSectionTree)+ )++ const flattenedApiSections = flattenCommonClientLibSections(apiSectionTree)+ const pendingFlattenedApiSectionsWrite = writeFile(+ join(GENERATED_DIRECTORY, 'api.latest.flat.json'),+ JSON.stringify(flattenedApiSections)+ )++ const apiSectionsBySlug = keyBy(+ flattenedApiSections.filter(({ slug }) => !!slug),+ (section) => section.slug+ )+ const pendingApiSlugDictionaryWrite = writeFile(+ join(GENERATED_DIRECTORY, 'api.latest.bySlug.json'),+ JSON.stringify(apiSectionsBySlug)+ )++ return Promise.all([+ pendingEndpointsByIdWrite,+ pendingApiSectionTreeWrite,+ pendingFlattenedApiSectionsWrite,+ pendingApiSlugDictionaryWrite,+ ])+}+async function run() {try {await mkdir(GENERATED_DIRECTORY, { recursive: true })- await Promise.all([writeTypes(), writeReferenceSections()])+ await Promise.all([+ writeTypes(),+ writeSdkReferenceSections(),+ writeCliReferenceSections(),+ writeApiReferenceSections(),+ ])} catch (err) {console.error(err)}diff --git a/apps/docs/features/docs/Reference.generated.singleton.ts b/apps/docs/features/docs/Reference.generated.singleton.tsindex ede3ac8cb64..99a20756b5d 100644--- a/apps/docs/features/docs/Reference.generated.singleton.ts+++ b/apps/docs/features/docs/Reference.generated.singleton.ts@@ -5,6 +5,7 @@ import { parse } from 'yaml'import type { ModuleTypes } from '~/features/docs/Reference.typeSpec'import type { AbbrevApiReferenceSection } from '~/features/docs/Reference.utils'import { type Json } from '../helpers.types'+import { type IApiEndPoint } from './Reference.api.utils'let typeSpec: Array<ModuleTypes>@@ -47,6 +48,20 @@ export async function getCliSpec() {return cliSpec}+let apiEndpointsById: Map<string, IApiEndPoint>++export async function getApiEndpointById(id: string) {+ if (!apiEndpointsById) {+ const rawJson = await readFile(+ join(process.cwd(), 'features/docs', './generated/api.latest.endpointsById.json'),+ 'utf-8'+ )+ apiEndpointsById = new Map(JSON.parse(rawJson))+ }++ return apiEndpointsById.get(id)+}+const functionsList = new Map<string, Array<{ id: unknown }>>()export async function getFunctionsList(sdkId: string, version: string) {diff --git a/apps/docs/features/docs/Reference.sections.tsx b/apps/docs/features/docs/Reference.sections.tsxindex a241e15cf6b..3581e0f1f06 100644--- a/apps/docs/features/docs/Reference.sections.tsx+++ b/apps/docs/features/docs/Reference.sections.tsx@@ -14,12 +14,16 @@ import { MDXRemoteRefs, getRefMarkdown } from '~/features/docs/Reference.mdx'import { MDXProviderReference } from '~/features/docs/Reference.mdx.client'import type { MethodTypes } from '~/features/docs/Reference.typeSpec'import {+ getApiEndpointById,getCliSpec,getFlattenedSections,getFunctionsList,getTypeSpec,} from '~/features/docs/Reference.generated.singleton'import {+ ApiOperationRequestBodyDetails,+ ApiSchemaParamDetails,+ ApiSchemaParamSubdetails,CollapsibleDetails,FnParameterDetails,RefSubLayout,@@ -30,6 +34,9 @@ import {import type { AbbrevApiReferenceSection } from '~/features/docs/Reference.utils'import { normalizeMarkdown } from '~/features/docs/Reference.utils'import { RefInternalLink } from './Reference.navigation.client'+import { getTypeDisplayFromSchema } from './Reference.api.utils'+import { ApiOperationBodySchemeSelector } from './Reference.ui.client'+import ApiSchema from '~/components/ApiSchema'type RefSectionsProps = {libraryId: string@@ -104,6 +111,8 @@ export function SectionSwitch({ libraryId, version, section }: SectionSwitchProp)case 'cli-command':return <CliCommandSection link={sectionLink} section={section} />+ case 'operation':+ return <ApiEndpointSection link={sectionLink} section={section} />default:console.error(`Unhandled type in reference sections: ${section.type}`)return null@@ -249,6 +258,82 @@ async function CliCommandSection({ link, section }: CliCommandSectionProps) {)}+interface ApiEndpointSectionProps {+ link: string+ section: AbbrevApiReferenceSection+}++async function ApiEndpointSection({ link, section }: ApiEndpointSectionProps) {+ const endpointDetails = await getApiEndpointById(section.id)+ if (!endpointDetails) return null++ const pathParameters = endpointDetails.parameters.filter((param) => param.in === 'path')+ const queryParameters = endpointDetails.parameters.filter((param) => param.in === 'query')++ return (+ <RefSubLayout.Section columns="double" link={link} {...section}>+ <StickyHeader title={endpointDetails.summary} className="col-[1_/_-1]" />+ <div className="flex flex-col gap-12">+ <div className="flex items-center gap-2">+ <span className="font-mono uppercase text-sm whitespace-nowrap bg-foreground text-background rounded-full font-mono font-medium px-2 py-0.5">+ {endpointDetails.method}+ </span>+ <code className="text-foreground-lighter break-all">{endpointDetails.path}</code>+ </div>+ {endpointDetails.description && (+ <ReactMarkdown className="prose break-words mb-8">+ {endpointDetails.description}+ </ReactMarkdown>+ )}+ {pathParameters.length > 0 && (+ <section>+ <h3 className="mb-3 text-base text-foreground">Path parameters</h3>+ <ul>+ {pathParameters.map((param, index) => (+ <ApiSchemaParamDetails key={index} param={param} />+ ))}+ </ul>+ </section>+ )}+ {queryParameters.length > 0 && (+ <section>+ <h3 className="mb-3 text-base text-foreground">Query parameters</h3>+ <ul>+ {queryParameters.map((param, index) => (+ <ApiSchemaParamDetails key={index} param={param} />+ ))}+ </ul>+ </section>+ )}+ {endpointDetails.requestBody && (+ <section>+ <ApiOperationBodySchemeSelector+ requestBody={endpointDetails.requestBody}+ className="mb-3"+ />+ <ApiOperationRequestBodyDetails requestBody={endpointDetails.requestBody} />+ </section>+ )}+ </div>+ {Object.keys(endpointDetails.responses).filter((code) => code.startsWith('2')).length > 0 && (+ <div className="overflow-auto">+ <h3 className="mb-3 text-base text-foreground">Response</h3>+ <ApiSchema+ id={`${section.id}-2xx-response`}+ schema={+ endpointDetails.responses[+ Object.keys(endpointDetails.responses)+ .filter((code) => code.startsWith('2'))+ .sort()[0]+ ].content?.['application/json']?.schema ?? {}+ }+ />+ </div>+ )}+ </RefSubLayout.Section>+ )+}+interface FunctionSectionProps {sdkId: stringversion: stringdiff --git a/apps/docs/features/docs/Reference.ui.client.tsx b/apps/docs/features/docs/Reference.ui.client.tsxindex 7797c35fff3..7be31014d4b 100644--- a/apps/docs/features/docs/Reference.ui.client.tsx+++ b/apps/docs/features/docs/Reference.ui.client.tsx@@ -1,12 +1,22 @@'use client'import type { HTMLAttributes, PropsWithChildren } from 'react'-import { useContext } from 'react'+import { useContext, useEffect, useRef, useState } from 'react'import { useInView } from 'react-intersection-observer'-import { cn } from 'ui'+import {+ cn,+ Select_Shadcn_,+ SelectContent_Shadcn_,+ SelectGroup_Shadcn_,+ SelectItem_Shadcn_,+ SelectTrigger_Shadcn_,+ SelectValue_Shadcn_,+} from 'ui'import { ReferenceContentInitiallyScrolledContext } from '~/features/docs/Reference.navigation.client'+import { type IApiEndPoint } from './Reference.api.utils'+import { API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES } from './Reference.ui.shared'/*** Wrap a reference section with client-side functionality:@@ -49,3 +59,59 @@ export function ReferenceSectionWrapper({</section>)}++export function ApiOperationBodySchemeSelector({+ requestBody,+ className,+}: {+ requestBody: IApiEndPoint['requestBody']+ className?: string+}) {+ const availableSchemes = Object.keys(requestBody.content) as Array<+ 'application/json' | 'application/x-www-form-urlencoded'+ >+ const [selectedScheme, setSelectedScheme] = useState(availableSchemes[0])++ const containerRef = useRef<HTMLDivElement>(null)+ const allSchemeDetails = useRef<HTMLUListElement[]>([])+ useEffect(() => {+ allSchemeDetails.current = Array.from(+ containerRef.current?.querySelectorAll(+ `[${API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES.KEY}]`+ )+ )+ }, [])++ useEffect(() => {+ allSchemeDetails.current?.forEach((schemeDetails) => {+ schemeDetails.hidden =+ schemeDetails.getAttribute(API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES.KEY) !==+ selectedScheme+ })+ }, [selectedScheme])++ return (+ <div ref={containerRef} className={cn('flex items-center justify-between gap-2', className)}>+ <h3 className="text-base text-foreground">Body</h3>+ <Select_Shadcn_+ value={selectedScheme}+ onValueChange={(value) =>+ setSelectedScheme(value as 'application/json' | 'application/x-www-form-urlencoded')+ }+ >+ <SelectTrigger_Shadcn_ className="w-48 [&>span]:w-full [&>span]:truncate">+ <SelectValue_Shadcn_ />+ </SelectTrigger_Shadcn_>+ <SelectContent_Shadcn_>+ <SelectGroup_Shadcn_>+ {availableSchemes.map((scheme) => (+ <SelectItem_Shadcn_ key={scheme} value={scheme}>+ {scheme}+ </SelectItem_Shadcn_>+ ))}+ </SelectGroup_Shadcn_>+ </SelectContent_Shadcn_>+ </Select_Shadcn_>+ </div>+ )+}diff --git a/apps/docs/features/docs/Reference.ui.shared.ts b/apps/docs/features/docs/Reference.ui.shared.tsnew file mode 100644index 00000000000..b0db50fbc8e--- /dev/null+++ b/apps/docs/features/docs/Reference.ui.shared.ts@@ -0,0 +1,5 @@+export const API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES = {+ KEY: 'data-sb-api-reference-request-body-schema',+ VALUE_JSON: 'application/json',+ VALUE_FORM_URLENCODED: 'application/x-www-form-urlencoded',+}diff --git a/apps/docs/features/docs/Reference.ui.tsx b/apps/docs/features/docs/Reference.ui.tsxindex 6631da1f364..3eea44d315b 100644--- a/apps/docs/features/docs/Reference.ui.tsx+++ b/apps/docs/features/docs/Reference.ui.tsx@@ -1,8 +1,14 @@import { isEqual } from 'lodash'import { ChevronRight, XCircle } from 'lucide-react'-import type { PropsWithChildren } from 'react'+import type { HTMLAttributes, PropsWithChildren } from 'react'-import { Collapsible_Shadcn_, CollapsibleContent_Shadcn_, CollapsibleTrigger_Shadcn_, cn } from 'ui'+import {+ Collapsible_Shadcn_,+ CollapsibleContent_Shadcn_,+ CollapsibleTrigger_Shadcn_,+ cn,+ CodeBlock,+} from 'ui'import { MDXRemoteBase } from '~/features/docs/MdxBase'import { MDXRemoteRefs } from '~/features/docs/Reference.mdx'@@ -15,6 +21,10 @@ import type {import { TYPESPEC_NODE_ANONYMOUS } from '~/features/docs/Reference.typeSpec'import { ReferenceSectionWrapper } from '~/features/docs/Reference.ui.client'import { normalizeMarkdown } from '~/features/docs/Reference.utils'+import { getTypeDisplayFromSchema, IApiEndPoint, type ISchema } from './Reference.api.utils'+import { API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES } from './Reference.ui.shared'+import ReactMarkdown from 'react-markdown'+import ApiSchema from '~/components/ApiSchema'interface SectionProps extends PropsWithChildren {link: string@@ -326,6 +336,232 @@ export function RequiredBadge({ isOptional }: { isOptional: boolean | 'NA' }) {) : undefined}+export function ApiSchemaParamDetails({ param }: { param: IApiEndPoint['parameters'][number] }) {+ return (+ <li className="border-t last-of-type:border-b py-5 flex flex-col gap-3">+ <div className="flex flex-wrap items-baseline gap-3">+ <span className="font-mono text-sm font-medium text-foreground break-all">+ {param.name}+ </span>+ <RequiredBadge isOptional={!param.required} />+ {param.schema.deprecated && <span className="text-xs text-warning-600">Deprecated</span>}+ <span className="text-xs text-foreground-muted">+ {getTypeDisplayFromSchema(param.schema).displayName}+ </span>+ </div>+ {param.description && (+ <ReactMarkdown className="prose break-words text-sm">{param.description}</ReactMarkdown>+ )}+ <ApiSchemaParamSubdetails schema={param.schema} />+ </li>+ )+}++export function ApiOperationRequestBodyDetails({+ requestBody,+}: {+ requestBody: IApiEndPoint['requestBody']+}) {+ const availableSchemes = Object.keys(requestBody.content) as Array<+ 'application/json' | 'application/x-www-form-urlencoded'+ >++ return (+ <>+ {availableSchemes.map((scheme, index) => (+ <ApiOperationRequestBodyDetailsInternal+ key={index}+ schema={requestBody.content[scheme].schema}+ hidden={index > 0}+ {...{+ [API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES.KEY]: scheme,+ }}+ />+ ))}+ </>+ )+}++interface ApiOperationRequestBodyDetailsInternalProps extends HTMLAttributes<HTMLUListElement> {+ schema: ISchema+}++function ApiOperationRequestBodyDetailsInternal({+ schema,+ ...props+}: ApiOperationRequestBodyDetailsInternalProps) {+ if ('allOf' in schema) {+ return (+ <>+ <span className="font-mono text-sm font-medium text-foreground">All of the following:</span>+ {schema.allOf.map((option, index) => (+ <ApiSchemaParamSubdetails key={index} schema={option} />+ ))}+ </>+ )+ } else if ('anyOf' in schema) {+ return (+ <>+ <span className="font-mono text-sm font-medium text-foreground">Any of the following:</span>+ {schema.anyOf.map((option, index) => (+ <ApiSchemaParamSubdetails key={index} schema={option} />+ ))}+ </>+ )+ } else if ('oneOf' in schema) {+ return (+ <>+ <span className="font-mono text-sm font-medium text-foreground">One of the following:</span>+ {schema.oneOf.map((option, index) => (+ <ApiSchemaParamSubdetails key={index} schema={option} />+ ))}+ </>+ )+ } else if ('enum' in schema) {+ return (+ <span className="font-mono text-sm font-medium text-foreground">+ {schema.enum.join(' | ')}+ </span>+ )+ } else if (+ schema.type === 'string' ||+ schema.type === 'boolean' ||+ schema.type === 'number' ||+ schema.type === 'integer'+ ) {+ return <span className="font-mono text-sm font-medium text-foreground">{schema.type}</span>+ } else if (schema.type === 'array') {+ return (+ <>+ <span className="font-mono text-sm font-medium text-foreground">{`Array of ${getTypeDisplayFromSchema(schema.items).displayName}`}</span>+ {!(+ 'type' in schema.items &&+ ['string', 'boolean', 'number', 'integer'].includes(schema.items.type)+ ) && <ApiSchemaParamSubdetails className="mt-4" schema={schema.items} />}+ </>+ )+ } else if (schema.type === 'object') {+ return (+ <ul {...props}>+ {Object.keys(schema.properties)+ .map((property) => ({+ name: property,+ required: schema.required?.includes(property),+ in: 'body' as const,+ schema: schema.properties[property],+ }))+ .map((property, index) => (+ <ApiSchemaParamDetails key={index} param={property} />+ ))}+ </ul>+ )+ }+}++export function ApiSchemaParamSubdetails({+ schema,+ className,+}: {+ schema: ISchema+ className?: string+}) {+ if (+ !('enum' in schema) &&+ 'type' in schema &&+ (['boolean', 'number', 'integer'].includes(schema.type) ||+ (schema.type === 'string' &&+ !('minLength' in schema || 'maxLength' in schema || 'pattern' in schema)) ||+ (schema.type === 'array' &&+ 'type' in schema.items &&+ ['boolean', 'number', 'integer', 'string'].includes(schema.items.type)))+ ) {+ return null+ }++ const subContent =+ 'enum' in schema+ ? schema.enum+ : 'type' in schema && schema.type === 'string'+ ? ['minLength', 'maxLength', 'pattern']+ .filter((key) => key in schema)+ .map((key) => ({+ constraint: key,+ value: schema[key],+ }))+ : []++ return (+ <Collapsible_Shadcn_>+ <CollapsibleTrigger_Shadcn_+ className={cn(+ 'group',+ 'w-fit rounded-full',+ 'px-5 py-1',+ 'border border-default',+ 'flex items-center gap-2',+ 'text-left text-sm text-foreground-light',+ 'hover:bg-surface-100',+ 'data-[state=open]:w-full',+ 'data-[state=open]:rounded-b-none data-[state=open]:rounded-tl-lg data-[state=open]:rounded-tr-lg',+ 'transition [transition-property:width,background-color]',+ className+ )}+ >+ <XCircle+ size={14}+ className={cn(+ 'text-foreground-muted',+ 'group-data-[state=closed]:rotate-45',+ 'transition-transform'+ )}+ />+ {'enum' in schema+ ? 'Accepted values'+ : 'allOf' in schema || 'anyOf' in schema || 'oneOf' in schema+ ? 'Options'+ : schema.type === 'array'+ ? 'Items'+ : schema.type === 'object'+ ? 'Object schema'+ : 'Details'}+ </CollapsibleTrigger_Shadcn_>+ <CollapsibleContent_Shadcn_>+ {'type' in schema && schema.type === 'object' ? (+ <div className={cn('border-b border-x border-fault', 'rounded-b-lg', 'p-5')}>+ <ApiSchema schema={schema} />+ </div>+ ) : (+ <ul className={cn('border-b border-x border-default', 'rounded-b-lg')}>+ {subContent.map((detail: any, index: number) => (+ <li+ key={index}+ className={cn(+ 'px-5 py-3',+ 'border-t border-default first:border-t-0',+ 'flex flex-col gap-3'+ )}+ >+ {'enum' in schema ? (+ <span className="font-mono text-sm font-medium text-foreground">+ {String(detail)}+ </span>+ ) : 'type' in schema && schema.type === 'string' ? (+ <span className="text-sm text-foreground flex items-baseline gap-2">+ <span className="font-mono text-sm font-medium text-foreground">+ {detail.constraint}+ </span>+ {detail.value}+ </span>+ ) : null}+ </li>+ ))}+ </ul>+ )}+ </CollapsibleContent_Shadcn_>+ </Collapsible_Shadcn_>+ )+}+/*** Whether the param comes from overwritten params in the library spec file or* directly from the type spec.diff --git a/apps/docs/features/docs/Reference.utils.ts b/apps/docs/features/docs/Reference.utils.tsindex e8d9d046475..1fd053dc805 100644--- a/apps/docs/features/docs/Reference.utils.ts+++ b/apps/docs/features/docs/Reference.utils.ts@@ -26,6 +26,7 @@ export interface AbbrevApiReferenceSection {export function parseReferencePath(slug: Array<string>) {const isClientSdkReference = clientSdkIds.includes(slug[0])const isCliReference = slug[0] === 'cli'+ const isApiReference = slug[0] === 'api'if (isClientSdkReference) {let [sdkId, maybeVersion, maybeCrawlers, ...path] = slug@@ -51,6 +52,11 @@ export function parseReferencePath(slug: Array<string>) {__type: 'cli' as const,path: slug.slice(1),}+ } else if (isApiReference) {+ return {+ __type: 'api' as const,+ path: slug.slice(1),+ }} else {return {__type: 'UNIMPLEMENTED' as const,@@ -91,7 +97,13 @@ export async function generateReferenceStaticParams() {},]- return [...sdkPages, ...cliPages]+ const apiPages = [+ {+ slug: ['api'],+ },+ ]++ return [...sdkPages, ...cliPages, ...apiPages]}export async function generateReferenceMetadata(@@ -103,6 +115,7 @@ export async function generateReferenceMetadata(const parsedPath = parseReferencePath(slug)const isClientSdkReference = parsedPath.__type === 'clientSdk'const isCliReference = parsedPath.__type === 'cli'+ const isApiReference = parsedPath.__type === 'api'if (isClientSdkReference) {const { sdkId, maybeVersion } = parsedPath@@ -144,6 +157,11 @@ export async function generateReferenceMetadata(title: 'CLI Reference | Supabase Docs',description: 'CLI reference for the Supabase CLI',}+ } else if (isApiReference) {+ return {+ title: 'Management API Reference | Supabase Docs',+ description: 'Management API reference for the Supabase API',+ }} else {return {}}diff --git a/apps/docs/middleware.ts b/apps/docs/middleware.tsindex 6bec442e946..7eb4d79e7a6 100644--- a/apps/docs/middleware.ts+++ b/apps/docs/middleware.ts@@ -38,6 +38,11 @@ export function middleware(request: NextRequest) {return NextResponse.rewrite(new URL(rewritePath, request.url))}+ if (lib === 'api') {+ const rewritePath = [REFERENCE_PATH, 'api'].join('/')+ return NextResponse.rewrite(new URL(rewritePath, request.url))+ }+if (clientSdkIds.includes(lib)) {const version = /v\d+/.test(maybeVersion) ? maybeVersion : nullconst rewritePath = [REFERENCE_PATH, lib, version].filter(Boolean).join('/')diff --git a/apps/docs/pages/reference/api/[...slug].tsx b/apps/docs/pages/reference/api/[...slug].tsxdeleted file mode 100644index 5bf710a5713..00000000000--- a/apps/docs/pages/reference/api/[...slug].tsx+++ /dev/null@@ -1,34 +0,0 @@-import { MenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu'-import RefSectionHandler from '~/components/reference/RefSectionHandler'-import { flattenSections } from '~/lib/helpers'-import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths'-import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps'-import { gen_v3 } from '~/lib/refGenerator/helpers'--import apiCommonSections from '~/spec/common-api-sections.json' assert { type: 'json' }-import specFile from '~/spec/transforms/api_v1_openapi_deparsed.json' assert { type: 'json' }--// @ts-ignore-const generatedSpec = gen_v3(specFile, 'wat', { apiUrl: 'apiv0', type: 'mgmt-api' })-const sections = flattenSections(apiCommonSections)-const libraryPath = '/api'--export default function Config(props) {- return (- <RefSectionHandler- menuId={MenuId.RefApi}- sections={sections}- spec={generatedSpec}- pageProps={props}- type="mgmt-api"- />- )-}--export async function getStaticProps() {- return handleRefStaticProps(sections, libraryPath)-}--export async function getStaticPaths() {- return handleRefGetStaticPaths(sections)-}