The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import { z } from 'zod'
import { METHODS, REGIONS } from './UnifiedLogs.constants'
import {
ARRAY_DELIMITER,
LEVELS,
RANGE_DELIMITER,
} from '@/components/ui/DataTable/DataTable.constants'
export const columnSchema = z.object({
id: z.string(),
log_type: z.string(),
method: z.string().nullable(),
pathname: z.string().nullable(),
level: z.enum(LEVELS).nullable(),
status: z.union([z.string(), z.number()]).nullable(),
date: z.date(),
timestamp: z.union([z.string(), z.number()]),
event_message: z.string().optional(),
log_count: z.number().nullish(),
logs: z.array(z.any()).optional(), // array of function logs
auth_user: z.string().nullable().optional(),
metadata: z.record(z.string(), z.unknown()).nullable().optional(),
})
export type ColumnSchema = z.infer<typeof columnSchema>
export const columnFilterSchema = z.object({
level: z
.string()
.transform((val) => val.split(ARRAY_DELIMITER))
.pipe(z.enum(LEVELS).array())
.optional(),
method: z
.string()
.transform((val) => val.split(ARRAY_DELIMITER))
.pipe(z.enum(METHODS).array())
.optional(),
pathname: z.string().optional(),
status: z
.string()
.transform((val) => val.split(ARRAY_DELIMITER))
.pipe(z.string().array())
.optional(),
regions: z
.string()
.transform((val) => val.split(ARRAY_DELIMITER))
.pipe(z.enum(REGIONS).array())
.optional(),
date: z
.string()
.transform((val) => val.split(RANGE_DELIMITER).map(Number))
.pipe(z.coerce.date().array())
.optional(),
auth_user: z.string().optional(),
})
export type ColumnFilterSchema = z.infer<typeof columnFilterSchema>
export const facetMetadataSchema = z.object({
rows: z.array(z.object({ value: z.any(), total: z.number() })),
total: z.number(),
min: z.number().optional(),
max: z.number().optional(),
})
export type FacetMetadataSchema = z.infer<typeof facetMetadataSchema>
export type BaseChartSchema = { timestamp: number; [key: string]: number }
export const timelineChartSchema = z.object({
timestamp: z.number(), // UNIX
...LEVELS.reduce(
(acc, level) => ({
...acc,
[level]: z.number().default(0),
}),
{} as Record<(typeof LEVELS)[number], z.ZodNumber>
),
// REMINDER: make sure to have the `timestamp` field in the object
}) satisfies z.ZodType<BaseChartSchema>
export type TimelineChartSchema = z.infer<typeof timelineChartSchema>