import {z} from 'zod' export type GetApiManagementV1WarehouseWarehouseIdTableTableIdActionsArgs = {principalUser?: string | undefined, principalRole?: string | undefined, warehouse_id: string, table_id: string}; export type GetApiManagementV1WarehouseWarehouseIdTableTableIdActionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const lakekeeperTableActionKind = z.union([z.object({action: z.literal("drop")}), z.object({action: z.literal("write_data")}), z.object({action: z.literal("read_data")}), z.object({action: z.literal("get_metadata")}), z.object({action: z.literal("commit")}), z.object({action: z.literal("rename")}), z.object({action: z.literal("include_in_list")}), z.object({action: z.literal("undrop")}), z.object({action: z.literal("get_tasks")}), z.object({action: z.literal("control_tasks")}), z.object({action: z.literal("set_protection")})]); export const getLakekeeperTableActionsResponse = z.object({"allowed-actions": z.array(lakekeeperTableActionKind)}); 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 allowed actions for a table * * GET /management/v1/warehouse/{warehouse_id}/table/{table_id}/actions */ export const getApiManagementV1WarehouseWarehouseIdTableTableIdActions = async (args: GetApiManagementV1WarehouseWarehouseIdTableTableIdActionsArgs, options?: GetApiManagementV1WarehouseWarehouseIdTableTableIdActionsOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.principalUser != null) query.append("principalUser", String(args.principalUser)) if (args.principalRole != null) query.append("principalRole", String(args.principalRole)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/management/v1/warehouse/${encodeURIComponent(String(args.warehouse_id))}/table/${encodeURIComponent(String(args.table_id))}/actions${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(getLakekeeperTableActionsResponse, await res.json()) };