style(supabase): prettier pass on the new TypeScript files
This commit is contained in:
1 parent
d239374d81
commit
ab04b2e43d
9 files changed
+70
-27
No files matched your search
@@ -54,17 +54,29 @@ export function resolveSupabaseConnection(
|
|||||||
const cleanKey = nonEmpty(anonKey)
|
const cleanKey = nonEmpty(anonKey)
|
||||||
if (cleanUrl && cleanKey) return { url: cleanUrl, anonKey: cleanKey }
|
if (cleanUrl && cleanKey) return { url: cleanUrl, anonKey: cleanKey }
|
||||||
if ((cleanUrl || cleanKey) && import.meta.env.DEV) {
|
if ((cleanUrl || cleanKey) && import.meta.env.DEV) {
|
||||||
console.warn('[config] supabaseUrl and supabaseAnonKey must be set together; Supabase disabled')
|
console.warn(
|
||||||
|
'[config] supabaseUrl and supabaseAnonKey must be set together; Supabase disabled',
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveConfig(runtime: RuntimeConfig = {}): AppConfig {
|
export function resolveConfig(runtime: RuntimeConfig = {}): AppConfig {
|
||||||
return {
|
return {
|
||||||
siteName: runtime.siteName ?? import.meta.env.VITE_APP_SITE_NAME ?? DEFAULTS.siteName,
|
siteName:
|
||||||
brandName: runtime.brandName ?? import.meta.env.VITE_APP_BRAND_NAME ?? DEFAULTS.brandName,
|
runtime.siteName ??
|
||||||
footerName: runtime.footerName ?? import.meta.env.VITE_APP_FOOTER_NAME ?? DEFAULTS.footerName,
|
import.meta.env.VITE_APP_SITE_NAME ??
|
||||||
tagline: runtime.tagline ?? import.meta.env.VITE_APP_TAGLINE ?? DEFAULTS.tagline,
|
DEFAULTS.siteName,
|
||||||
|
brandName:
|
||||||
|
runtime.brandName ??
|
||||||
|
import.meta.env.VITE_APP_BRAND_NAME ??
|
||||||
|
DEFAULTS.brandName,
|
||||||
|
footerName:
|
||||||
|
runtime.footerName ??
|
||||||
|
import.meta.env.VITE_APP_FOOTER_NAME ??
|
||||||
|
DEFAULTS.footerName,
|
||||||
|
tagline:
|
||||||
|
runtime.tagline ?? import.meta.env.VITE_APP_TAGLINE ?? DEFAULTS.tagline,
|
||||||
supabase: resolveSupabaseConnection(
|
supabase: resolveSupabaseConnection(
|
||||||
runtime.supabaseUrl ?? import.meta.env.VITE_SUPABASE_URL,
|
runtime.supabaseUrl ?? import.meta.env.VITE_SUPABASE_URL,
|
||||||
runtime.supabaseAnonKey ?? import.meta.env.VITE_SUPABASE_ANON_KEY,
|
runtime.supabaseAnonKey ?? import.meta.env.VITE_SUPABASE_ANON_KEY,
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ let cached: { connectionUrl: string; client: FaunosteoClient } | null = null
|
|||||||
* configured. Callers must handle null: the current local-only flows do not
|
* configured. Callers must handle null: the current local-only flows do not
|
||||||
* depend on Supabase. No UI uses this yet (foundation step).
|
* depend on Supabase. No UI uses this yet (foundation step).
|
||||||
*/
|
*/
|
||||||
export function getSupabaseClient(config: AppConfig = appConfig): FaunosteoClient | null {
|
export function getSupabaseClient(
|
||||||
|
config: AppConfig = appConfig,
|
||||||
|
): FaunosteoClient | null {
|
||||||
if (!config.supabase) return null
|
if (!config.supabase) return null
|
||||||
if (cached?.connectionUrl !== config.supabase.url) {
|
if (cached?.connectionUrl !== config.supabase.url) {
|
||||||
cached = {
|
cached = {
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ describe('resolveConfig', () => {
|
|||||||
supabaseUrl: 'http://127.0.0.1:54321',
|
supabaseUrl: 'http://127.0.0.1:54321',
|
||||||
supabaseAnonKey: 'anon',
|
supabaseAnonKey: 'anon',
|
||||||
})
|
})
|
||||||
expect(config.supabase).toEqual({ url: 'http://127.0.0.1:54321', anonKey: 'anon' })
|
expect(config.supabase).toEqual({
|
||||||
|
url: 'http://127.0.0.1:54321',
|
||||||
|
anonKey: 'anon',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('still resolves identity strings injected at runtime', () => {
|
it('still resolves identity strings injected at runtime', () => {
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ export default tseslint.config(
|
|||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-explicit-any': 'warn',
|
'@typescript-eslint/no-explicit-any': 'warn',
|
||||||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
'@typescript-eslint/no-unused-vars': [
|
||||||
|
'error',
|
||||||
|
{ argsIgnorePattern: '^_' },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -17,7 +17,9 @@ export interface SupabaseConnection {
|
|||||||
* Browser client: session persisted in localStorage, tokens refreshed in the
|
* Browser client: session persisted in localStorage, tokens refreshed in the
|
||||||
* background, PKCE for OAuth and magic-link redirects.
|
* background, PKCE for OAuth and magic-link redirects.
|
||||||
*/
|
*/
|
||||||
export function createBrowserClient(connection: SupabaseConnection): FaunosteoClient {
|
export function createBrowserClient(
|
||||||
|
connection: SupabaseConnection,
|
||||||
|
): FaunosteoClient {
|
||||||
return createClient<Database>(connection.url, connection.anonKey, {
|
return createClient<Database>(connection.url, connection.anonKey, {
|
||||||
auth: {
|
auth: {
|
||||||
persistSession: true,
|
persistSession: true,
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ describe('createBrowserClient', () => {
|
|||||||
expect(typeof client.from).toBe('function')
|
expect(typeof client.from).toBe('function')
|
||||||
expect(client.auth).toBeDefined()
|
expect(client.auth).toBeDefined()
|
||||||
// supabase-js keeps the resolved REST URL on the client instance.
|
// supabase-js keeps the resolved REST URL on the client instance.
|
||||||
expect(String((client as unknown as { supabaseUrl: string }).supabaseUrl)).toContain(
|
expect(
|
||||||
'127.0.0.1:54321',
|
String((client as unknown as { supabaseUrl: string }).supabaseUrl),
|
||||||
)
|
).toContain('127.0.0.1:54321')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('exposes the platform roles as runtime constants', () => {
|
it('exposes the platform roles as runtime constants', () => {
|
||||||
|
|||||||
@@ -64,7 +64,10 @@ function collectTapLines(results: Array<{ rows: unknown[] }>): string[] {
|
|||||||
* Runs one pgTAP file (which must wrap itself in begin/rollback) and reports
|
* Runs one pgTAP file (which must wrap itself in begin/rollback) and reports
|
||||||
* every `not ok` line plus plan mismatches announced by finish().
|
* every `not ok` line plus plan mismatches announced by finish().
|
||||||
*/
|
*/
|
||||||
export async function runPgTapFile(db: PGlite, file: string): Promise<TapReport> {
|
export async function runPgTapFile(
|
||||||
|
db: PGlite,
|
||||||
|
file: string,
|
||||||
|
): Promise<TapReport> {
|
||||||
const sql = await readFile(join(pgTapTestsDir, file), 'utf8')
|
const sql = await readFile(join(pgTapTestsDir, file), 'utf8')
|
||||||
let lines: string[]
|
let lines: string[]
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -4,11 +4,7 @@
|
|||||||
* assertion message, so a red test names the exact pgTAP check.
|
* assertion message, so a red test names the exact pgTAP check.
|
||||||
*/
|
*/
|
||||||
import type { PGlite } from '@electric-sql/pglite'
|
import type { PGlite } from '@electric-sql/pglite'
|
||||||
import {
|
import { createMigratedDatabase, listPgTapTests, runPgTapFile } from './harness'
|
||||||
createMigratedDatabase,
|
|
||||||
listPgTapTests,
|
|
||||||
runPgTapFile,
|
|
||||||
} from './harness'
|
|
||||||
|
|
||||||
const files = await listPgTapTests()
|
const files = await listPgTapTests()
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import { createMigratedDatabase } from './harness'
|
|||||||
type Tables = Database['public']['Tables']
|
type Tables = Database['public']['Tables']
|
||||||
type Functions = Database['public']['Functions']
|
type Functions = Database['public']['Functions']
|
||||||
|
|
||||||
type ColumnMap = { readonly [T in keyof Tables]: readonly (keyof Tables[T]['Row'] & string)[] }
|
type ColumnMap = {
|
||||||
|
readonly [T in keyof Tables]: readonly (keyof Tables[T]['Row'] & string)[]
|
||||||
|
}
|
||||||
|
|
||||||
const expectedColumns = {
|
const expectedColumns = {
|
||||||
profile_roles: [
|
profile_roles: [
|
||||||
@@ -45,18 +47,27 @@ const expectedColumns = {
|
|||||||
|
|
||||||
// Compile-time: a column present in the type but absent from the list is an error.
|
// Compile-time: a column present in the type but absent from the list is an error.
|
||||||
type MissingColumns = {
|
type MissingColumns = {
|
||||||
[T in keyof Tables]: Exclude<keyof Tables[T]['Row'], (typeof expectedColumns)[T][number]>
|
[T in keyof Tables]: Exclude<
|
||||||
|
keyof Tables[T]['Row'],
|
||||||
|
(typeof expectedColumns)[T][number]
|
||||||
|
>
|
||||||
}[keyof Tables]
|
}[keyof Tables]
|
||||||
const noMissingColumn: MissingColumns extends never ? true : never = true
|
const noMissingColumn: MissingColumns extends never ? true : never = true
|
||||||
|
|
||||||
type FunctionArgs = { readonly [F in keyof Functions]: readonly (keyof Functions[F]['Args'] & string)[] }
|
type FunctionArgs = {
|
||||||
|
readonly [F in keyof Functions]: readonly (keyof Functions[F]['Args'] &
|
||||||
|
string)[]
|
||||||
|
}
|
||||||
const expectedFunctionArgs = {
|
const expectedFunctionArgs = {
|
||||||
grant_platform_role: ['role', 'target_user_id'],
|
grant_platform_role: ['role', 'target_user_id'],
|
||||||
revoke_platform_role: ['reason', 'role', 'target_user_id'],
|
revoke_platform_role: ['reason', 'role', 'target_user_id'],
|
||||||
} as const satisfies FunctionArgs
|
} as const satisfies FunctionArgs
|
||||||
|
|
||||||
type MissingArgs = {
|
type MissingArgs = {
|
||||||
[F in keyof Functions]: Exclude<keyof Functions[F]['Args'], (typeof expectedFunctionArgs)[F][number]>
|
[F in keyof Functions]: Exclude<
|
||||||
|
keyof Functions[F]['Args'],
|
||||||
|
(typeof expectedFunctionArgs)[F][number]
|
||||||
|
>
|
||||||
}[keyof Functions]
|
}[keyof Functions]
|
||||||
const noMissingArg: MissingArgs extends never ? true : never = true
|
const noMissingArg: MissingArgs extends never ? true : never = true
|
||||||
|
|
||||||
@@ -100,9 +111,13 @@ describe('database.types.ts matches the migrated schema', () => {
|
|||||||
order by table_name, column_name`,
|
order by table_name, column_name`,
|
||||||
)
|
)
|
||||||
const actual: Record<string, string[]> = {}
|
const actual: Record<string, string[]> = {}
|
||||||
for (const row of rows) (actual[row.table_name] ??= []).push(row.column_name)
|
for (const row of rows)
|
||||||
|
(actual[row.table_name] ??= []).push(row.column_name)
|
||||||
const expected = Object.fromEntries(
|
const expected = Object.fromEntries(
|
||||||
Object.entries(expectedColumns).map(([table, cols]) => [table, [...cols].sort()]),
|
Object.entries(expectedColumns).map(([table, cols]) => [
|
||||||
|
table,
|
||||||
|
[...cols].sort(),
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
expect(actual).toEqual(expected)
|
expect(actual).toEqual(expected)
|
||||||
})
|
})
|
||||||
@@ -115,7 +130,9 @@ describe('database.types.ts matches the migrated schema', () => {
|
|||||||
where n.nspname = 'public' and t.typname = 'platform_role'
|
where n.nspname = 'public' and t.typname = 'platform_role'
|
||||||
order by e.enumsortorder`,
|
order by e.enumsortorder`,
|
||||||
)
|
)
|
||||||
expect(rows.map((r) => r.name)).toEqual([...Constants.public.Enums.platform_role])
|
expect(rows.map((r) => r.name)).toEqual([
|
||||||
|
...Constants.public.Enums.platform_role,
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('lists exactly the public functions and their argument names', async () => {
|
it('lists exactly the public functions and their argument names', async () => {
|
||||||
@@ -128,9 +145,14 @@ describe('database.types.ts matches the migrated schema', () => {
|
|||||||
)
|
)
|
||||||
order by p.proname`,
|
order by p.proname`,
|
||||||
)
|
)
|
||||||
const actual = Object.fromEntries(rows.map((r) => [r.name, [...r.args].sort()]))
|
const actual = Object.fromEntries(
|
||||||
|
rows.map((r) => [r.name, [...r.args].sort()]),
|
||||||
|
)
|
||||||
const expected = Object.fromEntries(
|
const expected = Object.fromEntries(
|
||||||
Object.entries(expectedFunctionArgs).map(([fn, args]) => [fn, [...args].sort()]),
|
Object.entries(expectedFunctionArgs).map(([fn, args]) => [
|
||||||
|
fn,
|
||||||
|
[...args].sort(),
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
expect(actual).toEqual(expected)
|
expect(actual).toEqual(expected)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user