From b6e0beaab9dc80e90fbc1c76a73056c932aad848 Mon Sep 17 00:00:00 2001 From: Daniel Staudigel Date: Thu, 18 Jul 2024 10:47:57 -0700 Subject: [PATCH] Add support for database types on different schemas. --- src/module.ts | 4 ++-- src/runtime/composables/useSupabaseClient.ts | 6 +++--- src/runtime/server/services/serverSupabaseClient.ts | 4 ++-- src/runtime/server/services/serverSupabaseServiceRole.ts | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/module.ts b/src/module.ts index dafe2e43..87fa34b3 100644 --- a/src/module.ts +++ b/src/module.ts @@ -204,10 +204,10 @@ export default defineNuxtModule({ filename: 'types/supabase-database.d.ts', getContents: async () => { if (!!options.types && fs.existsSync(await resolvePath(options.types))) { - return `export * from '${await resolvePath(options.types)}'` + return `export * from '${await resolvePath(options.types)}'; export type Schema = ${JSON.stringify(options?.clientOptions?.db?.schema || 'public')};` } - return `export type Database = unknown` + return `export type Database = unknown; export type Schema = ${JSON.stringify(options?.clientOptions?.db?.schema || 'public')};` }, }) diff --git a/src/runtime/composables/useSupabaseClient.ts b/src/runtime/composables/useSupabaseClient.ts index 26f73eb6..14e639ec 100644 --- a/src/runtime/composables/useSupabaseClient.ts +++ b/src/runtime/composables/useSupabaseClient.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from '@supabase/supabase-js' import { useNuxtApp } from '#imports' -import type { Database } from '#build/types/supabase-database' +import type { Database, Schema } from '#build/types/supabase-database' -export const useSupabaseClient = () => { - return useNuxtApp().$supabase?.client as SupabaseClient +export const useSupabaseClient = () => { + return useNuxtApp().$supabase?.client as SupabaseClient } diff --git a/src/runtime/server/services/serverSupabaseClient.ts b/src/runtime/server/services/serverSupabaseClient.ts index c9f0c8c8..789c27e2 100644 --- a/src/runtime/server/services/serverSupabaseClient.ts +++ b/src/runtime/server/services/serverSupabaseClient.ts @@ -2,9 +2,9 @@ import type { SupabaseClient } from '@supabase/supabase-js' import { createServerClient, parseCookieHeader, type CookieOptions } from '@supabase/ssr' import { getHeader, setCookie, type H3Event } from 'h3' import { useRuntimeConfig } from '#imports' -import type { Database } from '#build/types/supabase-database' +import type { Database, Schema } from '#build/types/supabase-database' -export const serverSupabaseClient = async (event: H3Event): Promise> => { +export const serverSupabaseClient = async (event: H3Event): Promise> => { // No need to recreate client if exists in request context if (!event.context._supabaseClient) { // get settings from runtime config diff --git a/src/runtime/server/services/serverSupabaseServiceRole.ts b/src/runtime/server/services/serverSupabaseServiceRole.ts index 9e14c6ad..a1a10b19 100644 --- a/src/runtime/server/services/serverSupabaseServiceRole.ts +++ b/src/runtime/server/services/serverSupabaseServiceRole.ts @@ -2,9 +2,9 @@ import type { SupabaseClient } from '@supabase/supabase-js' import { createClient } from '@supabase/supabase-js' import type { H3Event } from 'h3' import { useRuntimeConfig } from '#imports' -import type { Database } from '#build/types/supabase-database' +import type { Database, Schema } from '#build/types/supabase-database' -export const serverSupabaseServiceRole = (event: H3Event): SupabaseClient => { +export const serverSupabaseServiceRole = (event: H3Event): SupabaseClient => { const { supabase: { serviceKey }, public: {