import { useEffect, // useRef, useState, } from 'react' // pages/index.js import fs from 'fs' import matter from 'gray-matter' import { MDXRemote } from 'next-mdx-remote' import { serialize } from 'next-mdx-remote/serialize' import remarkGfm from 'remark-gfm' import components from '~/components/index' import { getAllDocs } from '~/lib/docs' import ReactMarkdown from 'react-markdown' // @ts-ignore import jsTypeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' // @ts-ignore import examples from '~/../../spec/examples/examples.yml' assert { type: 'yml' } // @ts-expect-error import jsSpec from '~/../../spec/supabase_js_v2_temp_new_shape.yml' assert { type: 'yml' } import { IconDatabase, Tabs } from 'ui' import CodeBlock from '~/components/CodeBlock/CodeBlock' import { useRouter } from 'next/router' import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers' import { ComesFrom } from '~/components/ComesFrom' import Link from 'next/link' import Param from '~/components/Params' import Options from '~/components/Options' import RefSubLayout from '~/layouts/ref/RefSubLayout' export default function JSReference(props) { // const myRef = useRef(null) //console.log('props', props) // console.log({ jsSpec }) const [offsetY, setOffsetY] = useState(0) const [sections, setSections] = useState([]) useEffect(() => { const els: HTMLElement[] = Array.from(document.querySelectorAll('div.ref-container')) const allSections = els.map((el: HTMLElement, index: number) => { const { top: boundingTop } = el.getBoundingClientRect() return { topic: el.getAttribute('id')!, boundingTop, isActive: index === 0, } }) // console.log('allSections', allSections) setSections(allSections) }, []) const router = useRouter() function updateUrl(key) { router.replace( { pathname: `/ref/js/${key}`, // query: { sortBy: 'price' }, }, undefined, { scroll: false } ) } return ( {jsSpec.functions.map((item, itemIndex) => { const hasTsRef = item['$ref'] || null const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec) const parameters = hasTsRef ? generateParameters(tsDefinition) : '' // console.log(`parameters ${item.title}`, parameters) const functionMarkdownContent = props?.docs[itemIndex]?.content const shortText = hasTsRef ? tsDefinition.signatures[0].comment.shortText : '' return ( <> <>
{/*

updateUrl(item.id)} > {examples.functions[itemIndex].title ?? examples.functions[itemIndex].id ?? item.name ?? item.id}

*/} {shortText && ( <>

{/* */} )}
{item.description && (
{/* */}

{item.description}

)} {functionMarkdownContent && (
{/* */}
)} {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 })}
    )} ) })}
{/*
*/}
)}
{item.examples && ( <> {' '} {item.examples && item.examples.map((example, exampleIndex) => { const exampleString = ` 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 ( {tables && tables.length > 0 && tables.map((table) => { // console.log(table) // @ts-ignore // const [content, setContent] = useState(null) // // @ts-ignore // useEffect(() => { // async function makeContent() { // setContent( // await serialize(table.content, { // mdxOptions: { // remarkPlugins: [remarkGfm], // format: 'mdx', // }, // }) // ) // } // makeContent() // }, []) return (
{table.name}
{/* {table.content} */} {/* {content && } */}
) })} {sql && ( {sql} )} {exampleString + (example.code && example.code .replace('```', '') .replace('js', '') .replace('```', ''))} {response && ( <> {response} )}
) })}
)}
) })}
) } export async function getStaticProps({ params }: { params: { slug: string[] } }) { const pages = jsSpec.functions.map((x) => x.id) // console.log('pages', pages) /** * Read all the markdown files that might have * - custom text * - call outs * - important notes regarding implementation */ const allMarkdownDocs = await Promise.all( pages.map(async (x, i) => { // const doc = getDocsBySlug(`docs/ref/database/${x}`) // if (i >= 5) return null const pathName = `docs/ref/js/${x}.mdx` function checkFileExists(x) { // console.log('checking this ', x) if (fs.existsSync(x)) { return true } else { return false } } const markdownExists = checkFileExists(pathName) console.log(x, 'markdownExists', markdownExists) const fileContents = markdownExists ? fs.readFileSync(pathName, 'utf8') : '' const { data, content } = matter(fileContents) // console.log('docBySlug', content) // console.log() // if (content) console.log(content) return { id: x, title: x, // ...content, meta: data, content: content ? await serialize(content || '') : null, } }) ) // console.log('allMarkdownDocs', allMarkdownDocs) return { props: { docs: allMarkdownDocs, }, } } export function getStaticPaths() { let docs = getAllDocs() return { paths: docs.map(() => { return { params: { slug: docs.map((d) => d.slug), }, } }), fallback: 'blocking', } }