import { Column } from 'react-data-grid' import { cn } from 'ui' import z from 'zod' import { QueueCreatedAtCell, QueueNameCell, QueueRLSCell, QueueSizeCell, QueueTypeCell, QueueWithMetrics, } from './QueueCells' import { PostgresQueue } from '@/data/database-queues/database-queues-query' export const formatQueueColumns = (): Column[] => { return [ { key: 'queue_name', name: 'Name', resizable: true, minWidth: 200, headerCellClass: undefined, renderHeaderCell: () => { return (

Name

) }, renderCell: (props) => { return }, }, { key: 'type', name: 'Type', resizable: true, minWidth: 120, headerCellClass: undefined, renderHeaderCell: () => { return (

Type

) }, renderCell: (props) => { return }, }, { key: 'rls_enabled', name: 'RLS enabled', resizable: true, minWidth: 120, headerCellClass: undefined, renderHeaderCell: () => { return (

RLS enabled

) }, renderCell: (props) => { return }, }, { key: 'created_at', name: 'Created at', resizable: true, minWidth: 180, headerCellClass: undefined, renderHeaderCell: () => { return (

Created at

) }, renderCell: (props) => { return }, }, { key: 'queue_size', name: 'Size', resizable: true, minWidth: 120, headerCellClass: undefined, renderHeaderCell: () => { return (

Size

) }, renderCell: (props) => { return }, }, ] } export const prepareQueuesForDataGrid = (queues: PostgresQueue[]): QueueWithMetrics[] => { return queues.map((queue) => ({ ...queue, id: queue.queue_name, // Use queue_name as unique id })) } // pgmq stores queue names as-provided in pgmq.meta and lowercases them only when // building the underlying q_/a_ relations, so uppercase queue names are fine — // the user-facing name is preserved and table-name lookups go through // pgmqQueueTable / pgmqArchiveTable which lowercase to match pgmq's behavior. export const QueueNameSchema = z .string() .trim() .min(1, 'Please provide a name for your queue') .max(47, "The name can't be longer than 47 characters") .regex( /^[a-zA-Z0-9_-]+$/, 'Name must contain only alphanumeric characters, underscores, and hyphens' ) export const isQueueNameValid = (queueName: string) => { return QueueNameSchema.safeParse(queueName).success } // pgmq.format_table_name() lowercases its input, so the actual relations in the // pgmq schema are always q_/a_ followed by the lowercased queue name — even when // pgmq.meta stores the original casing. Use these helpers anywhere a queue name // is mapped to a relname. export const pgmqQueueTable = (queueName: string) => `q_${queueName.toLowerCase()}` export const pgmqArchiveTable = (queueName: string) => `a_${queueName.toLowerCase()}`