import {z} from 'zod' export type GetApiApiV1ProjectsProjectUuidExploresArgs = {projectUuid: string}; export type GetApiApiV1ProjectsProjectUuidExploresOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const exploreType = z.enum(["virtual", "default", "pre_aggregate"]); export const preAggregateSource = z.object({preAggregateName: z.string(), sourceExploreName: z.string()}); export const inlineErrorType = z.enum(["METADATA_PARSE_ERROR", "NO_DIMENSIONS_FOUND", "SKIPPED_JOIN", "MISSING_TABLE", "FIELD_ERROR", "SET_VALIDATION_ERROR", "INVALID_PARAMETER", "DUPLICATE_FIELD_NAME", "WAREHOUSE_COLUMN_ERROR"]); export const inlineError = z.object({message: z.string(), type: inlineErrorType}); export const summaryExplore = z.union([z.object({name: z.string(), label: z.string(), type: exploreType.optional(), tags: z.array(z.string()), groupLabel: z.string().optional(), groups: z.array(z.string()).optional(), aiHint: z.union([z.string(), z.array(z.string())]).optional(), preAggregateSource: preAggregateSource.optional(), warnings: z.array(inlineError).optional(), databaseName: z.string(), schemaName: z.string(), description: z.string().optional()}), z.object({name: z.string(), label: z.string(), type: exploreType.optional(), tags: z.array(z.string()).optional(), groupLabel: z.string().optional(), groups: z.array(z.string()).optional(), aiHint: z.union([z.string(), z.array(z.string())]).optional(), errors: z.array(inlineError), description: z.string().optional(), schemaName: z.string().optional(), databaseName: z.string().optional()})]); export const apiExploresResults = z.array(summaryExplore); export const getApiApiV1ProjectsProjectUuidExploresResponse = z.object({results: apiExploresResults, status: z.literal("ok")}); 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 }; /** * List explores * * GET /api/v1/projects/{projectUuid}/explores */ export const getApiApiV1ProjectsProjectUuidExplores = async (args: GetApiApiV1ProjectsProjectUuidExploresArgs, options: GetApiApiV1ProjectsProjectUuidExploresOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectUuid))}/explores${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(getApiApiV1ProjectsProjectUuidExploresResponse, await res.json()) };