import { z } from 'zod' import { introspectionResponseSchema, sqlConnectionBodySchema, sqlDeleteBodySchema, sqlInsertBodySchema, sqlQueryBodySchema, sqlRowsResponseSchema, sqlUpdateBodySchema, } from '@/lib/api/contracts/tools/databases/shared' import { type ContractBodyInput, type ContractJsonResponse, defineRouteContract, } from '@/lib/api/contracts/types' export const postgresqlQueryBodySchema = sqlQueryBodySchema export const postgresqlExecuteBodySchema = sqlQueryBodySchema export const postgresqlInsertBodySchema = sqlInsertBodySchema export const postgresqlUpdateBodySchema = sqlUpdateBodySchema export const postgresqlDeleteBodySchema = sqlDeleteBodySchema export const postgresqlIntrospectBodySchema = sqlConnectionBodySchema.extend({ schema: z.string().default('public'), }) export const postgresqlQueryContract = defineRouteContract({ method: 'POST', path: '/api/tools/postgresql/query', body: postgresqlQueryBodySchema, response: { mode: 'json', schema: sqlRowsResponseSchema }, }) export const postgresqlExecuteContract = defineRouteContract({ method: 'POST', path: '/api/tools/postgresql/execute', body: postgresqlExecuteBodySchema, response: { mode: 'json', schema: sqlRowsResponseSchema }, }) export const postgresqlInsertContract = defineRouteContract({ method: 'POST', path: '/api/tools/postgresql/insert', body: postgresqlInsertBodySchema, response: { mode: 'json', schema: sqlRowsResponseSchema }, }) export const postgresqlUpdateContract = defineRouteContract({ method: 'POST', path: '/api/tools/postgresql/update', body: postgresqlUpdateBodySchema, response: { mode: 'json', schema: sqlRowsResponseSchema }, }) export const postgresqlDeleteContract = defineRouteContract({ method: 'POST', path: '/api/tools/postgresql/delete', body: postgresqlDeleteBodySchema, response: { mode: 'json', schema: sqlRowsResponseSchema }, }) export const postgresqlIntrospectContract = defineRouteContract({ method: 'POST', path: '/api/tools/postgresql/introspect', body: postgresqlIntrospectBodySchema, response: { mode: 'json', schema: introspectionResponseSchema }, }) export type PostgreSQLQueryRequest = ContractBodyInput export type PostgreSQLQueryResponse = ContractJsonResponse export type PostgreSQLExecuteRequest = ContractBodyInput export type PostgreSQLExecuteResponse = ContractJsonResponse export type PostgreSQLInsertRequest = ContractBodyInput export type PostgreSQLInsertResponse = ContractJsonResponse export type PostgreSQLUpdateRequest = ContractBodyInput export type PostgreSQLUpdateResponse = ContractJsonResponse export type PostgreSQLDeleteRequest = ContractBodyInput export type PostgreSQLDeleteResponse = ContractJsonResponse export type PostgreSQLIntrospectRequest = ContractBodyInput export type PostgreSQLIntrospectResponse = ContractJsonResponse