useTestQueryRLS.utils.ts24 lines · main
1import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
2import type { ParseSQLQueryResponse } from '@/data/misc/parse-query-mutation'
3
4export function filterTablePolicies({
5 policies,
6 schema,
7 table,
8 role,
9 operation,
10}: {
11 policies: Policy[]
12 schema: string
13 table: string
14 role: string | undefined
15 operation: ParseSQLQueryResponse['operation']
16}): Policy[] {
17 return policies.filter(
18 (x) =>
19 x.schema === schema &&
20 x.table === table &&
21 (x.roles.includes(role ?? '') || (x.roles.length === 1 && x.roles[0] === 'public')) &&
22 (x.command === 'ALL' || x.command === operation)
23 )
24}