Initial work on database.new visualizer (#19027)

* Initial commit.

* Remove bunch of unneeded deps.

* Fix the providers.

* Minor fixes to make the themes work.

* Fix prettier errors.

* Add default constraint.

* Midway styling

* General styling improvements

* More styling stuff

* Bit more styling

* Bit more pizzazz

* Scaffold all threads modal

* Small style fix

* Ensure loading state persist in new page until redirect

* Fix

* Test';

* Add basic validation

* Fix

* Remove console logs

* Hide show all threads button

* chore: style the blocks

* fix: stroke width

* add some shadow

* stroke width

* Update TableNode.tsx

* Swap hide chat for hide code

* more sidebar styling

* Resolve conflicts

* Some style fixeds

* Some style fixeds

* mock profile

* update user dorpdown

* Update globals.css

* Chore/db new layouts and url params (#19142)

* chore: layouts

* Fix + clean up

---------

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>

* Fix header

* Scaffold profile and conversations

* Some quick styling

* Update apps/database-new/.env.local.example

Co-authored-by: Greg Richardson <greg.nmr@gmail.com>

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Greg Richardson <greg.nmr@gmail.com>
This commit is contained in:
Ivan Vasilov
2023-11-22 17:01:32 +01:00
committed by GitHub
parent 3fef9c8f8c
commit fbfe910c22
82 changed files with 10148 additions and 8285 deletions

View File

@@ -2,3 +2,4 @@
# https://app.supabase.com/project/_/settings/api
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
OPENAI_API_KEY=your-openai-api-key

View File

@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}

View File

@@ -4,7 +4,6 @@
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
# testing
/coverage

View File

@@ -1,93 +1,5 @@
<a href="https://demo-nextjs-with-supabase.vercel.app/">
<img alt="Next.js and Supabase Starter Kit - the fastest way to build apps with Next.js and Supabase" src="https://demo-nextjs-with-supabase.vercel.app/opengraph-image.png">
<h1 align="center">Next.js and Supabase Starter Kit</h1>
</a>
# database.new
<p align="center">
The fastest way to build apps with Next.js and Supabase
</p>
## Overview
<p align="center">
<a href="#features"><strong>Features</strong></a> ·
<a href="#demo"><strong>Demo</strong></a> ·
<a href="#deploy-to-vercel"><strong>Deploy to Vercel</strong></a> ·
<a href="#clone-and-run-locally"><strong>Clone and run locally</strong></a> ·
<a href="#feedback-and-issues"><strong>Feedback and issues</strong></a>
<a href="#more-supabase-examples"><strong>More Examples</strong></a>
</p>
<br/>
## Features
- Works across the entire [Next.js](https://nextjs.org) stack
- App Router
- Pages Router
- Middleware
- Client
- Server
- It just works!
- supabase-ssr. A package to configure Supabase Auth to use cookies
- Styling with [Tailwind CSS](https://tailwindcss.com)
- Optional deployment with [Supabase Vercel Integration and Vercel deploy](#deploy-your-own)
- Environment variables automatically assigned to Vercel project
## Demo
You can view a fully working demo at [demo-nextjs-with-supabase.vercel.app](https://demo-nextjs-with-supabase.vercel.app/).
## Deploy to Vercel
Vercel deployment will guide you through creating a Supabase account and project.
After installation of the Supabase integration, all relevant environment variables will be assigned to the project so the deployment is fully functioning.
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&project-name=nextjs-with-supabase&repository-name=nextjs-with-supabase&demo-title=nextjs-with-supabase&demo-description=This%20starter%20configures%20Supabase%20Auth%20to%20use%20cookies%2C%20making%20the%20user's%20session%20available%20throughout%20the%20entire%20Next.js%20app%20-%20Client%20Components%2C%20Server%20Components%2C%20Route%20Handlers%2C%20Server%20Actions%20and%20Middleware.&demo-url=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2F&external-id=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&demo-image=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2Fopengraph-image.png&integration-ids=oac_VqOgBHqhEoFTPzGkPd7L0iH6)
The above will also clone the Starter kit to your GitHub, you can clone that locally and develop locally.
If you wish to just develop locally and not deploy to Vercel, [follow the steps below](#clone-and-run-locally).
## Clone and run locally
1. You'll first need a Supabase project which can be made [via the Supabase dashboard](https://database.new)
2. Create a Next.js app using the Supabase Starter template npx command
```bash
npx create-next-app -e with-supabase
```
3. Use `cd` to change into the app's directory
```bash
cd name-of-new-app
```
4. Rename `.env.local.example` to `.env.local` and update the following:
```
NEXT_PUBLIC_SUPABASE_URL=[INSERT SUPABASE PROJECT URL]
NEXT_PUBLIC_SUPABASE_ANON_KEY=[INSERT SUPABASE PROJECT API ANON KEY]
```
Both `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY` can be found in [your Supabase project's API settings](https://app.supabase.com/project/_/settings/api)
5. You can now run the Next.js local development server:
```bash
npm run dev
```
The starter kit should now be running on [localhost:3000](http://localhost:3000/).
> Check out [the docs for Local Development](https://supabase.com/docs/guides/getting-started/local-development) to also run Supabase locally.
## Feedback and issues
Please file feedback and issues over on the [Supabase GitHub org](https://github.com/supabase/supabase/issues/new/choose).
## More Supabase examples
- [Next.js Subscription Payments Starter](https://github.com/vercel/nextjs-subscription-payments)
- [Cookie-based Auth and the Next.js 13 App Router (free course)](https://youtube.com/playlist?list=PL5S4mPUpp4OtMhpnp93EFSo42iQ40XjbF)
- [Supabase Auth and the Next.js App Router](https://github.com/supabase/supabase/tree/master/examples/auth/nextjs)
This site will host a tool for designing SQL schemas.

View File

@@ -0,0 +1,66 @@
'use client'
import { last, sortBy } from 'lodash'
import { useParams, useRouter } from 'next/navigation'
import { useEffect, useMemo, useRef, useState } from 'react'
import { CodeEditor } from '@/components/CodeEditor/CodeEditor'
import SchemaGraph from '@/components/SchemaGraph/SchemaGraph'
import { useMessagesQuery } from '@/data/messages-query'
import { AssistantMessage, PostgresTable } from '@/lib/types'
import { parseTables } from '@/lib/utils'
export default function ThreadPage() {
const router = useRouter()
const { threadId, runId, messageId }: { threadId: string; runId: string; messageId: string } =
useParams()
const [tables, setTables] = useState<PostgresTable[]>([])
const { data, isSuccess } = useMessagesQuery({ threadId, runId })
// [Joshen] Slightly hacky here, just so the useEffect triggers once - until we figure out something better
const isLoadingPrev = useRef<boolean>(false)
const isLoading = isSuccess && data.status === 'loading'
const messages = useMemo(() => {
if (isSuccess) return sortBy(data.messages, (m) => m.created_at)
return []
}, [data?.messages, isSuccess])
const userMessages = messages.filter((m) => m.role === 'user')
const selectedMessageIdx = useMemo(() => {
return messages.findIndex((m) => m.id === messageId)
}, [messages, messageId])
const selectedMessageReply = useMemo(
() =>
(selectedMessageIdx !== -1 ? messages[selectedMessageIdx + 1] : undefined) as
| AssistantMessage
| undefined,
[messages, selectedMessageIdx]
)
const content = useMemo(
() => selectedMessageReply?.sql.replaceAll('```sql', '').replaceAll('```', '') || '',
[selectedMessageReply?.sql]
)
useEffect(() => {
parseTables(content).then((t) => setTables(t))
}, [content])
useEffect(() => {
if (isLoadingPrev.current && !isLoading) {
const latestMessage = last(userMessages)
if (latestMessage) router.push(`/${threadId}/${runId}/${latestMessage.id}`)
}
isLoadingPrev.current = isLoading
}, [isLoading])
return (
<div className="grow max-h-screen flex flex-row items-center justify-between bg-alternative h-full">
<SchemaGraph tables={tables} />
<CodeEditor content={content} />
</div>
)
}

View File

@@ -0,0 +1,34 @@
'use client'
import { last, sortBy } from 'lodash'
import { useParams, useRouter } from 'next/navigation'
import { useEffect, useMemo } from 'react'
import { CodeEditor } from '@/components/CodeEditor/CodeEditor'
import SchemaGraph from '@/components/SchemaGraph/SchemaGraph'
import { useMessagesQuery } from '@/data/messages-query'
export default function ThreadPage() {
const router = useRouter()
const { threadId, runId }: { threadId: string; runId: string } = useParams()
const { data, isSuccess } = useMessagesQuery({ threadId, runId })
const messages = useMemo(() => {
if (isSuccess) return sortBy(data.messages, (m) => m.created_at)
return []
}, [data?.messages, isSuccess])
useEffect(() => {
if (isSuccess && messages.length > 0) {
const latestMessage = last(messages.filter((message) => message.role === 'user'))
if (latestMessage) router.push(`/${threadId}/${runId}/${latestMessage.id}`)
}
}, [isSuccess])
return (
<div className="grow max-h-screen flex flex-row items-center justify-between bg-alternative h-full">
<SchemaGraph tables={[]} />
<CodeEditor content="" />
</div>
)
}

View File

@@ -0,0 +1,11 @@
'use client'
import { Chat } from '@/components/Chat/Chat'
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div className="flex flex-row items-center justify-between bg-alternative h-full">
<Chat />
{children}
</div>
)
}

View File

@@ -0,0 +1,50 @@
// import { parseTables } from '@/lib/utils'
import { compact } from 'lodash'
import OpenAI from 'openai'
const openai = new OpenAI()
export async function GET(
req: Request,
{ params }: { params: { threadId: string; runId: string } }
) {
const [run, { data: messages }] = await Promise.all([
openai.beta.threads.runs.retrieve(params.threadId, params.runId),
openai.beta.threads.messages.list(params.threadId),
])
const mappedMessages = compact(
await Promise.all(
messages.map(async (m) => {
if (m.role === 'user' && m.content[0].type === 'text') {
return {
id: m.id,
role: 'user' as const,
created_at: m.created_at,
text: m.content[0].text.value,
}
}
if (m.content.length >= 1 && m.content[0].type === 'text') {
let sql = ''
if (m.content[0].type === 'text') {
sql = m.content[0].text.value.replaceAll('\n', '')
}
return {
id: m.id,
role: 'assistant' as const,
created_at: m.created_at,
sql,
}
}
})
)
)
const result = {
id: params.threadId,
status: run.status === 'completed' ? 'completed' : 'loading',
messages: mappedMessages,
}
return Response.json(result)
}

View File

@@ -0,0 +1,22 @@
import OpenAI from 'openai'
const openai = new OpenAI()
export async function POST(req: Request, { params }: { params: { threadId: string } }) {
if (!req.body) {
return Response.error()
}
const { prompt } = await req.json()
const message = await openai.beta.threads.messages.create(params.threadId, {
content: prompt,
role: 'user',
})
const run = await openai.beta.threads.runs.create(message.thread_id, {
assistant_id: 'asst_oLWrK8lScZVNEpfjwUIvBAnq',
})
return Response.json({ threadId: message.thread_id, runId: run.id })
}

View File

@@ -0,0 +1,24 @@
import OpenAI from 'openai'
const openai = new OpenAI()
export async function POST(req: Request) {
if (!req.body) {
return Response.error()
}
const { prompt } = await req.json()
const thread = await openai.beta.threads.create()
await openai.beta.threads.messages.create(thread.id, {
role: 'user',
content: prompt,
})
const run = await openai.beta.threads.runs.create(thread.id, {
assistant_id: 'asst_oLWrK8lScZVNEpfjwUIvBAnq',
})
return Response.json({ threadId: thread.id, runId: run.id })
}

View File

@@ -1,20 +0,0 @@
import { createClient } from '@/utils/supabase/server'
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
export async function GET(request: Request) {
// The `/auth/callback` route is required for the server-side auth flow implemented
// by the Auth Helpers package. It exchanges an auth code for the user's session.
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-sign-in-with-code-exchange
const requestUrl = new URL(request.url)
const code = requestUrl.searchParams.get('code')
if (code) {
const cookieStore = cookies()
const supabase = createClient(cookieStore)
await supabase.auth.exchangeCodeForSession(code)
}
// URL to redirect to after sign in process completes
return NextResponse.redirect(requestUrl.origin)
}

View File

@@ -2,41 +2,141 @@
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 200 20% 98%;
--btn-background: 200 10% 91%;
--btn-background-hover: 200 10% 89%;
--foreground: 200 50% 3%;
}
@import '~ui/build/css/source/global.css';
@import '~ui/build/css/themes/dark.css';
@import '~ui/build/css/themes/light.css';
@media (prefers-color-scheme: dark) {
:root {
--background: 200 50% 3%;
--btn-background: 200 10% 9%;
--btn-background-hover: 200 10% 12%;
--foreground: 200 20% 96%;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-Book.woff2) format('woff2'),
url(/fonts/custom/CustomFont-Book.woff) format('woff');
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-BookItalic.woff2) format('woff2'),
url(/fonts/custom/CustomFont-BookItalic.woff) format('woff');
font-weight: 400;
font-style: italic;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-Medium.woff2) format('woff2'),
url(/fonts/custom/CustomFont-Medium.woff) format('woff');
font-weight: 500;
font-style: normal;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-MediumItalic.woff2) format('woff2'),
url(/fonts/custom/CustomFont-MediumItalic.woff) format('woff');
font-weight: 500;
font-style: italic;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-Bold.woff2) format('woff2'),
url(/fonts/custom/CustomFont-Bold.woff) format('woff');
font-weight: 700;
font-style: 600;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-BoldItalic.woff2) format('woff2'),
url(/fonts/custom/CustomFont-BoldItalic.woff) format('woff');
font-style: 600;
font-style: italic;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-Black.woff2) format('woff2'),
url(/fonts/custom/CustomFont-Black.woff) format('woff');
font-weight: 800;
font-style: normal;
}
@font-face {
font-family: 'circular';
src: url(/fonts/custom/CustomFont-BlackItalic.woff2) format('woff2'),
url(/fonts/custom/CustomFont-BlackItalic.woff) format('woff');
font-weight: 800;
font-style: italic;
}
@font-face {
font-family: 'source code pro';
src: url('/fonts/source-code-pro/SourceCodePro-Regular.eot');
src: url('/fonts/source-code-pro/SourceCodePro-Regular.woff2') format('woff2'),
url('/fonts/source-code-pro/SourceCodePro-Regular.woff') format('woff'),
url('/fonts/source-code-pro/SourceCodePro-Regular.ttf') format('truetype'),
url('/fonts/source-code-pro/SourceCodePro-Regular.svg#SourceCodePro-Regular') format('svg');
font-weight: normal;
font-style: normal;
font-display: swap;
}
html,
body,
main {
@apply bg-background;
@apply text-foreground;
height: 100%;
width: 100%;
padding: 0;
margin: 0;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
}
.chat-shimmering-loader {
animation: shimmer 1.5s infinite linear;
background: linear-gradient(
to right,
hsl(var(--background-default)) 0%,
hsl(var(--brand-default)) 25%,
hsl(var(--brand-300)) 35%,
hsl(var(--background-default)) 45%,
hsl(var(--background-surface-100)) 75%
);
background-size: 3000px 100%;
}
.shimmering-loader {
animation: shimmer 2s infinite linear;
background: linear-gradient(
to right,
hsl(var(--border-default)) 4%,
hsl(var(--background-surface-200)) 25%,
hsl(var(--border-default)) 36%
);
background-size: 1000px 100%;
}
.dark .shimmering-loader {
animation: shimmer 2s infinite linear;
background: linear-gradient(
to right,
hsl(var(--border-default)) 4%,
hsl(var(--border-control)) 25%,
hsl(var(--border-default)) 36%
);
background-size: 1000px 100%;
}
@keyframes shimmer {
0% {
background-position: -1000px 0;
}
100% {
background-position: 1000px 0;
}
}
@layer base {
* {
@apply border-foreground/20;
}
.monaco-editor,
.monaco-diff-editor {
--vscode-editor-background: hsl(var(--background-alternative)) !important;
--vscode-editorGutter-background: hsl(var(--background-alternative)) !important;
padding-top: 12px;
}
.animate-in {
animation: animateIn 0.3s ease 0.15s both;
}
@keyframes animateIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* .monaco-editor .overflow-guard */

View File

@@ -1,21 +1,34 @@
import { GeistSans } from 'geist/font'
import '@ui/layout/ai-icon-animation/ai-icon-animation-style.module.css'
import './globals.css'
import Header from '@/components/Header'
import { ReactQueryProvider, ThemeProvider } from '@/components/providers'
import type { Metadata } from 'next'
const defaultUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: 'http://localhost:3000'
export const metadata = {
export const metadata: Metadata = {
metadataBase: new URL(defaultUrl),
title: 'Next.js and Supabase Starter Kit',
description: 'The fastest way to build apps with Next.js and Supabase',
title: 'database.new',
description: 'Generate schemas from your ideas',
}
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" className={GeistSans.className}>
<body className="bg-background text-foreground">
<main className="min-h-screen flex flex-col items-center">{children}</main>
<html lang="en" className="dark">
<body>
<ThemeProvider defaultTheme="system" enableSystem disableTransitionOnChange>
<ReactQueryProvider>
<div className="flex flex-col h-full">
<Header />
<main role="main" className="grow">
{children}
</main>
</div>
</ReactQueryProvider>
</ThemeProvider>
</body>
</html>
)

View File

@@ -1,112 +0,0 @@
import Link from 'next/link'
import { headers, cookies } from 'next/headers'
import { createClient } from '@/utils/supabase/server'
import { redirect } from 'next/navigation'
export default function Login({ searchParams }: { searchParams: { message: string } }) {
const signIn = async (formData: FormData) => {
'use server'
const email = formData.get('email') as string
const password = formData.get('password') as string
const cookieStore = cookies()
const supabase = createClient(cookieStore)
const { error } = await supabase.auth.signInWithPassword({
email,
password,
})
if (error) {
return redirect('/login?message=Could not authenticate user')
}
return redirect('/')
}
const signUp = async (formData: FormData) => {
'use server'
const origin = headers().get('origin')
const email = formData.get('email') as string
const password = formData.get('password') as string
const cookieStore = cookies()
const supabase = createClient(cookieStore)
const { error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${origin}/auth/callback`,
},
})
if (error) {
return redirect('/login?message=Could not authenticate user')
}
return redirect('/login?message=Check email to continue sign in process')
}
return (
<div className="flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2">
<Link
href="/"
className="absolute left-8 top-8 py-2 px-4 rounded-md no-underline text-foreground bg-btn-background hover:bg-btn-background-hover flex items-center group text-sm"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="mr-2 h-4 w-4 transition-transform group-hover:-translate-x-1"
>
<polyline points="15 18 9 12 15 6" />
</svg>{' '}
Back
</Link>
<form
className="animate-in flex-1 flex flex-col w-full justify-center gap-2 text-foreground"
action={signIn}
>
<label className="text-md" htmlFor="email">
Email
</label>
<input
className="rounded-md px-4 py-2 bg-inherit border mb-6"
name="email"
placeholder="you@example.com"
required
/>
<label className="text-md" htmlFor="password">
Password
</label>
<input
className="rounded-md px-4 py-2 bg-inherit border mb-6"
type="password"
name="password"
placeholder="••••••••"
required
/>
<button className="bg-green-700 rounded-md px-4 py-2 text-foreground mb-2">Sign In</button>
<button
formAction={signUp}
className="border border-foreground/20 rounded-md px-4 py-2 text-foreground mb-2"
>
Sign Up
</button>
{searchParams?.message && (
<p className="mt-4 p-4 bg-foreground/10 text-foreground text-center">
{searchParams.message}
</p>
)}
</form>
</div>
)
}

View File

@@ -0,0 +1,58 @@
'use client'
import { useMutation } from '@tanstack/react-query'
import { Loader2 } from 'lucide-react'
import { useRouter } from 'next/navigation'
import { Input } from 'ui'
export default function NewThread() {
const router = useRouter()
const { mutate, isPending, isSuccess } = useMutation({
mutationFn: async (prompt: string) => {
const body = { prompt }
const response = await fetch('/api/ai/sql/threads/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
})
const result = await response.json()
return result
},
onSuccess(data) {
const url = `/${data.threadId}/${data.runId}`
router.push(url)
},
})
return (
<div className="h-full flex items-center justify-center w-full flex-col gap-y-4">
<div className="flex items-center gap-x-1.5 font-mono text-xl">
<span>database</span>
<div className="w-1.5 h-1.5 rounded-full bg-purple-900"></div>
<span>new</span>
</div>
<Input
autoFocus
size="xlarge"
className="w-11/12 max-w-xl shadow"
inputClassName="rounded-full"
placeholder="e.g Create a Telegram-like chat application"
disabled={isPending || isSuccess}
onKeyDown={(e) => {
if (e.code === 'Enter') {
const value = (e.target as any).value
if (value.length > 0) mutate(value)
}
}}
actions={
isPending || isSuccess ? (
<div className="mr-3">
<Loader2 size={18} className="animate-spin" />
</div>
) : null
}
/>
</div>
)
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 KiB

View File

@@ -1,57 +0,0 @@
import DeployButton from '../components/DeployButton'
import AuthButton from '../components/AuthButton'
import { createClient } from '@/utils/supabase/server'
import ConnectSupabaseSteps from '@/components/ConnectSupabaseSteps'
import SignUpUserSteps from '@/components/SignUpUserSteps'
import Header from '@/components/Header'
import { cookies } from 'next/headers'
export default async function Index() {
const cookieStore = cookies()
const canInitSupabaseClient = () => {
// This function is just for the interactive tutorial.
// Feel free to remove it once you have Supabase connected.
try {
createClient(cookieStore)
return true
} catch (e) {
return false
}
}
const isSupabaseConnected = canInitSupabaseClient()
return (
<div className="flex-1 w-full flex flex-col gap-20 items-center">
<nav className="w-full flex justify-center border-b border-b-foreground/10 h-16">
<div className="w-full max-w-4xl flex justify-between items-center p-3 text-sm">
<DeployButton />
{isSupabaseConnected && <AuthButton />}
</div>
</nav>
<div className="animate-in flex-1 flex flex-col gap-20 opacity-0 max-w-4xl px-3">
<Header />
<main className="flex-1 flex flex-col gap-6">
<h2 className="font-bold text-4xl mb-4">Next steps</h2>
{isSupabaseConnected ? <SignUpUserSteps /> : <ConnectSupabaseSteps />}
</main>
</div>
<footer className="w-full border-t border-t-foreground/10 p-8 flex justify-center text-center text-xs">
<p>
Powered by{' '}
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Supabase
</a>
</p>
</footer>
</div>
)
}

View File

@@ -0,0 +1,9 @@
'use client'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime)
export default function Layout({ children }: { children: React.ReactNode }) {
return <div className="max-w-4xl mx-auto h-full">{children}</div>
}

View File

@@ -0,0 +1,100 @@
'use client'
import { useConversationsQuery } from '@/data/conversations-query'
import dayjs from 'dayjs'
import Link from 'next/link'
import { Button, IconChevronRight, Input } from 'ui'
export default function Profile() {
const MOCK_PROFILE = {
name: 'J-Dog',
username: 'joshenlim',
email: 'joshen@supabase.io',
avatar: 'https://i.pinimg.com/564x/d1/0d/89/d10d890537309f146f92f9af9d70cf83.jpg',
}
const { data, isLoading, isSuccess } = useConversationsQuery({ userId: '' })
const conversations = data ?? []
return (
<div className="grid grid-cols-4 gap-x-8 py-12">
<div className="col-span-1 flex flex-col gap-y-6">
<div className="flex items-center gap-x-4">
<div
className="w-14 h-14 rounded-full border bg-no-repeat bg-center bg-cover"
style={{ backgroundImage: `url('${MOCK_PROFILE.avatar}')` }}
/>
<div className="flex flex-col">
<p className="text-xl">{MOCK_PROFILE.name}</p>
<p className="text-foreground-light">@{MOCK_PROFILE.username}</p>
</div>
</div>
{/* [Joshen] If we want some form action here */}
<div className="flex flex-col gap-y-2">
<Input size="tiny" label="Name" value={MOCK_PROFILE.name} />
<Input size="tiny" label="Username" value={MOCK_PROFILE.username} />
<Input size="tiny" label="Email" value={MOCK_PROFILE.email} />
</div>
<div className="flex items-center justify-end gap-x-2">
<Button type="default">Cancel</Button>
<Button type="primary">Save changes</Button>
</div>
</div>
<div className="col-span-3 flex flex-col gap-y-4">
<p>Past conversations</p>
<div className="w-full h-px border-t" />
<div className="flex flex-col gap-y-3">
{isLoading && (
<div className="flex flex-col gap-y-3">
<div className="rounded w-full shimmering-loader py-7" />
<div className="rounded w-full shimmering-loader py-7" />
</div>
)}
{!isLoading && conversations.length === 0 && (
<div className="border rounded py-6 flex flex-col items-center justify-center gap-y-2">
<p className="text-sm text-foreground-light">No conversations created yet</p>
<Button type="default">
<Link href="/new">Start a conversation</Link>
</Button>
</div>
)}
{isSuccess &&
conversations.map((conversation) => {
const hoursFromNow = dayjs().diff(dayjs(conversation.updatedAt), 'hours')
const formattedTimeFromNow = dayjs(conversation.updatedAt).fromNow()
const formattedUpdatedAt = dayjs(conversation.updatedAt).format('DD MMM YYYY, HH:mm')
return (
<Link
key={conversation.id}
href={`/${conversation.threadId}/${conversation.runId}`}
>
<div className="group flex items-center justify-between border rounded w-full px-4 py-2 transition bg-surface-100 hover:bg-surface-200">
<div className="flex flex-col gap-y-1">
<p className="text-sm">{conversation.name}</p>
<p className="text-xs text-foreground-light">
Last updated at{' '}
{hoursFromNow > 6 ? `on ${formattedUpdatedAt}` : formattedTimeFromNow}
</p>
</div>
<Button
type="text"
icon={<IconChevronRight size={16} strokeWidth={2} />}
className="transition opacity-0 group-hover:opacity-100 px-1"
/>
</div>
</Link>
)
})}
</div>
</div>
</div>
)
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 KiB

View File

@@ -0,0 +1,2 @@
export const NODE_WIDTH = 700
export const NODE_HEIGHT = 200

View File

@@ -0,0 +1,127 @@
'use client'
import { useQuery } from '@tanstack/react-query'
import { Modal } from 'ui'
import { useParams } from 'next/navigation'
import { AssistantMessage, ReadThreadAPIResult, UserMessage } from '@/lib/types'
import { useEffect, useMemo } from 'react'
import { sortBy } from 'lodash'
import ReactFlow, {
Background,
BackgroundVariant,
ReactFlowProvider,
useReactFlow,
MiniMap,
} from 'reactflow'
import { getGraphDataFromMessages } from './AllThreadsModal.utils'
import MessageNode from './MessageNode'
interface AllThreadsProps {
visible: boolean
onClose: () => void
onSelectMessage: (messageId: string, replyId: string) => void
}
// [Joshen] POC idea for forking/branching - not for phase 1
const AllThreads = ({ visible, onClose, onSelectMessage }: AllThreadsProps) => {
const params = useParams()
const reactFlowInstance = useReactFlow()
const nodeTypes = useMemo(() => ({ message: MessageNode }), [])
// [Joshen] Scaffolding a query cause im presuming we need a different endpoint to retrieve _all_ threads
const { data, isSuccess } = useQuery<ReadThreadAPIResult>({
queryFn: async () => {
const response = await fetch(`/api/ai/sql/threads/${params.threadId}/read/${params.runId}`, {
method: 'GET',
})
const result = await response.json()
return result
},
queryKey: [params.threadId, params.runId],
refetchInterval: (options) => {
const data = options.state.data
if (data && data.status === 'completed') {
return Infinity
}
return 5000
},
enabled: !!(params.threadId && params.runId),
})
const messages = useMemo(() => {
if (isSuccess) return sortBy(data.messages, (m) => m.created_at)
return []
}, [data?.messages, isSuccess])
const userMessages = messages.filter((m) => m.role === 'user') as UserMessage[]
useEffect(() => {
if (reactFlowInstance !== undefined && userMessages.length > 0) {
const { nodes, edges } = getGraphDataFromMessages({
messages: userMessages,
onSelectMessage: (message: UserMessage) => {
const index = messages.indexOf(message)
const reply = messages[index + 1] as AssistantMessage
onSelectMessage(message.id, reply.id)
},
})
reactFlowInstance.setNodes(nodes)
reactFlowInstance.setEdges(edges)
setTimeout(() => {
reactFlowInstance.fitView({})
const viewport = reactFlowInstance.getViewport()
reactFlowInstance.setViewport({ x: viewport.x - 70, y: 150, zoom: 1 })
})
}
}, [reactFlowInstance, userMessages])
useEffect(() => {
if (reactFlowInstance !== undefined && visible) {
reactFlowInstance.fitView({})
}
}, [reactFlowInstance, visible])
return (
<Modal
showCloseButton
hideFooter
size="xxlarge"
visible={visible}
onCancel={onClose}
header="All threads in current conversation"
>
<div className="h-[700px] border-t bg-background">
<ReactFlow
nodesDraggable={false}
edgesUpdatable={false}
defaultNodes={[]}
defaultEdges={[]}
maxZoom={1.1}
nodeTypes={nodeTypes}
proOptions={{ hideAttribution: true }}
>
<Background gap={16} color="#000" variant={BackgroundVariant.Lines} />
<MiniMap
pannable
zoomable
nodeColor={'rgba(0,0,0,0.7)'}
maskColor={'rgba(0,0,0,0.85)'}
className="border border-control rounded-md shadow-sm"
/>
</ReactFlow>
</div>
</Modal>
)
}
const AllThreadsModal = ({ visible, onClose, onSelectMessage }: AllThreadsProps) => {
return (
<ReactFlowProvider>
<AllThreads visible={visible} onClose={onClose} onSelectMessage={onSelectMessage} />
</ReactFlowProvider>
)
}
export default AllThreadsModal

View File

@@ -0,0 +1,65 @@
import { UserMessage } from '@/lib/types'
import dagre from '@dagrejs/dagre'
import { Edge, Node, Position } from 'reactflow'
import { NODE_HEIGHT, NODE_WIDTH } from './AllThreadsModal.constants'
import { MessageNodeData } from './MessageNode'
export const getGraphDataFromMessages = ({
messages,
onSelectMessage,
}: {
messages: UserMessage[]
onSelectMessage: (message: UserMessage) => void
}): { nodes: Node<MessageNodeData>[]; edges: Edge[] } => {
const nodes: Node[] = messages.map((message, idx) => {
return {
id: message.id,
type: 'message',
data: {
id: message.id,
text: message.text,
isStart: idx === 0,
isEnd: idx === messages.length - 1,
onSelectMessage: () => onSelectMessage(message),
},
position: { x: 0, y: 0 },
}
})
const edges: Edge[] = []
messages.forEach((message, idx) => {
if (idx > 0) {
edges.push({
id: `edge-${idx}`,
source: messages[idx - 1].id,
target: message.id,
type: 'smoothstep',
animated: true,
})
}
})
const dagreGraph = new dagre.graphlib.Graph()
dagreGraph.setDefaultEdgeLabel(() => ({}))
dagreGraph.setGraph({ rankdir: 'TB', ranksep: 50, nodesep: 20 })
nodes.forEach((node) =>
dagreGraph.setNode(node.id, { width: NODE_WIDTH / 2, height: NODE_HEIGHT / 2 })
)
edges.forEach((edge) => dagreGraph.setEdge(edge.source, edge.target))
dagre.layout(dagreGraph)
nodes.forEach((node) => {
const nodeWithPosition = dagreGraph.node(node.id)
node.targetPosition = Position.Top
node.sourcePosition = Position.Bottom
node.position = {
x: nodeWithPosition.x - nodeWithPosition.width / 2,
y: nodeWithPosition.y - nodeWithPosition.height / 2,
}
return node
})
return { nodes, edges }
}

View File

@@ -0,0 +1,44 @@
import { Handle, NodeProps, Position } from 'reactflow'
import { NODE_HEIGHT, NODE_WIDTH } from './AllThreadsModal.constants'
export interface MessageNodeData {
id: string
text: string
isStart: boolean
isEnd: boolean
onSelectMessage: () => void
}
const MessageNode = ({ data }: NodeProps<MessageNodeData>) => {
const { id, text, isStart, isEnd, onSelectMessage } = data
return (
<>
{!isStart && (
<Handle
type="target"
id="handle-t"
position={Position.Top}
style={{ background: 'transparent' }}
/>
)}
<div
className="flex flex-col gap-y-1 rounded bg-surface-100 border border-default p-3 hover:bg-surface-200 transition cursor-pointer"
style={{ width: NODE_WIDTH / 2 - 10, height: NODE_HEIGHT / 2 }}
onClick={() => onSelectMessage()}
>
<p className="text-xs text-foreground-light font-mono">{id}</p>
<p className="text-sm">{text}</p>
</div>
{!isEnd && (
<Handle
type="source"
id="handle-s"
position={Position.Bottom}
style={{ background: 'transparent' }}
/>
)}
</>
)
}
export default MessageNode

View File

@@ -1,40 +0,0 @@
import { createClient } from '@/utils/supabase/server'
import Link from 'next/link'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
export default async function AuthButton() {
const cookieStore = cookies()
const supabase = createClient(cookieStore)
const {
data: { user },
} = await supabase.auth.getUser()
const signOut = async () => {
'use server'
const cookieStore = cookies()
const supabase = createClient(cookieStore)
await supabase.auth.signOut()
return redirect('/login')
}
return user ? (
<div className="flex items-center gap-4">
Hey, {user.email}!
<form action={signOut}>
<button className="py-2 px-4 rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
Logout
</button>
</form>
</div>
) : (
<Link
href="/login"
className="py-2 px-3 flex rounded-md no-underline bg-btn-background hover:bg-btn-background-hover"
>
Login
</Link>
)
}

View File

@@ -0,0 +1,17 @@
import { useEffect, useRef } from 'react'
const BottomMarker = () => {
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
if (ref.current) {
setTimeout(() => {
if (ref.current) ref.current.scrollIntoView({ behavior: 'smooth' })
}, 700)
}
}, [ref])
return <div ref={ref} />
}
export default BottomMarker

View File

@@ -0,0 +1,126 @@
'use client'
import { useMutation } from '@tanstack/react-query'
import { sortBy } from 'lodash'
import { Loader2 } from 'lucide-react'
import { useParams, useRouter } from 'next/navigation'
import { useEffect, useMemo, useState } from 'react'
import { Input, ScrollArea, cn } from 'ui'
import { useMessagesQuery } from '@/data/messages-query'
import { AssistantMessage, UserMessage } from '@/lib/types'
import BottomMarker from './BottomMarker'
import UserChat from './UserChat'
export const Chat = () => {
const router = useRouter()
const [value, setValue] = useState('')
const [inputEntered, setInputEntered] = useState(false)
const { threadId, runId, messageId }: { threadId: string; runId: string; messageId: string } =
useParams()
const { data, isSuccess } = useMessagesQuery({ threadId, runId })
const messages = useMemo(() => {
if (isSuccess) return sortBy(data.messages, (m) => m.created_at)
return []
}, [data?.messages, isSuccess])
const selectedMessage = messageId
const loading = isSuccess && data.status === 'loading'
const userMessages = messages.filter((message) => message.role === 'user')
const { mutate } = useMutation({
mutationFn: async (prompt: string) => {
const body = { prompt }
const response = await fetch(`/api/ai/sql/threads/${threadId}/update`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
})
const result = await response.json()
return result
},
onSuccess(data) {
const url = messageId
? `/${data.threadId}/${data.runId}/${messageId}`
: `/${data.threadId}/${data.runId}`
router.push(url)
},
})
useEffect(() => {
setInputEntered(false)
setValue('')
}, [loading])
return (
<div
className={cn(
'bg',
'border-r relative',
'flex flex-col h-full border-r',
'w-[400px] 2xl:w-[500px]'
)}
>
<div className="flex flex-col grow items-between">
{messages.length === 0 ? (
<div className="grow flex items-center justify-center">
<Loader2 className="animate-spin" />
</div>
) : (
<ScrollArea className="grow h-px">
<div className="flex flex-col py-6">
{userMessages.map((message, idx) => {
const index = messages.indexOf(message)
const reply = messages[index + 1] as AssistantMessage
const isLatest = idx === userMessages.length - 1
return (
<UserChat
key={message.id}
message={message as UserMessage}
reply={reply}
isLatest={isLatest}
isSelected={selectedMessage === message?.id}
isLoading={loading && isLatest}
/>
)
})}
<BottomMarker />
</div>
</ScrollArea>
)}
<div className="px-4 pb-4">
<Input
value={value}
disabled={loading || inputEntered}
inputClassName="rounded-full pl-8"
placeholder={
loading
? 'Generating reply to request...'
: 'Ask for some changes on the selected message'
}
icon={<div className="ml-1 w-2 h-2 rounded-full bg-purple-900" />}
onChange={(v) => setValue(v.target.value)}
onKeyDown={(e) => {
if (e.code === 'Enter' && value.length > 0) {
mutate(value)
setInputEntered(true)
}
}}
actions={
loading || inputEntered ? (
<div className="mr-2">
<Loader2 size={16} className="animate-spin" />
</div>
) : null
}
/>
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,120 @@
import { AssistantMessage, UserMessage } from '@/lib/types'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { useParams, useRouter } from 'next/navigation'
import { cn } from 'ui'
dayjs.extend(relativeTime)
interface UserChatProps {
message: UserMessage
reply?: AssistantMessage
isLatest: boolean
isSelected: boolean
isLoading: boolean
}
const UserChat = ({ message, reply, isLatest, isSelected, isLoading }: UserChatProps) => {
const router = useRouter()
const { threadId, runId } = useParams()
const hoursFromNow = dayjs().diff(dayjs(message.created_at * 1000), 'hours')
const formattedTimeFromNow = dayjs(message.created_at * 1000).fromNow()
const formattedCreatedAt = dayjs(message.created_at * 1000).format('DD MMM YYYY, HH:mm')
const replyDuration = reply !== undefined ? reply.created_at - message.created_at : undefined
return (
<div
className={cn(
'group',
'transition flex w-full gap-x-5 px-8 hover:bg-surface-200/50 cursor-pointer border-r',
isSelected && 'bg-surface-200',
isSelected ? 'border-r-foreground' : 'border-r border-r-transparent'
)}
onClick={() => {
router.push(`/${threadId}/${runId}/${message.id}`)
}}
>
<div className="flex flex-col justify-between items-center relative top-3">
{/* Node */}
<div
className={cn(
'transition w-2.5 h-2.5 mt-[1px] ml-[1px] rounded-full border',
isSelected
? 'bg-dbnew border-dbnew'
: 'bg-transparent border-foreground-muted group-hover:border-foreground'
)}
/>
{isLoading && (
<span
className={cn(
'absolute w-4 h-4 -top-0.5',
'after:content-spinner after:t-0 after:block after:absolute after:h-4 after:w-4 after:border-r after:border-r-dbnew after:rounded-[50%] after:rotate-45 z-10',
'animate-spin'
)}
>
<div className="absolute border w-4 h-4 rounded-full z-0" />
</span>
)}
{/* Node line*/}
{!isLatest && <div className="border-l border-strong flex-grow" />}
</div>
<div className="flex w-full flex-col gap-y-2 py-4">
<div className="group relative">
<span className="z-10 absolute top-0 -left-[8px]">
<svg viewBox="0 0 8 13" height="13" width="8">
<path
className={
// 'transition fill-background-surface-100 border'
isSelected
? 'transition stroke-border fill-background-surface-100 stroke-border-default'
: 'transition stroke-border fill-background-surface-100 stroke-border-default'
}
d="M1.533,2.568L8,11.193V0L2.812,0C1.042,0,0.474,1.156,1.533,2.568z"
/>
</svg>
</span>
<div
title={message.text}
className={cn(
'cursor-pointer transition relative overflow-hidden',
'w-full rounded-lg rounded-tl-none',
'bg-alternative',
'border'
// isSelected ? 'bg-surface-100' : 'bg-surface-100 group-hover:bg-surface-200'
)}
>
<p
className={cn(
'transition p-4 text-sm',
isSelected ? 'text-foreground' : 'text-light group-hover:text-foreground'
)}
>
{message.text}
</p>
{isLoading && <div className="chat-shimmering-loader w-full h-0.5 absolute bottom-0" />}
</div>
</div>
{isSelected && (
<p
className={cn(
'transition-all',
isSelected ? 'h-inherit opacity-100' : 'h-0 opacity-0',
'font-mono text-xs text-foreground-lighter'
)}
>
Sent {hoursFromNow > 6 ? `on ${formattedCreatedAt}` : formattedTimeFromNow}
{replyDuration !== undefined
? ` with ${replyDuration}s response`
: isLoading
? ', generating response...'
: ''}
</p>
)}
</div>
</div>
)
}
export default UserChat

View File

@@ -1,58 +0,0 @@
'use client'
import { useState } from 'react'
const CopyIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
</svg>
)
const CheckIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
)
export default function Code({ code }: { code: string }) {
const [icon, setIcon] = useState(CopyIcon)
const copy = async () => {
await navigator?.clipboard?.writeText(code)
setIcon(CheckIcon)
setTimeout(() => setIcon(CopyIcon), 2000)
}
return (
<pre className="bg-foreground/5 rounded-md p-8 my-8 relative">
<button
onClick={copy}
className="absolute top-4 right-4 p-2 rounded-md bg-foreground/5 hover:bg-foreground/10"
>
{icon}
</button>
<code>{code}</code>
</pre>
)
}

View File

@@ -0,0 +1,127 @@
import Editor, { BeforeMount, EditorProps, OnMount } from '@monaco-editor/react'
import { merge, noop } from 'lodash'
import { useTheme } from 'next-themes'
import { useEffect, useRef } from 'react'
import { format } from 'sql-formatter'
import { cn } from 'ui'
import { getTheme } from './CodeEditor.utils'
import { useAppStateSnapshot } from '@/lib/state'
interface MonacoEditorProps {
id: string
language: 'pgsql' | 'json' | 'html'
autofocus?: boolean
defaultValue?: string
isReadOnly?: boolean
onInputChange?: (value?: string) => void
onInputRun?: (value: string) => void
hideLineNumbers?: boolean
loading?: boolean
options?: EditorProps['options']
value?: string
}
export const CodeEditor = ({ content = '' }: { content: string }) => {
const snap = useAppStateSnapshot()
const code = format(content, { language: 'postgresql' })
return (
<div
className={cn(
snap.hideCode ? 'max-w-0' : 'max-w-lg 2xl:max-w-xl',
'w-full border-l',
'grow flex flex-col h-full'
)}
>
<MonacoEditor id="sql-editor" language="pgsql" value={code} />
</div>
)
}
const MonacoEditor = ({
id,
language,
defaultValue,
hideLineNumbers = false,
onInputChange = noop,
options,
value,
}: MonacoEditorProps) => {
const monacoRef = useRef<any>()
const { resolvedTheme } = useTheme()
useEffect(() => {
if (resolvedTheme && monacoRef.current) {
const mode: any = getTheme(resolvedTheme)
monacoRef.current.editor.defineTheme('supabase', mode)
}
}, [resolvedTheme, monacoRef])
const beforeMount: BeforeMount = (monaco) => {
monacoRef.current = monaco
monaco.editor.defineTheme('supabase', {
base: 'vs-dark',
inherit: true,
rules: [
{ token: '', background: '1f1f1f' },
{ token: '', background: '1f1f1f', foreground: 'd4d4d4' },
{ token: 'string.sql', foreground: '24b47e' },
{ token: 'comment', foreground: '666666' },
{ token: 'predefined.sql', foreground: 'D4D4D4' },
],
colors: { 'editor.background': '#1f1f1f' },
})
}
const onMount: OnMount = async (editor, monaco) => {
// Add margin above first line
editor.changeViewZones((accessor) => {
accessor.addZone({
afterLineNumber: 0,
heightInPx: 4,
domNode: document.createElement('div'),
})
})
if (resolvedTheme) {
const mode: any = getTheme(resolvedTheme)
monacoRef.current.editor.defineTheme('supabase', mode)
}
}
const optionsMerged = merge(
{
tabSize: 2,
fontSize: 13,
readOnly: true,
minimap: { enabled: false },
wordWrap: 'on',
fixedOverflowWidgets: true,
contextmenu: true,
lineNumbers: hideLineNumbers ? 'off' : undefined,
glyphMargin: hideLineNumbers ? false : undefined,
lineNumbersMinChars: hideLineNumbers ? 0 : undefined,
folding: hideLineNumbers ? false : undefined,
},
options
)
merge({ cpp: '12' }, { java: '23' }, { python: '35' })
return (
<Editor
path={id}
theme="supabase"
className={cn('bg-alternative [&>div]:p-0')}
value={value ?? undefined}
defaultLanguage={language}
defaultValue={defaultValue ?? undefined}
loading={false}
options={optionsMerged}
beforeMount={beforeMount}
onMount={onMount}
onChange={onInputChange}
/>
)
}

View File

@@ -0,0 +1,20 @@
export const getTheme = (theme: string) => {
const isDarkMode = theme.includes('dark')
return {
base: isDarkMode ? 'vs-dark' : 'vs', // can also be vs-dark or hc-black
inherit: true, // can also be false to completely replace the builtin rules
rules: [
{ token: '', background: isDarkMode ? '1f1f1f' : 'f0f0f0' },
{
token: '',
background: isDarkMode ? '1f1f1f' : 'f0f0f0',
foreground: isDarkMode ? 'd4d4d4' : '444444',
},
{ token: 'string.sql', foreground: '24b47e' },
{ token: 'comment', foreground: '666666' },
{ token: 'predefined.sql', foreground: isDarkMode ? 'D4D4D4' : '444444' },
],
colors: { 'editor.background': isDarkMode ? '#1f1f1f' : '#f0f0f0' },
}
}

View File

@@ -1,59 +0,0 @@
import Step from './Step'
export default function ConnectSupabaseSteps() {
return (
<ol className="flex flex-col gap-6">
<Step title="Create Supabase project">
<p>
Head over to{' '}
<a
href="https://app.supabase.com/project/_/settings/api"
target="_blank"
className="font-bold hover:underline text-foreground/80"
rel="noreferrer"
>
database.new
</a>{' '}
and create a new Supabase project.
</p>
</Step>
<Step title="Declare environment variables">
<p>
Rename the{' '}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
.env.example
</span>{' '}
file in your Next.js app to{' '}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
.env.local
</span>{' '}
and populate with values from{' '}
<a
href="https://app.supabase.com/project/_/settings/api"
target="_blank"
className="font-bold hover:underline text-foreground/80"
rel="noreferrer"
>
your Supabase project's API Settings
</a>
.
</p>
</Step>
<Step title="Restart your Next.js development server">
<p>
You may need to quit your Next.js development server and run{' '}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
npm run dev
</span>{' '}
again to load the new environment variables.
</p>
</Step>
<Step title="Refresh the page">
<p>You may need to refresh the page for Next.js to load the new environment variables.</p>
</Step>
</ol>
)
}

View File

@@ -1,15 +0,0 @@
export default function DeployButton() {
return (
<a
className="py-2 px-3 flex rounded-md no-underline hover:bg-btn-background-hover border"
href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&project-name=nextjs-with-supabase&repository-name=nextjs-with-supabase&demo-title=nextjs-with-supabase&demo-description=This%20starter%20configures%20Supabase%20Auth%20to%20use%20cookies%2C%20making%20the%20user's%20session%20available%20throughout%20the%20entire%20Next.js%20app%20-%20Client%20Components%2C%20Server%20Components%2C%20Route%20Handlers%2C%20Server%20Actions%20and%20Middleware.&demo-url=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2F&external-id=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&demo-image=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2Fopengraph-image.png&integration-ids=oac_VqOgBHqhEoFTPzGkPd7L0iH6"
target="_blank"
rel="noreferrer"
>
<svg aria-label="Vercel logomark" role="img" viewBox="0 0 74 64" className="h-4 w-4 mr-2">
<path d="M37.5896 0.25L74.5396 64.25H0.639648L37.5896 0.25Z" fill="currentColor"></path>
</svg>
Deploy to Vercel
</a>
)
}

View File

@@ -1,44 +1,141 @@
import NextLogo from './NextLogo'
import SupabaseLogo from './SupabaseLogo'
/* eslint-disable @next/next/no-img-element */
'use client'
import { LogIn, LogOut, Moon, Sun } from 'lucide-react'
import { useTheme } from 'next-themes'
import Link from 'next/link'
import { useParams } from 'next/navigation'
import { useEffect, useState } from 'react'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
IconUser,
} from 'ui'
import { useMessagesQuery } from '@/data/messages-query'
import { useAppStateSnapshot } from '@/lib/state'
import { UserMessage } from '@/lib/types'
import { Separator } from '@ui/components/Modal/Modal'
const Header = () => {
const snap = useAppStateSnapshot()
const { threadId, runId, messageId }: { threadId: string; runId: string; messageId: string } =
useParams()
const [mounted, setMounted] = useState(false)
const { setTheme, resolvedTheme } = useTheme()
const isConversation = threadId !== undefined && runId !== undefined
useEffect(() => {
setMounted(true)
}, [])
const { data } = useMessagesQuery({ threadId, runId, enabled: isConversation })
const selectedMessage = data?.messages.find((m) => m.id === messageId) as UserMessage
// [Joshen] Fetch user profile here
const isLoggedIn = true
const MOCK_PROFILE = {
name: 'J-Dog',
username: 'joshenlim',
email: 'joshen@supabase.io',
avatar: 'https://i.pinimg.com/564x/d1/0d/89/d10d890537309f146f92f9af9d70cf83.jpg',
}
export default function Header() {
return (
<div className="flex flex-col gap-16 items-center">
<div className="flex gap-8 justify-center items-center">
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
rel="noreferrer"
>
<SupabaseLogo />
</a>
<span className="border-l rotate-45 h-6" />
<a href="https://nextjs.org/" target="_blank" rel="noreferrer">
<NextLogo />
</a>
<nav
role="navigation"
className="bg-background border flex items-center justify-between px-4 min-h-[50px]"
>
<div className="flex items-center gap-x-4">
<div className="flex items-center gap-x-1.5 font-mono">
<span>database</span>
<div className="w-1.5 h-1.5 rounded-full bg-purple-900"></div>
<span>new</span>
</div>
{selectedMessage !== undefined && (
<p title={selectedMessage.text} className="truncate border-l text-sm px-4">
{selectedMessage.text}
</p>
)}
</div>
<h1 className="sr-only">Supabase and Next.js Starter Template</h1>
<p className="text-3xl lg:text-4xl !leading-tight mx-auto max-w-xl text-center">
The fastest way to build apps with{' '}
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Supabase
</a>{' '}
and{' '}
<a
href="https://nextjs.org/"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Next.js
</a>
</p>
<div className="w-full p-[1px] bg-gradient-to-r from-transparent via-foreground/10 to-transparent my-8" />
</div>
<div className="flex items-center gap-x-2">
{isConversation && (
<>
(
<Button type="default" onClick={() => snap.setHideCode(!snap.hideCode)}>
{snap.hideCode ? 'Show code' : 'Hide code'}
</Button>
<div className="border-r py-3" />)
</>
)}
<Button type="default">
<Link href="/new">New conversation</Link>
</Button>
<Button
type="outline"
className="px-1"
icon={mounted && resolvedTheme === 'dark' ? <Moon size={16} /> : <Sun size={16} />}
onClick={() => (resolvedTheme === 'dark' ? setTheme('light') : setTheme('dark'))}
/>
<DropdownMenu>
<DropdownMenuTrigger asChild className="flex">
{isLoggedIn ? (
<button
className="border border-foreground-lighter rounded-full w-[30px] h-[30px] bg-no-repeat bg-center bg-cover"
style={{ backgroundImage: `url('${MOCK_PROFILE.avatar}')` }}
/>
) : (
<Button type="outline" className="p-1.5 rounded-full" icon={<IconUser size={16} />} />
)}
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" className="w-48">
{isLoggedIn ? (
<>
<div className="px-2 py-2">
<p className="text-xs text-foreground">{MOCK_PROFILE.name}</p>
<p className="text-xs text-foreground-light">{MOCK_PROFILE.email}</p>
</div>
<Link href="/profile">
<DropdownMenuItem className="space-x-2" onClick={() => {}}>
<IconUser size={14} />
<p>Profile</p>
</DropdownMenuItem>
</Link>
<Separator />
<a href="https://supabase.com" target="_blank" rel="noreferrer">
<DropdownMenuItem className="space-x-2">
<img alt="supabase" src="/supabase.png" className="w-[14px]" />
<p>Supabase</p>
</DropdownMenuItem>
</a>
<DropdownMenuItem className="space-x-2" onClick={() => {}}>
<LogOut size={14} />
<p>Sign out</p>
</DropdownMenuItem>
</>
) : (
<div className="flex flex-col gap-y-2 p-2">
<div className="text-xs">
Sign in to <span className="text-foreground">database.new</span> to save your
conversations!
</div>
<Button type="default" icon={<LogIn size={14} />}>
Sign in
</Button>
</div>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>
</nav>
)
}
export default Header

View File

@@ -1,40 +0,0 @@
export default function NextLogo() {
return (
<svg aria-label="Next.js logotype" height="68" role="img" viewBox="0 0 394 79" width="100">
<path
d="M261.919 0.0330722H330.547V12.7H303.323V79.339H289.71V12.7H261.919V0.0330722Z"
fill="currentColor"
/>
<path
d="M149.052 0.0330722V12.7H94.0421V33.0772H138.281V45.7441H94.0421V66.6721H149.052V79.339H80.43V12.7H80.4243V0.0330722H149.052Z"
fill="currentColor"
/>
<path
d="M183.32 0.0661486H165.506L229.312 79.3721H247.178L215.271 39.7464L247.127 0.126654L229.312 0.154184L206.352 28.6697L183.32 0.0661486Z"
fill="currentColor"
/>
<path
d="M201.6 56.7148L192.679 45.6229L165.455 79.4326H183.32L201.6 56.7148Z"
fill="currentColor"
/>
<path
clipRule="evenodd"
d="M80.907 79.339L17.0151 0H0V79.3059H13.6121V16.9516L63.8067 79.339H80.907Z"
fill="currentColor"
fillRule="evenodd"
/>
<path
d="M333.607 78.8546C332.61 78.8546 331.762 78.5093 331.052 77.8186C330.342 77.1279 329.991 76.2917 330 75.3011C329.991 74.3377 330.342 73.5106 331.052 72.8199C331.762 72.1292 332.61 71.7838 333.607 71.7838C334.566 71.7838 335.405 72.1292 336.115 72.8199C336.835 73.5106 337.194 74.3377 337.204 75.3011C337.194 75.9554 337.028 76.5552 336.696 77.0914C336.355 77.6368 335.922 78.064 335.377 78.373C334.842 78.6911 334.252 78.8546 333.607 78.8546Z"
fill="currentColor"
/>
<path
d="M356.84 45.4453H362.872V68.6846C362.863 70.8204 362.401 72.6472 361.498 74.1832C360.585 75.7191 359.321 76.8914 357.698 77.7185C356.084 78.5364 354.193 78.9546 352.044 78.9546C350.079 78.9546 348.318 78.6001 346.75 77.9094C345.182 77.2187 343.937 76.1826 343.024 74.8193C342.101 73.456 341.649 71.7565 341.649 69.7207H347.691C347.7 70.6114 347.903 71.3838 348.29 72.0291C348.677 72.6744 349.212 73.1651 349.895 73.5105C350.586 73.8559 351.38 74.0286 352.274 74.0286C353.243 74.0286 354.073 73.8286 354.746 73.4196C355.419 73.0197 355.936 72.4199 356.296 71.6201C356.646 70.8295 356.831 69.8479 356.84 68.6846V45.4453Z"
fill="currentColor"
/>
<path
d="M387.691 54.5338C387.544 53.1251 386.898 52.0254 385.773 51.2438C384.638 50.4531 383.172 50.0623 381.373 50.0623C380.11 50.0623 379.022 50.2532 378.118 50.6258C377.214 51.0075 376.513 51.5164 376.033 52.1617C375.554 52.807 375.314 53.5432 375.295 54.3703C375.295 55.061 375.461 55.6608 375.784 56.1607C376.107 56.6696 376.54 57.0968 377.103 57.4422C377.656 57.7966 378.274 58.0874 378.948 58.3237C379.63 58.56 380.313 58.76 380.995 58.9236L384.14 59.6961C385.404 59.9869 386.631 60.3778 387.802 60.8776C388.973 61.3684 390.034 61.9955 390.965 62.7498C391.897 63.5042 392.635 64.413 393.179 65.4764C393.723 66.5397 394 67.7848 394 69.2208C394 71.1566 393.502 72.8562 392.496 74.3285C391.491 75.7917 390.043 76.9369 388.143 77.764C386.252 78.582 383.965 79 381.272 79C378.671 79 376.402 78.6002 374.493 77.8004C372.575 77.0097 371.08 75.8463 370.001 74.3194C368.922 72.7926 368.341 70.9294 368.258 68.7391H374.235C374.318 69.8842 374.687 70.8386 375.314 71.6111C375.95 72.3745 376.78 72.938 377.795 73.3197C378.819 73.6923 379.962 73.8832 381.226 73.8832C382.545 73.8832 383.707 73.6832 384.712 73.2924C385.708 72.9016 386.492 72.3564 387.055 71.6475C387.627 70.9476 387.913 70.1206 387.922 69.1754C387.913 68.312 387.654 67.5939 387.156 67.0304C386.649 66.467 385.948 65.9944 385.053 65.6127C384.15 65.231 383.098 64.8856 381.899 64.5857L378.081 63.6223C375.323 62.9225 373.137 61.8592 371.541 60.4323C369.937 59.0054 369.143 57.115 369.143 54.7429C369.143 52.798 369.678 51.0894 370.758 49.6261C371.827 48.1629 373.294 47.0268 375.148 46.2179C377.011 45.4 379.114 45 381.456 45C383.836 45 385.92 45.4 387.719 46.2179C389.517 47.0268 390.929 48.1538 391.952 49.5897C392.976 51.0257 393.511 52.6707 393.539 54.5338H387.691Z"
fill="currentColor"
/>
</svg>
)
}

View File

@@ -0,0 +1,3 @@
// ReactFlow is scaling everything by the factor of 2
export const NODE_WIDTH = 320
export const NODE_ROW_HEIGHT = 40

View File

@@ -0,0 +1,84 @@
'use client'
import { PostgresTable } from '@/lib/types'
import { useTheme } from 'next-themes'
import { useEffect, useMemo, useState } from 'react'
import ReactFlow, {
Background,
BackgroundVariant,
ReactFlowProvider,
useReactFlow,
} from 'reactflow'
import 'reactflow/dist/style.css'
import { cn } from 'ui'
import { getGraphDataFromTables } from './SchemaGraph.utils'
import TableNode from './TableNode'
interface SchemaGraphProps {
tables: PostgresTable[]
}
const TablesGraph = ({ tables }: SchemaGraphProps) => {
const { resolvedTheme } = useTheme()
const [mounted, setMounted] = useState(false)
const reactFlowInstance = useReactFlow()
const nodeTypes = useMemo(() => ({ table: TableNode }), [])
useEffect(() => {
setMounted(true)
}, [])
useEffect(() => {
getGraphDataFromTables(tables).then(({ nodes, edges }) => {
reactFlowInstance.setNodes(nodes)
reactFlowInstance.setEdges(edges)
setTimeout(() => reactFlowInstance.fitView({}), 10)
})
}, [tables, resolvedTheme])
return (
<>
<div className={cn('h-full grow')}>
<ReactFlow
defaultNodes={[]}
defaultEdges={[]}
defaultEdgeOptions={{
type: 'smoothstep',
animated: true,
deletable: false,
style: {
stroke: 'hsl(var(--border-stronger))',
strokeWidth: 0.5,
},
}}
nodeTypes={nodeTypes}
minZoom={1}
maxZoom={1.8}
proOptions={{ hideAttribution: true }}
onInit={(instance) => {
instance.fitView()
}}
>
{mounted && (
<Background
gap={16}
className="[&>*]:stroke-foreground-muted opacity-[25%]"
variant={BackgroundVariant.Dots}
color={'inherit'}
/>
)}
</ReactFlow>
</div>
</>
)
}
const SchemaGraph = ({ tables }: SchemaGraphProps) => {
return (
<ReactFlowProvider>
<TablesGraph tables={tables} />
</ReactFlowProvider>
)
}
export default SchemaGraph

View File

@@ -0,0 +1,168 @@
import { PostgresTable } from '@/lib/types'
import dagre from '@dagrejs/dagre'
import { uniqBy } from 'lodash'
import { Edge, Node, Position } from 'reactflow'
import { NODE_ROW_HEIGHT, NODE_WIDTH } from './SchemaGraph.constants'
import { TableNodeData } from './TableNode'
export async function getGraphDataFromTables(tables: PostgresTable[]): Promise<{
nodes: Node<TableNodeData>[]
edges: Edge[]
}> {
if (!tables.length) {
return { nodes: [], edges: [] }
}
const nodes = tables.map((table) => {
const columns = (table.columns || []).map((column) => {
return {
id: column.id,
isPrimary: table.primary_keys.some((pk) => pk.name === column.name),
name: column.name,
format: column.format,
isNullable: column.is_nullable,
isUnique: column.is_unique,
isIdentity: column.is_identity,
}
})
return {
id: `${table.id}`,
type: 'table',
data: {
name: table.name,
isForeign: false,
columns,
},
position: { x: 0, y: 0 },
}
})
const edges: Edge[] = []
// const currentSchema = tables[0].schema
const uniqueRelationships = uniqBy(
tables.flatMap((t) => t.relationships),
'id'
)
for (const rel of uniqueRelationships) {
// TODO: Support [external->this] relationship?
// if (rel.source_schema !== currentSchema) {
// continue
// }
// Create additional [this->foreign] node that we can point to on the graph.
// if (rel.target_table_schema !== currentSchema) {
// nodes.push({
// id: rel.constraint_name,
// type: 'table',
// data: {
// name: `${rel.target_table_schema}.${rel.target_table_name}.${rel.target_column_name}`,
// isForeign: true,
// columns: [],
// },
// position: { x: 0, y: 0 },
// })
// const [source, sourceHandle] = findTablesHandleIds(
// tables,
// rel.source_table_name,
// rel.source_column_name
// )
// if (source) {
// edges.push({
// id: String(rel.id),
// source,
// sourceHandle,
// target: rel.constraint_name,
// targetHandle: rel.constraint_name,
// })
// }
// continue
// }
const [source, sourceHandle] = findTablesHandleIds(
tables,
rel.source_table_name,
rel.source_column_name
)
const [target, targetHandle] = findTablesHandleIds(
tables,
rel.target_table_name,
rel.target_column_name
)
// We do not support [external->this] flow currently.
if (source && target) {
edges.push({
id: String(rel.id),
source,
sourceHandle,
target,
targetHandle,
})
}
}
return getLayoutedElements(nodes, edges)
}
function findTablesHandleIds(
tables: PostgresTable[],
table_name: string,
column_name: string
): [string?, string?] {
for (const table of tables) {
if (table_name !== table.name) continue
for (const column of table.columns || []) {
if (column_name !== column.name) continue
return [String(table.id), column.id]
}
}
return []
}
const getLayoutedElements = (nodes: Node[], edges: Edge[]) => {
const dagreGraph = new dagre.graphlib.Graph()
dagreGraph.setDefaultEdgeLabel(() => ({}))
dagreGraph.setGraph({
rankdir: 'LR',
align: 'UR',
nodesep: 25,
ranksep: 50,
})
nodes.forEach((node) => {
dagreGraph.setNode(node.id, {
width: NODE_WIDTH / 2,
height: (NODE_ROW_HEIGHT / 2) * (node.data.columns.length + 1), // columns + header
})
})
edges.forEach((edge) => {
dagreGraph.setEdge(edge.source, edge.target)
})
dagre.layout(dagreGraph)
nodes.forEach((node) => {
const nodeWithPosition = dagreGraph.node(node.id)
node.targetPosition = Position.Left
node.sourcePosition = Position.Right
// We are shifting the dagre node position (anchor=center center) to the top left
// so it matches the React Flow node anchor point (top left).
node.position = {
x: nodeWithPosition.x - nodeWithPosition.width / 2,
y: nodeWithPosition.y - nodeWithPosition.height / 2,
}
return node
})
return { nodes, edges }
}

View File

@@ -0,0 +1,134 @@
import { Diamond, DiamondIcon, Fingerprint, Hash, Key, Table, Table2 } from 'lucide-react'
import { IconHash, IconKey, cn } from 'ui'
import { Handle, NodeProps } from 'reactflow'
import { NODE_WIDTH } from './SchemaGraph.constants'
export type TableNodeData = {
name: string
isForeign: boolean
columns: {
id: string
isPrimary: boolean
isNullable: boolean
isUnique: boolean
isIdentity: boolean
name: string
format: string
}[]
}
const TableNode = ({ data, targetPosition, sourcePosition }: NodeProps<TableNodeData>) => {
// Important styles is a nasty hack to use Handles (required for edges calculations), but do not show them in the UI.
// ref: https://github.com/wbkd/react-flow/discussions/2698
const hiddenNodeConnector = '!h-px !w-px !min-w-0 !min-h-0 !cursor-grab !border-0 !opacity-0'
const itemHeight = 'h-[22px]'
return (
<>
{data.isForeign ? (
<div className="rounded-lg">
<header className="text-[0.5rem] leading-5 font-bold px-2 text-center bg-brand text-gray-300">
{data.name}
{targetPosition && (
<Handle
type="target"
id={data.name}
position={targetPosition}
className={cn(hiddenNodeConnector, '!left-0')}
/>
)}
</header>
</div>
) : (
<div
className="border border-[0.5px] overflow-hidden rounded-[4px] shadow-sm"
style={{ width: NODE_WIDTH / 2 }}
>
<header
className={cn(
'text-[0.55rem] px-2 bg-alternative text-default flex gap-1 items-center',
itemHeight
)}
>
<Table2 strokeWidth={1} size={12} className="text-light" />
{data.name}
</header>
{data.columns.map((column) => (
<div
className={cn(
'text-[8px] leading-5 relative flex flex-row justify-items-start',
'bg-surface-100',
'border-t',
'border-t-[0.5px]',
// 'odd:bg-scale-300',
// 'even:bg-scale-400',
'hover:bg-scale-500 transition cursor-default',
itemHeight
)}
key={column.id}
>
<div className="gap-[0.24rem] flex mx-2 align-middle basis-1/5 items-center justify-start">
{column.isPrimary && (
<Key
size={8}
strokeWidth={1}
className={cn(
// 'sb-grid-column-header__inner__primary-key'
'flex-shrink-0',
'text-light'
)}
/>
)}
{column.isNullable && (
<DiamondIcon size={8} strokeWidth={1} className="flex-shrink-0 text-light" />
)}
{!column.isNullable && (
<DiamondIcon
size={8}
strokeWidth={1}
fill="currentColor"
className="flex-shrink-0 text-light"
/>
)}
{column.isUnique && (
<Fingerprint size={8} strokeWidth={1} className="flex-shrink-0 text-light" />
)}
{column.isIdentity && (
<Hash size={8} strokeWidth={1} className="flex-shrink-0 text-light" />
)}
</div>
<div className="flex w-full justify-between">
<span className="text-ellipsis overflow-hidden whitespace-nowrap">
{column.name}
</span>
<span className="px-2 inline-flex justify-end font-mono text-lighter text-[0.4rem]">
{column.format}
</span>
</div>
{targetPosition && (
<Handle
type="target"
id={column.id}
position={targetPosition}
className={cn(hiddenNodeConnector, '!left-0')}
/>
)}
{sourcePosition && (
<Handle
type="source"
id={column.id}
position={sourcePosition}
className={cn(hiddenNodeConnector, '!right-0')}
/>
)}
</div>
))}
</div>
)}
</>
)
}
export default TableNode

View File

@@ -1,112 +0,0 @@
import Link from 'next/link'
import Step from './Step'
import Code from '@/components/Code'
const create = `
create table notes (
id serial primary key,
title text
);
insert into notes(title)
values
('Today I created a Supabase project.'),
('I added some data and queried it from Next.js.'),
('It was awesome!');
`.trim()
const server = `
import { createClient } from '@/utils/supabase/server'
import { cookies } from 'next/headers'
export default async function Page() {
const cookieStore = cookies()
const supabase = createClient(cookieStore)
const { data: notes } = await supabase.from('notes').select()
return <pre>{JSON.stringify(notes, null, 2)}</pre>
}
`.trim()
const client = `
'use client'
import { createClient } from '@/utils/supabase/client'
import { useEffect, useState } from 'react'
export default function Page() {
const [notes, setNotes] = useState<any[] | null>(null)
const supabase = createClient()
useEffect(() => {
const getData = async () => {
const { data } = await supabase.from('notes').select()
setNotes(data)
}
getData()
}, [])
return <pre>{JSON.stringify(notes, null, 2)}</pre>
}
`.trim()
export default function SignUpUserSteps() {
return (
<ol className="flex flex-col gap-6">
<Step title="Sign up your first user">
<p>
Head over to the{' '}
<Link href="/login" className="font-bold hover:underline text-foreground/80">
Login
</Link>{' '}
page and sign up your first user. It's okay if this is just you for now. Your awesome idea
will have plenty of users later!
</p>
</Step>
<Step title="Create some tables and insert some data">
<p>
Head over to the{' '}
<a
href="https://supabase.com/dashboard/project/_/editor"
className="font-bold hover:underline text-foreground/80"
target="_blank"
rel="noreferrer"
>
Table Editor
</a>{' '}
for your Supabase project to create a table and insert some example data. If you're stuck
for creativity, you can copy and paste the following into the{' '}
<a
href="https://supabase.com/dashboard/project/_/sql/new"
className="font-bold hover:underline text-foreground/80"
target="_blank"
rel="noreferrer"
>
SQL Editor
</a>{' '}
and click RUN!
</p>
<Code code={create} />
</Step>
<Step title="Query Supabase data from Next.js">
<p>
To create a Supabase client and query data from an Async Server Component, create a new
page.tsx file at{' '}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
/app/notes/page.tsx
</span>{' '}
and add the following.
</p>
<Code code={server} />
<p>Alternatively, you can use a Client Component.</p>
<Code code={client} />
</Step>
<Step title="Build in a weekend and scale to millions!">
<p>You're ready to launch your product to the world! 🚀</p>
</Step>
</ol>
)
}

View File

@@ -1,14 +0,0 @@
export default function Step({ title, children }: { title: string; children: React.ReactNode }) {
return (
<li className="mx-4">
<input type="checkbox" id={title} className={`mr-2 peer`} />
<label
htmlFor={title}
className={`text-lg text-foreground/90 peer-checked:line-through font-semibold hover:cursor-pointer`}
>
{title}
</label>
<div className={`mx-6 text-foreground/80 text-sm peer-checked:line-through`}>{children}</div>
</li>
)
}

View File

@@ -1,102 +0,0 @@
export default function SupabaseLogo() {
return (
<svg
aria-label="Supabase logo"
width="140"
height="30"
viewBox="0 0 115 23"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clipPath="url(#clip0_4671_51136)">
<g clipPath="url(#clip1_4671_51136)">
<path
d="M13.4028 21.8652C12.8424 22.5629 11.7063 22.1806 11.6928 21.2898L11.4954 8.25948H20.3564C21.9614 8.25948 22.8565 10.0924 21.8585 11.3353L13.4028 21.8652Z"
fill="url(#paint0_linear_4671_51136)"
/>
<path
d="M13.4028 21.8652C12.8424 22.5629 11.7063 22.1806 11.6928 21.2898L11.4954 8.25948H20.3564C21.9614 8.25948 22.8565 10.0924 21.8585 11.3353L13.4028 21.8652Z"
fill="url(#paint1_linear_4671_51136)"
fillOpacity="0.2"
/>
<path
d="M9.79895 0.89838C10.3593 0.200591 11.4954 0.582929 11.5089 1.47383L11.5955 14.5041H2.84528C1.24026 14.5041 0.345103 12.6711 1.34316 11.4283L9.79895 0.89838Z"
fill="#3ECF8E"
/>
</g>
<path
d="M30.5894 13.3913C30.7068 14.4766 31.7052 16.3371 34.6026 16.3371C37.1279 16.3371 38.3418 14.7479 38.3418 13.1976C38.3418 11.8022 37.3824 10.6588 35.4836 10.2712L34.1131 9.98049C33.5846 9.88359 33.2323 9.5929 33.2323 9.12777C33.2323 8.58512 33.7804 8.17818 34.4656 8.17818C35.5618 8.17818 35.9729 8.89521 36.0513 9.45725L38.2243 8.97275C38.1069 7.94561 37.1867 6.22083 34.446 6.22083C32.3709 6.22083 30.844 7.63555 30.844 9.34094C30.844 10.6781 31.6856 11.7828 33.5454 12.1898L34.8179 12.4805C35.5618 12.6355 35.8555 12.9844 35.8555 13.4107C35.8555 13.9146 35.4444 14.3603 34.583 14.3603C33.4476 14.3603 32.8797 13.6626 32.8212 12.9068L30.5894 13.3913Z"
fill="currentColor"
/>
<path
d="M46.6623 16.0464H49.1486C49.1094 15.717 49.0506 15.0581 49.0506 14.3216V6.51154H46.4468V12.0542C46.4468 13.1588 45.7813 13.934 44.6263 13.934C43.4126 13.934 42.8643 13.0813 42.8643 12.0154V6.51154H40.2606V12.5387C40.2606 14.6123 41.5918 16.2984 43.9215 16.2984C44.9393 16.2984 46.0556 15.9108 46.5841 15.0193C46.5841 15.4069 46.6231 15.8526 46.6623 16.0464Z"
fill="currentColor"
/>
<path
d="M54.433 19.7286V15.1162C54.9027 15.7558 55.8817 16.279 57.213 16.279C59.9341 16.279 61.7545 14.1472 61.7545 11.2596C61.7545 8.43021 60.1298 6.29842 57.3108 6.29842C55.8623 6.29842 54.7855 6.93792 54.3548 7.67439V6.51159H51.8295V19.7286H54.433ZM59.19 11.279C59.19 12.9845 58.133 13.9728 56.8017 13.9728C55.4708 13.9728 54.394 12.9651 54.394 11.279C54.394 9.59299 55.4708 8.6046 56.8017 8.6046C58.133 8.6046 59.19 9.59299 59.19 11.279Z"
fill="currentColor"
/>
<path
d="M63.229 13.4495C63.229 14.9417 64.4818 16.3177 66.5375 16.3177C67.9662 16.3177 68.8865 15.6588 69.3758 14.9029C69.3758 15.2712 69.4149 15.7944 69.4737 16.0464H71.862C71.8033 15.7169 71.7449 15.0386 71.7449 14.5348V9.84482C71.7449 7.92622 70.6093 6.22083 67.5555 6.22083C64.9713 6.22083 63.5811 7.86807 63.4248 9.36033L65.7347 9.84482C65.8131 9.0115 66.4395 8.29445 67.5747 8.29445C68.6713 8.29445 69.1998 8.85646 69.1998 9.53475C69.1998 9.86421 69.0238 10.1355 68.4755 10.2131L66.1068 10.5619C64.5015 10.7945 63.229 11.744 63.229 13.4495ZM67.0854 14.3991C66.2438 14.3991 65.8325 13.8565 65.8325 13.2945C65.8325 12.558 66.361 12.1898 67.0268 12.0929L69.1998 11.7634V12.1898C69.1998 13.8759 68.1818 14.3991 67.0854 14.3991Z"
fill="currentColor"
/>
<path
d="M76.895 16.0465V14.8837C77.4038 15.6976 78.4217 16.279 79.7531 16.279C82.4941 16.279 84.2951 14.1278 84.2951 11.2403C84.2951 8.4108 82.6701 6.25965 79.851 6.25965C78.4217 6.25965 77.3648 6.8798 76.934 7.55806V2.01546H74.3696V16.0465H76.895ZM81.6911 11.2596C81.6911 13.0038 80.6341 13.9728 79.3028 13.9728C77.9912 13.9728 76.895 12.9845 76.895 11.2596C76.895 9.51543 77.9912 8.56584 79.3028 8.56584C80.6341 8.56584 81.6911 9.51543 81.6911 11.2596Z"
fill="currentColor"
/>
<path
d="M85.7692 13.4495C85.7692 14.9417 87.022 16.3177 89.0776 16.3177C90.5065 16.3177 91.4269 15.6588 91.916 14.9029C91.916 15.2712 91.9554 15.7944 92.014 16.0464H94.4023C94.3439 15.7169 94.2851 15.0386 94.2851 14.5348V9.84482C94.2851 7.92622 93.1495 6.22083 90.0955 6.22083C87.5115 6.22083 86.1216 7.86807 85.965 9.36033L88.2747 9.84482C88.3533 9.0115 88.9798 8.29445 90.1149 8.29445C91.2115 8.29445 91.74 8.85646 91.74 9.53475C91.74 9.86421 91.5638 10.1355 91.0156 10.2131L88.647 10.5619C87.0418 10.7945 85.7692 11.744 85.7692 13.4495ZM89.6258 14.3991C88.784 14.3991 88.3727 13.8565 88.3727 13.2945C88.3727 12.558 88.9012 12.1898 89.5671 12.0929L91.74 11.7634V12.1898C91.74 13.8759 90.722 14.3991 89.6258 14.3991Z"
fill="currentColor"
/>
<path
d="M96.087 13.3913C96.2042 14.4766 97.2028 16.3371 100.1 16.3371C102.626 16.3371 103.839 14.7479 103.839 13.1976C103.839 11.8022 102.88 10.6588 100.981 10.2712L99.6105 9.98049C99.082 9.88359 98.7299 9.5929 98.7299 9.12777C98.7299 8.58512 99.2778 8.17818 99.963 8.17818C101.06 8.17818 101.471 8.89521 101.549 9.45725L103.722 8.97275C103.604 7.94561 102.684 6.22083 99.9436 6.22083C97.8683 6.22083 96.3416 7.63555 96.3416 9.34094C96.3416 10.6781 97.183 11.7828 99.043 12.1898L100.316 12.4805C101.06 12.6355 101.353 12.9844 101.353 13.4107C101.353 13.9146 100.942 14.3603 100.081 14.3603C98.9451 14.3603 98.3776 13.6626 98.3188 12.9068L96.087 13.3913Z"
fill="currentColor"
/>
<path
d="M107.794 10.1937C107.852 9.32158 108.596 8.31381 109.947 8.31381C111.435 8.31381 112.062 9.24406 112.101 10.1937H107.794ZM112.355 12.6743C112.042 13.527 111.376 14.1278 110.163 14.1278C108.87 14.1278 107.794 13.2169 107.735 11.9573H114.626C114.626 11.9184 114.665 11.5309 114.665 11.1626C114.665 8.10064 112.884 6.22083 109.908 6.22083C107.441 6.22083 105.17 8.19753 105.17 11.2402C105.17 14.4572 107.5 16.3371 110.143 16.3371C112.512 16.3371 114.039 14.9611 114.528 13.3138L112.355 12.6743Z"
fill="currentColor"
/>
</g>
<defs>
<linearGradient
id="paint0_linear_4671_51136"
x1="11.4954"
y1="11.1486"
x2="19.3439"
y2="14.4777"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#249361" />
<stop offset="1" stopColor="#3ECF8E" />
</linearGradient>
<linearGradient
id="paint1_linear_4671_51136"
x1="8.00382"
y1="6.42177"
x2="11.5325"
y2="13.1398"
gradientUnits="userSpaceOnUse"
>
<stop />
<stop offset="1" stopOpacity="0" />
</linearGradient>
<clipPath id="clip0_4671_51136">
<rect
width="113.85"
height="21.8943"
fill="currentColor"
transform="translate(0.922119 0.456161)"
/>
</clipPath>
<clipPath id="clip1_4671_51136">
<rect
width="21.3592"
height="21.8943"
fill="currentColor"
transform="translate(0.919006 0.497101)"
/>
</clipPath>
</defs>
</svg>
)
}

View File

@@ -0,0 +1,11 @@
'use client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PropsWithChildren } from 'react'
const queryClient = new QueryClient()
export function ReactQueryProvider({ children }: PropsWithChildren) {
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
}
export { ThemeProvider } from 'common'

View File

@@ -0,0 +1,52 @@
import { useQuery } from '@tanstack/react-query'
export type ConversationsVariables = {
userId: string
enabled?: boolean
}
// Just update based on the schema - or use the dashboard's type generation feature 😉
export type Conversation = {
id: string
name: string
threadId: string
runId: string
createdAt: string
updatedAt: string
}
export const useConversationsQuery = ({ userId, enabled }: ConversationsVariables) =>
useQuery<Conversation[]>({
queryKey: [userId, 'conversations'],
enabled: enabled && !!userId,
queryFn: async () => {
// [Joshen] Just mocking the conversations data, to replace with fetching from Supabase
const getConversations = (): Promise<Conversation[]> => {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve([
{
id: '1',
name: 'Twitter clone',
threadId: 'thread_vrXIl16bUusqFMUFYDw8CoEy',
runId: 'run_4DiPb5ppb5hwY1y6dT1qEWzc',
createdAt: '2022-07-29 07:53:58.560926+00',
updatedAt: '2022-07-29 07:53:58.560926+00',
},
{
id: '2',
name: 'Supabase clone',
threadId: 'thread_vrXIl16bUusqFMUFYDw8CoEy',
runId: 'run_4DiPb5ppb5hwY1y6dT1qEWzc',
createdAt: '2022-07-29 07:53:58.560926+00',
updatedAt: '2022-07-30 07:53:58.560926+00',
},
])
}, 100)
})
}
const result = await getConversations()
return result
},
})

View File

@@ -0,0 +1,28 @@
import { useQuery } from '@tanstack/react-query'
import { ReadThreadAPIResult } from '@/lib/types'
export type MessagesVariables = {
threadId: string
runId: string
enabled?: boolean
}
export const useMessagesQuery = ({ threadId, runId, enabled }: MessagesVariables) =>
useQuery<ReadThreadAPIResult>({
queryKey: [threadId, runId],
enabled: enabled && !!(threadId && runId),
queryFn: async () => {
const response = await fetch(`/api/ai/sql/threads/${threadId}/read/${runId}`, {
method: 'GET',
})
const result = await response.json()
return result
},
refetchInterval: (options) => {
const data = options.state.data
if (data && data.status === 'completed') {
return Infinity
} else return 5000
},
})

View File

@@ -0,0 +1,12 @@
import { proxy, snapshot, useSnapshot } from 'valtio'
export const appState = proxy({
hideCode: false,
setHideCode: (value: boolean) => {
appState.hideCode = value
},
})
export const getAppStateSnapshot = () => snapshot(appState)
export const useAppStateSnapshot = (options?: Parameters<typeof useSnapshot>[1]) =>
useSnapshot(appState, options)

View File

@@ -0,0 +1,45 @@
export type GeneratedTable = Partial<PostgresTable>
export type AssistantMessage = {
id: string
role: 'assistant'
created_at: number
sql: string
json: GeneratedTable[]
}
export type UserMessage = {
id: string
role: 'user'
created_at: number
text: string
}
export type Message = AssistantMessage | UserMessage
export type ReadThreadAPIResult = {
id: string
status: 'loading' | 'completed'
messages: Message[]
}
export type PostgresColumn = {
id: string
name: string
format: string
is_nullable: boolean
is_unique: boolean
is_identity: boolean
}
export type PostgresTable = {
id: string
name: string
primary_keys: { name: string }[]
relationships: {
id: string
target_table_name: string
target_column_name: string
source_table_name: string
source_column_name: string
}[]
columns: PostgresColumn[]
}

View File

@@ -0,0 +1,226 @@
import { parseQuery } from '@gregnr/libpg-query'
import { compact } from 'lodash'
import { z } from 'zod'
import { PostgresColumn, PostgresTable } from './types'
const constraintDefinitionSchema = z.object({
Constraint: z.discriminatedUnion('contype', [
z
.object({
contype: z.literal('CONSTR_PRIMARY'),
keys: z
.array(
z.object({
String: z.object({
sval: z.string(),
}),
})
)
.optional(),
})
.passthrough(),
z.object({
contype: z.literal('CONSTR_IDENTITY'),
}),
z.object({
contype: z.literal('CONSTR_NOTNULL'),
}),
z.object({
contype: z.literal('CONSTR_UNIQUE'),
}),
z.object({
contype: z.literal('CONSTR_DEFAULT'),
}),
z.object({
contype: z.literal('CONSTR_FOREIGN'),
pktable: z.object({
relname: z.string(),
}),
fk_attrs: z
.array(
z.object({
String: z.object({
sval: z.string(),
}),
})
)
.optional(),
pk_attrs: z.array(
z.object({
String: z.object({
sval: z.string(),
}),
})
),
}),
]),
})
const columnDefinitionSchema = z.object({
ColumnDef: z.object({
colname: z.string(),
typeName: z.object({
names: z.array(
z.object({
String: z.object({
sval: z.string(),
}),
})
),
}),
constraints: z.array(constraintDefinitionSchema).optional(),
}),
})
const tableDefinitionSchema = z.object({
CreateStmt: z.object({
relation: z.object({
relname: z.string(),
}),
tableElts: z.array(z.union([columnDefinitionSchema, constraintDefinitionSchema])),
}),
})
const parseQueryResultSchema = z.object({
stmts: z.array(
z.object({
stmt: tableDefinitionSchema,
})
),
})
/**
* Parses SQL into tables compatible with the existing schema visualizer.
*
* TODO: consider running in WebWorker
*/
export async function parseTables(sql: string) {
// Parse SQL using the real Postgres parser (compiled to WASM)
// See: https://github.com/pyramation/libpg-query-node/pull/34
const result = await parseQuery(sql)
const parsedSql = parseQueryResultSchema.safeParse(result)
if (!parsedSql.success) {
console.log(parsedSql.error)
return []
}
// This code generates all columns with their constraints
const pgTables: PostgresTable[] = parsedSql.data.stmts
.filter(({ stmt }) => 'CreateStmt' in stmt)
.map(({ stmt }) => {
const statement = stmt.CreateStmt
const columns = compact(
statement.tableElts.map((column) => {
if ('ColumnDef' in column) {
const format = column.ColumnDef.typeName.names.find(
({ String: { sval } }) => sval !== 'pg_catalog'
)?.String.sval
if (!format) {
return undefined
}
const constraints = (column.ColumnDef.constraints || []).map(
(c) => c.Constraint.contype
)
const result: PostgresColumn = {
name: column.ColumnDef.colname,
format: format,
id: column.ColumnDef.colname,
is_nullable: !constraints.includes('CONSTR_NOTNULL'),
is_unique: constraints.includes('CONSTR_UNIQUE'),
is_identity: constraints.includes('CONSTR_IDENTITY'),
}
return result
}
})
)
// This code processes user_id bigint references users (id) SQL.
const columnRelationships = compact(
statement.tableElts.map((column) => {
if ('ColumnDef' in column) {
const found = (column.ColumnDef.constraints || []).find(
(c) => c.Constraint.contype === 'CONSTR_FOREIGN'
)
if (found && found.Constraint.contype === 'CONSTR_FOREIGN') {
return {
id: `${statement.relation.relname}_${column.ColumnDef.colname}_${found.Constraint.pktable.relname}_${found.Constraint.pk_attrs[0].String.sval}`,
source_table_name: statement.relation.relname,
source_column_name: column.ColumnDef.colname,
target_table_name: found.Constraint.pktable.relname,
target_column_name: found.Constraint.pk_attrs[0].String.sval,
}
}
}
})
)
// This code processes foreign key (tweet_user_username, tweet_content) references tweets (user_username, content) SQL. It supports composite keys between two tables
const tableRelationships = compact(
statement.tableElts.flatMap((constraint) => {
if ('Constraint' in constraint) {
if (
constraint.Constraint.contype === 'CONSTR_FOREIGN' &&
constraint.Constraint.fk_attrs &&
constraint.Constraint.pk_attrs.length === constraint.Constraint.fk_attrs.length
) {
const pkTable = constraint.Constraint.pktable
const pgAttrs = constraint.Constraint.pk_attrs
return constraint.Constraint.fk_attrs.map((attr, index) => {
return {
id: `${statement.relation.relname}_${attr.String.sval}_${pkTable.relname}_${pgAttrs[index].String.sval}`,
source_table_name: statement.relation.relname,
source_column_name: attr.String.sval,
target_table_name: pkTable.relname,
target_column_name: pgAttrs[index].String.sval,
}
})
}
}
})
)
const columnPrimaryKeys = compact(
statement.tableElts.map((column) => {
if ('ColumnDef' in column) {
const constraint = (column.ColumnDef.constraints || []).find(
(c) => c.Constraint.contype === 'CONSTR_PRIMARY'
)
if (constraint) {
return { name: column.ColumnDef.colname }
}
}
})
)
// This code processes primary key (user_username, tweet_user_username, tweet_content) SQL.
const tablePrimaryKeys = compact(
statement.tableElts.flatMap((constraint) => {
if ('Constraint' in constraint) {
if (constraint.Constraint.contype === 'CONSTR_PRIMARY' && constraint.Constraint.keys) {
return constraint.Constraint.keys.map((key) => ({ name: key.String.sval }))
}
return undefined
}
})
)
const table: PostgresTable = {
name: statement.relation.relname,
columns,
id: statement.relation.relname,
primary_keys: [...columnPrimaryKeys, ...tablePrimaryKeys],
relationships: [...columnRelationships, ...tableRelationships],
}
return table
})
return pgTables
}

View File

@@ -1,25 +0,0 @@
import { NextResponse, type NextRequest } from 'next/server'
import { createClient } from '@/utils/supabase/middleware'
export async function middleware(request: NextRequest) {
try {
// This `try/catch` block is only here for the interactive tutorial.
// Feel free to remove once you have Supabase connected.
const { supabase, response } = createClient(request)
// Refresh session if expired - required for Server Components
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-session-with-middleware
await supabase.auth.getSession()
return response
} catch (e) {
// If you are here, a Supabase client could not be created!
// This is likely because you have not set up environment variables.
// Check out http://localhost:3000 for Next Steps.
return NextResponse.next({
request: {
headers: request.headers,
},
})
}
}

View File

@@ -1,8 +1,28 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverActions: true,
transpilePackages: ['ui'],
webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
config.module.rules.push({
test: /\.node$/,
use: [
{
loader: 'nextjs-node-loader',
options: {
includeWebpackPublicPath: false,
outputPath: config.output.path,
},
},
],
})
return config
},
redirects: () => [
{
source: '/',
destination: '/new',
permanent: true,
},
],
}
module.exports = nextConfig

View File

@@ -1,25 +1,39 @@
{
"name": "database-new",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev --port 3002",
"build": "next build",
"start": "next start"
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@supabase/ssr": "latest",
"@supabase/supabase-js": "latest",
"autoprefixer": "10.4.15",
"geist": "^1.0.0",
"@dagrejs/dagre": "^1.0.4",
"@gregnr/libpg-query": "13.4.0-dev.12",
"@monaco-editor/react": "^4.6.0",
"@tanstack/react-query": "^5.7.2",
"common": "*",
"config": "*",
"dayjs": "^1.11.10",
"lodash": "^4.17.21",
"lucide-react": "^0.292.0",
"next": "^13.5.3",
"postcss": "8.4.29",
"openai": "^4.17.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "3.3.3",
"typescript": "^5.2.2"
"react-flow": "^1.0.3",
"sql-formatter": "^13.1.0",
"ui": "*",
"valtio": "^1.12.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.2.24",
"encoding": "^0.1.13"
"@types/react-dom": "^18.2.8",
"autoprefixer": "10.4.14",
"nextjs-node-loader": "^1.1.5-alpha.0",
"postcss": "8.4.29",
"typescript": "^5.2.2"
}
}

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 461 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>

After

Width:  |  Height:  |  Size: 629 B

View File

@@ -1,17 +1,18 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./app/**/*.{js,ts,jsx,tsx,mdx}', './components/**/*.{js,ts,jsx,tsx,mdx}'],
const config = require('config/tailwind.config')
export default config({
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
'../../packages/ui/src/**/*.{tsx,ts,js}',
],
theme: {
extend: {
colors: {
background: 'hsl(var(--background))',
foreground: 'hsl(var(--foreground))',
btn: {
background: 'hsl(var(--btn-background))',
'background-hover': 'hsl(var(--btn-background-hover))',
},
dbnew: '#6046FA',
},
},
},
plugins: [],
}
})

View File

@@ -1,15 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
@@ -20,7 +19,9 @@
}
],
"paths": {
"@/*": ["./*"]
"@/*": ["./*"],
// handle ui package paths
"@ui/*": ["./../../packages/ui/src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],

12
apps/database-new/types/sse.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
declare module 'sse.js' {
export type SSEOptions = EventSourceInit & {
headers?: Record<string, string>
payload?: string
method?: string
}
export class SSE extends EventSource {
constructor(url: string | URL, sseOptions?: SSEOptions)
stream(): void
}
}

View File

@@ -1,7 +0,0 @@
import { createBrowserClient } from '@supabase/ssr'
export const createClient = () =>
createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)

View File

@@ -1,61 +0,0 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { type NextRequest, NextResponse } from 'next/server'
export const createClient = (request: NextRequest) => {
// Create an unmodified response
let response = NextResponse.next({
request: {
headers: request.headers,
},
})
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return request.cookies.get(name)?.value
},
set(name: string, value: string, options: CookieOptions) {
// If the cookie is updated, update the cookies for the request and response
request.cookies.set({
name,
value,
...options,
})
response = NextResponse.next({
request: {
headers: request.headers,
},
})
response.cookies.set({
name,
value,
...options,
})
},
remove(name: string, options: CookieOptions) {
// If the cookie is removed, update the cookies for the request and response
request.cookies.set({
name,
value: '',
...options,
})
response = NextResponse.next({
request: {
headers: request.headers,
},
})
response.cookies.set({
name,
value: '',
...options,
})
},
},
}
)
return { supabase, response }
}

View File

@@ -1,34 +0,0 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'
export const createClient = (cookieStore: ReturnType<typeof cookies>) => {
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return cookieStore.get(name)?.value
},
set(name: string, value: string, options: CookieOptions) {
try {
cookieStore.set({ name, value, ...options })
} catch (error) {
// The `set` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
remove(name: string, options: CookieOptions) {
try {
cookieStore.set({ name, value: '', ...options })
} catch (error) {
// The `delete` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
)
}

11305
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@
"dev:studio": "turbo run dev --filter=studio --parallel",
"dev:docs": "turbo run dev --filter=docs --parallel",
"dev:www": "turbo run dev --filter=www --parallel",
"dev:database-new": "turbo run dev --filter=database-new --parallel",
"lint": "turbo run lint",
"typecheck": "turbo --continue typecheck",
"format": "prettier --write \"apps/**/*.{js,jsx,ts,tsx,css,md,mdx,json}\"",

View File

@@ -9,6 +9,7 @@ import InputIconContainer from '../../lib/Layout/InputIconContainer'
import { HIDDEN_PLACEHOLDER } from './../../lib/constants'
import { cn } from '@ui/lib/utils/cn'
import styleHandler from '../../lib/theme/styleHandler'
import { useFormContext } from '../Form/FormContext'
@@ -170,7 +171,7 @@ function Input({
ref={inputRef}
type={type}
value={reveal && hidden ? HIDDEN_PLACEHOLDER : value}
className={inputClasses.join(' ')}
className={cn(inputClasses)}
{...props}
/>
{icon && <InputIconContainer icon={icon} className={iconContainerClassName} />}