import ReactMarkdown from 'react-markdown' import { IconDatabase, Tabs } from 'ui' import CodeBlock from '~/components/CodeBlock/CodeBlock' import Options from '~/components/Options' import Param from '~/components/Params' import RefSubLayout from '~/layouts/ref/RefSubLayout' import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers' import RefDetailCollapse from '~/components/reference/RefDetailCollapse' import { Fragment } from 'react' import { IRefFunctionSection } from './Reference.types' const RefFunctionSection: React.FC = (props) => { const item = props.spec.functions.find((x: any) => x.id === props.funcData.id) // gracefully return nothing if function does not exist if (!item) return <> const hasTsRef = item['$ref'] || null const tsDefinition = hasTsRef && props.typeSpec ? extractTsDocNode(hasTsRef, props.typeSpec) : null const parameters = hasTsRef && tsDefinition ? generateParameters(tsDefinition) : '' const shortText = hasTsRef && tsDefinition ? tsDefinition.signatures[0].comment.shortText : '' return ( <> <>
{shortText && {shortText}}
{item.description && (
{item.description}
)} {item.notes && (
{item.notes}
)} {/* // parameters */} {parameters && (
Parameters
    {parameters.map((param) => { // grab override params from yaml file const overrideParams = item.overrideParams // params from the yaml file can override the params from parameters if it matches the name const overide = overrideParams?.filter((x) => { return param.name === x.name }) const paramItem = overide?.length > 0 ? overide[0] : param return ( {paramItem.subContent && (
    {param.subContent.map((param) => { return ( {param.subContent && ( {param.subContent.map((param) => { return ( ) })} )} ) })}
    )} ) })}
)}
{item.examples && ( <>
{item.examples && item.examples.map((example, exampleIndex) => { const exampleString = '' const codeBlockLang = example?.code?.startsWith('```js') ? 'js' : example?.code?.startsWith('```ts') ? 'ts' : example?.code?.startsWith('```dart') ? 'dart' : example?.code?.startsWith('```c#') ? 'csharp' : 'js' // ` // import { createClient } from '@supabase/supabase-js' // // Create a single supabase client for interacting with your database // const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key') // ` const currentExampleId = example.id const staticExample = item.examples[exampleIndex] const response = staticExample.response const sql = staticExample?.data?.sql const tables = staticExample?.data?.tables return ( {exampleString + (example.code && example.code .replace(/```/g, '') .replace('js', '') .replace('ts', '') .replace('dart', '') .replace('c#', ''))} {((tables && tables.length > 0) || sql) && ( <> {tables && tables.length > 0 && tables.map((table) => { return (
{table.name}
) })} {sql && ( {sql.replace(/sql/g, '').replace(/```/g, '')} )}
)} {response && ( {response.replace(/```/g, '').replace('json', '')} )} {example.description && (
{example.description}
)}
) })}
)}
) } export default RefFunctionSection