import {z} from 'zod' export type OrganizationID = string; export type GetApiOrganizationsOrganizationIDProjectsProjectIDBranchesBranchIDPostgresConfigArgs = {organizationID: OrganizationID, projectID: string, branchID: string}; export type GetApiOrganizationsOrganizationIDProjectsProjectIDBranchesBranchIDPostgresConfigOptions = {baseUrl?: string | undefined, xata?: string | undefined, fetch?: typeof fetch | undefined}; export const postgresConfigParameter = z.object({name: z.string(), type: z.enum(["string", "int", "float", "bytes", "enum", "duration", "boolean"]), description: z.string(), section: z.string(), acceptableRange: z.object({minValue: z.string().optional(), maxValue: z.string().optional(), enumValues: z.array(z.string()).optional()}).optional(), defaultValue: z.string(), defaultValueSource: z.enum(["postgres", "instance_type"]), currentValue: z.string(), documentationLink: z.string(), recommendation: z.string(), restartRequired: z.boolean().optional()}); export const postgresConfigDetails = z.object({parameters: z.array(postgresConfigParameter)}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get PostgreSQL configuration details * * GET /organizations/{organizationID}/projects/{projectID}/branches/{branchID}/postgres-config */ export const getApiOrganizationsOrganizationIDProjectsProjectIDBranchesBranchIDPostgresConfig = async (args: GetApiOrganizationsOrganizationIDProjectsProjectIDBranchesBranchIDPostgresConfigArgs, options?: GetApiOrganizationsOrganizationIDProjectsProjectIDBranchesBranchIDPostgresConfigOptions) => { const {baseUrl = "https://api.xata.tech", fetch: fetchFn = fetch, xata} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (xata !== undefined) headers.set('authorization', `Bearer ${xata}`) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organizationID))}/projects/${encodeURIComponent(String(args.projectID))}/branches/${encodeURIComponent(String(args.branchID))}/postgres-config${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(postgresConfigDetails, await res.json()) };