Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add type generation from local dashboard

kishanhitkd1b9242edfca
diff --git a/studio/pages/api/v1/projects/[ref]/types/typescript.ts b/studio/pages/api/v1/projects/[ref]/types/typescript.ts
new file mode 100644
index 00000000000..56fc47a33cc
--- /dev/null
+++ b/studio/pages/api/v1/projects/[ref]/types/typescript.ts
@@ -0,0 +1,38 @@
+import { NextApiRequest, NextApiResponse } from 'next'
+import { PG_META_URL } from 'lib/constants'
+import apiWrapper from 'lib/api/apiWrapper'
+import { constructHeaders } from 'lib/api/apiHelpers'
+import { get } from 'lib/common/fetch'
+
+export default (req: NextApiRequest, res: NextApiResponse) =>
+ apiWrapper(req, res, handler, { withAuth: true })
+
+async function handler(req: NextApiRequest, res: NextApiResponse) {
+ const { method } = req
+
+ switch (method) {
+ case 'GET':
+ return handleGetAll(req, res)
+ default:
+ res.setHeader('Allow', ['GET'])
+ res.status(405).json({ error: { message: `Method ${method} Not Allowed` } })
+ }
+}
+
+const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
+ const includedSchema = 'public,graphql_public,storage'
+ const excludedSchema =
+ 'auth,cron,extensions,graphql,net,pgsodium,pgsodium_masks,realtime,supabase_functions,supabase_migrations,vault,_analytics,_realtime'
+
+ const headers = constructHeaders(req.headers)
+ const response = await get(
+ `${PG_META_URL}/generators/typescript?included_schema=${includedSchema}&excluded_schemas=${excludedSchema}`,
+ { headers }
+ )
+
+ if (response.error) {
+ return res.status(400).json({ error: response.error })
+ }
+
+ return res.status(200).json({ types: response })
+}