mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 08:56:46 -04:00
0433eeb5f5
Mark provenance of SQL via the branded types SafeSqlFragment and UntrustedSqlFragment. Only SafeSqlFragment should be executed; UntrustedSqlFragments require some kind of implicit user approval (show on screen + user has to click something) before they are promoted to SafeSqlFragment. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Editor and RLS tester show loading states for inferred/generated SQL and include a dedicated user SQL editor for safer edits. * **Refactor** * Platform-wide SQL handling tightened: snippets and AI-generated SQL are treated as untrusted/display-only until promoted, improving safety and consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
21 lines
641 B
TypeScript
21 lines
641 B
TypeScript
import { type SafeSqlFragment } from '@supabase/pg-meta'
|
|
import { format } from 'sql-formatter'
|
|
|
|
/**
|
|
* Util function for formatting SQL. It wraps the `sql-formatter` library with a preset format options so that the
|
|
* formatting is consistent across the app. It also has a try/catch block which returns the original SQL in case of
|
|
* an error.
|
|
*/
|
|
export function formatSql(sql: SafeSqlFragment): SafeSqlFragment
|
|
export function formatSql(sql: string): string
|
|
export function formatSql(sql: string): string {
|
|
try {
|
|
return format(sql, {
|
|
language: 'postgresql',
|
|
keywordCase: 'lower',
|
|
})
|
|
} catch {
|
|
return sql
|
|
}
|
|
}
|