The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
type things properly
Jonathan Summers-Muird613f64e65ca
diff --git a/apps/docs/components/Options.tsx b/apps/docs/components/Options.tsxindex b3e9d37e70f..269bca93077 100644--- a/apps/docs/components/Options.tsx+++ b/apps/docs/components/Options.tsx@@ -6,7 +6,13 @@ interface IOptions {name?: string}-const Options: FC<IOptions> = (props) => {+type IOption = AcceptedValue | any++type OptionsSubComponents = {+ Option: IOption+}++const Options: FC<IOptions> & OptionsSubComponents = (props) => {const [open, setOpen] = useState(false)return (<div className="mt-0">@@ -40,8 +46,6 @@ const Options: FC<IOptions> = (props) => {)}-type IOption = AcceptedValue | any-const Option: FC<IOption> = (props) => {return (<div@@ -72,7 +76,6 @@ const Option: FC<IOption> = (props) => {)}-// @ts-ignoreOptions.Option = Optionexport default Optionsdiff --git a/apps/docs/layouts/ref/LibFunctionLayout.tsx b/apps/docs/layouts/ref/LibFunctionLayout.tsxdeleted file mode 100644index 2126cf764fc..00000000000--- a/apps/docs/layouts/ref/LibFunctionLayout.tsx+++ /dev/null@@ -1,3 +0,0 @@-export default function () {- return <div>hello i am a layout</div>-}diff --git a/apps/docs/layouts/ref/RefSubLayout.tsx b/apps/docs/layouts/ref/RefSubLayout.tsxnew file mode 100644index 00000000000..74b06e92576--- /dev/null+++ b/apps/docs/layouts/ref/RefSubLayout.tsx@@ -0,0 +1,36 @@+import { FC } from 'react'++interface ISectionContainer extends FC {+ id: string+}++type RefSubLayoutSubComponents = {+ Section: ISectionContainer+}++type RefSubLayoutType = {}++const RefSubLayout: React.FunctionComponent<RefSubLayoutType> & RefSubLayoutSubComponents = (+ props+) => {+ return (+ <div className="flex my-16">+ <div className="w-full">+ <div className="flex flex-col gap-32 mx-auto max-w-5xl">{props.children}</div>+ </div>+ </div>+ )+}++const Section: FC<ISectionContainer> = (props) => {+ return (+ <div className="grid grid-cols-2 ref-container gap-10" key={props.id} id={props.id}>+ {props.children}+ </div>+ )+}++// @ts-ignore // needs typing with FC type+RefSubLayout.Section = Section++export default RefSubLayoutdiff --git a/apps/docs/pages/new/reference/javascript/[...slug].tsx b/apps/docs/pages/new/reference/javascript/[...slug].tsxindex 4ae1692f297..22db758768f 100644--- a/apps/docs/pages/new/reference/javascript/[...slug].tsx+++ b/apps/docs/pages/new/reference/javascript/[...slug].tsx@@ -32,9 +32,9 @@ 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'-const marginTop = 256-export default function Ref(props) {+export default function JSReference(props) {// const myRef = useRef(null)//console.log('props', props)@@ -43,11 +43,6 @@ export default function Ref(props) {const [offsetY, setOffsetY] = useState(0)const [sections, setSections] = useState([])- // useEffect(() => {- // window.scrollTo(0, 0)- // setOffsetY(0)- // }, [])-useEffect(() => {const els: HTMLElement[] = Array.from(document.querySelectorAll('div.ref-container'))@@ -65,62 +60,9 @@ export default function Ref(props) {setSections(allSections)}, [])- // useEffect(() => {- // if (sections.length <= 1) return-- // const onScroll = () => {- // console.log('SCROLL EVENT')- // setOffsetY(window.pageYOffset)- // }- // window.addEventListener('scroll', debounce(onScroll, 500))-- // return () => window.removeEventListener('scroll', onScroll)- // }, [sections])-- // useEffect(() => {- // if (sections.length === 0) return-- // if (sections.length === 1) {- // sections[0].isActive = true- // return- // }-- // sections.forEach((section, index) => {- // if (index === 0) {- // section.isActive = sections[index + 1].boundingTop > offsetY + marginTop- // } else {- // if (sections[index + 1]) {- // section.isActive =- // sections[index + 1].boundingTop > offsetY + marginTop &&- // sections[index].boundingTop <= offsetY + marginTop- // } else {- // section.isActive = sections[index].boundingTop <= offsetY + marginTop- // }- // }- // })- // }, [sections, offsetY])-- // useEffect(() => {- // const observer = new IntersectionObserver((entries) => {- // // console.log('entries', entries)- // const entry = entries[0]- // // console.log('entry', entry)- // })- // // console.log('myRef', myRef.current)- // observer.observe(myRef.current)- // }, [])-const router = useRouter()function updateUrl(key) {- // router.replace(- // {- // pathname: `/ref/js/${key}`,- // // query: { sortBy: 'price' },- // }- // // undefined,- // // { shallow: true }- // )router.replace({pathname: `/ref/js/${key}`,@@ -132,338 +74,235 @@ export default function Ref(props) {}return (- <div>- <div className="flex my-16">- {/* <div className="px-10 fixed">- {sections.map((x, i) => {- return (- <Link href={`#${x.topic}`} key={i}>- <a- className={[- 'block text-sm hover:text-scale-1200 text-scale-1100 cursor-pointer',- sections && sections[i].isActive ? 'text-brand-900' : 'text-scale-1100',- ].join(' ')}- // key={i}- // onClick={() => {- // window.scrollTo(0, x.boundingTop - marginTop)- // setOffsetY(x.boundingTop - marginTop)- // }}+ <RefSubLayout>+ {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 (+ <RefSubLayout.Section>+ <div className="prose" key={item.id}>+ <header className={['mb-16'].join(' ')}>+ <h2+ className="text-2xl text-scale-1200 capitalize mb-4 scroll-mt-16"+ onClick={() => updateUrl(item.id)}>- {x.topic}- </a>- </Link>- )- })}- </div> */}-- <div className="w-full">- <div- className="flex flex-col gap-32 mx-auto max-w-5xl"- // ref={myRef}- >- {jsSpec.functions.map((item, itemIndex) => {- // if (item['$ref']) console.log('$ref', item['$ref'])- // if (item.id !== 'select()') return <div>hidden section</div>- // const sectionRef = useRef(null)-- // console.log('x', x)- const hasTsRef = item['$ref'] || null- // console.log('hasTsRef', hasTsRef)- // console.log('jsTypeSpec', jsTypeSpec)- const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec)- // console.log('tsDefinition', tsDefinition)- // console.log(`tsDefinition for ${item.title ?? item.id}`, tsDefinition)-- // useEffect(() => {- // const observer = new IntersectionObserver((entries) => {- // // console.log('entries', entries)- // const entry = entries[0]-- // // console.log(- // // x.id,- // // 'intersectiong',- // // entry.isIntersecting,- // // 'visible',- // // entry.isVisible- // // )- // })- // // console.log('myRef', myRef.current)- // observer.observe(sectionRef.current)- // }, [])-- const parameters = hasTsRef ? generateParameters(tsDefinition) : ''-- console.log(`parameters ${item.title}`, parameters)-- // @ts-ignore- // const [serialFunctionMarkdownContent, setSerialFunctionMarkdownContent] =- // useState(null)-- const functionMarkdownContent = props?.docs[itemIndex]?.content-- // useEffect(() => {- // async function makeContent() {- // setSerialFunctionMarkdownContent(- // await serialize(functionMarkdownContent, {- // mdxOptions: {- // remarkPlugins: [remarkGfm],- // format: 'mdx',- // },- // })- // )- // }- // makeContent()- // }, [])-- // console.log('serialFunctionMarkdownContent', serialFunctionMarkdownContent)-- const shortText = hasTsRef ? tsDefinition.signatures[0].comment.shortText : ''-- return (- <div>- <div- className="grid grid-cols-2 ref-container gap-10"- id={item.id}- // ref={sectionRef}- >- <div className="prose" key={item.id}>- <header- className={[- // 'border-b sticky top-16 z-10',- 'mb-16',- ].join(' ')}- >- <h2- className="text-2xl text-scale-1200 capitalize mb-4 scroll-mt-16"- onClick={() => updateUrl(item.id)}- >- {examples.functions[itemIndex].title ??- examples.functions[itemIndex].id ??- item.name ??- item.id}- </h2>- {shortText && (- <>- <p- className="text-sm text-scale-1100"- dangerouslySetInnerHTML={{ __html: shortText }}- ></p>- {/* <ComesFrom+ {examples.functions[itemIndex].title ??+ examples.functions[itemIndex].id ??+ item.name ??+ item.id}+ </h2>+ {shortText && (+ <>+ <p+ className="text-sm text-scale-1100"+ dangerouslySetInnerHTML={{ __html: shortText }}+ ></p>+ {/* <ComesFromlink="https://raw.githubusercontent.com/supabase/supabase/master/spec/enrichments/tsdoc_v2/combined.json"text="combined.json"/> */}- </>- )}- </header>+ </>+ )}+ </header>- {item.description && (- <>- {/* <ComesFrom+ {item.description && (+ <>+ {/* <ComesFromlink="https://raw.githubusercontent.com/supabase/supabase/master/spec/enrichments/tsdoc_v2/combined.json"text="combined.json"/> */}- <p className="text-sm">{item.description}</p>- </>- )}- {functionMarkdownContent && (- <>- {/* <ComesFrom+ <p className="text-sm">{item.description}</p>+ </>+ )}+ {functionMarkdownContent && (+ <>+ {/* <ComesFromlink="https://github.com/supabase/supabase/pull/10095/files#diff-bf42aab7d324c5330e4ae65d94803cd6da686d2241015536b0263e7f76aeca35"text="auth.signUp().mdx"/> */}- <MDXRemote {...functionMarkdownContent} components={components} />- </>- )}- {item.notes && (- <div>- {/* <ComesFrom+ <MDXRemote {...functionMarkdownContent} components={components} />+ </>+ )}+ {item.notes && (+ <div>+ {/* <ComesFromlink="https://github.com/supabase/supabase/blob/master/spec/supabase_js_v2.yml#L105"text="supabase_js_v2"/> */}- <ReactMarkdown className="text-sm">{item.notes}</ReactMarkdown>- </div>- )}- {/* // parameters */}- {parameters && (- <div className="not-prose mt-12">- {/* <ComesFrom+ <ReactMarkdown className="text-sm">{item.notes}</ReactMarkdown>+ </div>+ )}+ {/* // parameters */}+ {parameters && (+ <div className="not-prose mt-12">+ {/* <ComesFromlink="https://github.com/supabase/supabase/blob/master/spec/enrichments/tsdoc_v2/combined.json"text="combined.json"/> */}- <h5 className="mb-3 text-base">Parameters</h5>- <ul className="">- {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 (- <Param {...paramItem}>- {paramItem.subContent && (- <div className="mt-3">- <Options>- {param.subContent.map((param) => {- return <Options.Option {...param} />- })}- </Options>- </div>- )}- </Param>- )- })}- </ul>- {/* <div dangerouslySetInnerHTML={{ __html: parameters }}></div> */}- </div>- )}- </div>- <div className="w-full">- <div className="sticky top-24">- {item.examples && (- <>- {' '}- <ComesFrom- className="mb-5"- link="https://github.com/supabase/supabase/blob/master/spec/supabase_js_v2.yml"- text="supabase_js_v2"- />- <Tabs- defaultActiveId={item.examples[0].id}- size="small"- type="underlined"- scrollable- >- {item.examples &&- item.examples.map((example, exampleIndex) => {- const exampleString = `+ <h5 className="mb-3 text-base">Parameters</h5>+ <ul className="">+ {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 (+ <Param {...paramItem}>+ {paramItem.subContent && (+ <div className="mt-3">+ <Options>+ {param.subContent.map((param) => {+ return <Options.Option {...param} />+ })}+ </Options>+ </div>+ )}+ </Param>+ )+ })}+ </ul>+ {/* <div dangerouslySetInnerHTML={{ __html: parameters }}></div> */}+ </div>+ )}+ </div>+ <div className="w-full">+ <div className="sticky top-24">+ {item.examples && (+ <>+ {' '}+ <ComesFrom+ className="mb-5"+ link="https://github.com/supabase/supabase/blob/master/spec/supabase_js_v2.yml"+ text="supabase_js_v2"+ />+ <Tabs+ defaultActiveId={item.examples[0].id}+ size="small"+ type="underlined"+ scrollable+ >+ {item.examples &&+ item.examples.map((example, exampleIndex) => {+ const exampleString = `import { createClient } from '@supabase/supabase-js'// Create a single supabase client for interacting with your databaseconst 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+ const currentExampleId = example.id+ const staticExample = item.examples[exampleIndex]++ const response = staticExample.response+ const sql = staticExample?.data?.sql+ const tables = staticExample?.data?.tables++ return (+ <Tabs.Panel id={example.id} label={example.name}>+ {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 (- <Tabs.Panel id={example.id} label={example.name}>- {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 (- <div className="bg-scale-300 border rounded prose max-w-none">- <div className="bg-scale-200 px-5 py-2">- <div className="flex gap-2 items-center">- <div className="text-brand-900">- <IconDatabase size={16} />- </div>- <h5 className="text-xs text-scale-1200">- {table.name}- </h5>- </div>- </div>-- {/* <ReactMarkdown>{table.content}</ReactMarkdown> */}- {/* {content && <MDXRemote {...content} />} */}- </div>- )- })}- {sql && (- <CodeBlock- className="useless-code-block-class"- language="sql"- hideLineNumbers={true}- >- {sql}- </CodeBlock>- )}- <CodeBlock- className="useless-code-block-class"- language="js"- hideLineNumbers={true}- >- {exampleString +- (example.code &&- example.code- .replace('```', '')- .replace('js', '')- .replace('```', ''))}- </CodeBlock>- {response && (- <>- <ComesFrom- className="mb-5 mt-5"- link="https://github.com/supabase/supabase/pull/10095/files#diff-c514c66b77772b9e3d9a5403c136ee52dfeaaeacb1d8138ea85ce35ee64e5006"- text="examples.yml"- />- <CodeBlock- className="useless-code-block-class"- language="json"- hideLineNumbers={true}- >- {response}- </CodeBlock>- </>- )}- </Tabs.Panel>+ <div className="bg-scale-300 border rounded prose max-w-none">+ <div className="bg-scale-200 px-5 py-2">+ <div className="flex gap-2 items-center">+ <div className="text-brand-900">+ <IconDatabase size={16} />+ </div>+ <h5 className="text-xs text-scale-1200">{table.name}</h5>+ </div>+ </div>++ {/* <ReactMarkdown>{table.content}</ReactMarkdown> */}+ {/* {content && <MDXRemote {...content} />} */}+ </div>)})}- </Tabs>- </>- )}- </div>- </div>- </div>- </div>- )- })}- </div>- </div>- </div>- </div>+ {sql && (+ <CodeBlock+ className="useless-code-block-class"+ language="sql"+ hideLineNumbers={true}+ >+ {sql}+ </CodeBlock>+ )}+ <CodeBlock+ className="useless-code-block-class"+ language="js"+ hideLineNumbers={true}+ >+ {exampleString ++ (example.code &&+ example.code+ .replace('```', '')+ .replace('js', '')+ .replace('```', ''))}+ </CodeBlock>+ {response && (+ <>+ <ComesFrom+ className="mb-5 mt-5"+ link="https://github.com/supabase/supabase/pull/10095/files#diff-c514c66b77772b9e3d9a5403c136ee52dfeaaeacb1d8138ea85ce35ee64e5006"+ text="examples.yml"+ />+ <CodeBlock+ className="useless-code-block-class"+ language="json"+ hideLineNumbers={true}+ >+ {response}+ </CodeBlock>+ </>+ )}+ </Tabs.Panel>+ )+ })}+ </Tabs>+ </>+ )}+ </div>+ </div>+ </RefSubLayout.Section>+ )+ })}+ </RefSubLayout>)}export async function getStaticProps({ params }: { params: { slug: string[] } }) {- /**- * This is our collection of human readable titles and IDs- */- let markdownDocs = [- {- title: 'Inserting data',- id: 'select()',- },- { title: 'Deleting data', id: 'delete()' },- ]-const pages = jsSpec.functions.map((x) => x.id)// console.log('pages', pages)