import {z} from 'zod' export type BootstrapCatalogParams = {aws_access_key_id?: string | undefined, aws_secret_access_key?: string | undefined, broadcast_addr?: string | undefined, catalog_path?: string | undefined, communal_storage?: string | undefined, control_addr?: string | undefined, db_name?: string | undefined, db_password?: string | undefined, generate_http_certs?: boolean | undefined, host?: string | undefined, ipv6?: boolean | undefined, large_cluster?: number | undefined, license_key?: string | undefined, networking_mode?: string | undefined, node_name?: string | undefined, num_shards?: number | undefined, parameters?: {[key: string]: string} | undefined, port_number?: number | undefined, spread_logging?: boolean | undefined, spread_logging_level?: number | undefined, spread_port?: string | undefined, storage_location?: string | undefined, superuser_name?: string | undefined}; export type CreateApiCatalogBootstrapArgs = {body: BootstrapCatalogParams}; export type CreateApiCatalogBootstrapOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiCatalogBootstrapResponse = z.record(z.string(), z.string()); 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 }; /** * Bootstrap catalog * * POST /catalog/bootstrap */ export const createApiCatalogBootstrap = async (args: CreateApiCatalogBootstrapArgs, options: CreateApiCatalogBootstrapOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/catalog/bootstrap${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiCatalogBootstrapResponse, await res.json()) };