import {z} from 'zod' export type UserOrRole = {user: string} | {role: string}; export type LakekeeperServerAction = {action: 'create_project', name?: (string | null) | undefined, project_id?: (string | null) | undefined} | {action: 'update_users'} | {action: 'delete_users'} | {action: 'list_users'} | {action: 'provision_users'}; export type LakekeeperProjectAction = {action: 'create_warehouse', name?: (string | null) | undefined} | {action: 'delete'} | {action: 'rename'} | {action: 'get_metadata'} | {action: 'list_warehouses'} | {action: 'include_in_list'} | {action: 'create_role', name?: (string | null) | undefined} | {action: 'list_roles'} | {action: 'search_roles'} | {action: 'get_endpoint_statistics'} | {action: 'modify_task_queue_config'} | {action: 'get_task_queue_config'} | {action: 'get_project_tasks'} | {action: 'control_project_tasks'}; export type LakekeeperWarehouseAction = {action: 'create_namespace', name?: (string | null) | undefined, properties?: {[key: string]: string} | undefined} | {action: 'delete'} | {action: 'update_storage'} | {action: 'update_storage_credential'} | {action: 'get_metadata'} | {action: 'get_config'} | {action: 'list_namespaces'} | {action: 'list_everything'} | {action: 'use'} | {action: 'include_in_list'} | {action: 'deactivate'} | {action: 'activate'} | {action: 'rename'} | {action: 'list_deleted_tabulars'} | {action: 'modify_soft_deletion'} | {action: 'get_task_queue_config'} | {action: 'modify_task_queue_config'} | {action: 'get_all_tasks'} | {action: 'control_all_tasks'} | {action: 'set_protection'} | {action: 'set_format_version_policy'} | {action: 'get_endpoint_statistics'}; export type LakekeeperNamespaceAction = {action: 'create_table', name?: (string | null) | undefined, properties?: {[key: string]: string} | undefined, table_id?: (string | null) | undefined} | {action: 'create_view', name?: (string | null) | undefined, properties?: {[key: string]: string} | undefined} | {action: 'create_namespace', name?: (string | null) | undefined, properties?: {[key: string]: string} | undefined} | {action: 'delete', force?: boolean | undefined, purge?: boolean | undefined, recursive?: boolean | undefined} | {action: 'update_properties', removed_properties?: Array | undefined, updated_properties?: {[key: string]: string} | undefined} | {action: 'get_metadata'} | {action: 'list_tables'} | {action: 'list_views'} | {action: 'list_namespaces'} | {action: 'list_everything'} | {action: 'set_protection'} | {action: 'include_in_list'} | {action: 'create_generic_table', base_location?: (string | null) | undefined, format?: (string | null) | undefined, generic_table_id?: (string | null) | undefined, name?: (string | null) | undefined, properties?: {[key: string]: string} | undefined} | {action: 'list_generic_tables'}; export type LakekeeperTableAction = {action: 'drop', force?: boolean | undefined, purge?: boolean | undefined} | {action: 'write_data'} | {action: 'read_data'} | {action: 'get_metadata'} | {action: 'commit', removed_properties?: Array | undefined, updated_properties?: {[key: string]: string} | undefined} | {action: 'rename'} | {action: 'include_in_list'} | {action: 'undrop'} | {action: 'get_tasks'} | {action: 'control_tasks'} | {action: 'set_protection'}; export type LakekeeperViewAction = {action: 'drop', force?: boolean | undefined, purge?: boolean | undefined} | {action: 'get_metadata'} | {action: 'select'} | {action: 'commit', removed_properties?: Array | undefined, updated_properties?: {[key: string]: string} | undefined} | {action: 'include_in_list'} | {action: 'rename'} | {action: 'undrop'} | {action: 'get_tasks'} | {action: 'control_tasks'} | {action: 'set_protection'}; export type LakekeeperGenericTableAction = {action: 'drop'} | {action: 'read_data'} | {action: 'write_data'} | {action: 'get_metadata'} | {action: 'rename'} | {action: 'include_in_list'} | {action: 'undrop'} | {action: 'get_tasks'} | {action: 'control_tasks'} | {action: 'set_protection'}; export type CatalogActionCheckOperation = {server: {action: LakekeeperServerAction}} | {project: {action: LakekeeperProjectAction, 'project-id'?: (string | null) | undefined}} | {warehouse: {action: LakekeeperWarehouseAction, 'warehouse-id': string}} | {namespace: {'namespace-id': string, 'warehouse-id': string, action: LakekeeperNamespaceAction} | {namespace: Array, 'warehouse-id': string, action: LakekeeperNamespaceAction}} | {table: {'table-id': string, 'warehouse-id': string, action: LakekeeperTableAction} | {namespace: Array, table: string, 'warehouse-id': string, action: LakekeeperTableAction}} | {view: {'table-id': string, 'warehouse-id': string, action: LakekeeperViewAction} | {namespace: Array, table: string, 'warehouse-id': string, action: LakekeeperViewAction}} | {'generic-table': {'table-id': string, 'warehouse-id': string, action: LakekeeperGenericTableAction} | {namespace: Array, table: string, 'warehouse-id': string, action: LakekeeperGenericTableAction}}; export type CatalogActionCheckItem = {id?: (string | null) | undefined, identity?: (UserOrRole | null) | undefined, operation: CatalogActionCheckOperation}; export type CatalogActionsBatchCheckRequest = {checks: Array, 'error-on-not-found'?: boolean | undefined}; export type CreateApiManagementV1ActionBatchCheckArgs = {body: CatalogActionsBatchCheckRequest}; export type CreateApiManagementV1ActionBatchCheckOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const catalogActionsBatchCheckResult = z.object({allowed: z.boolean(), id: z.string().nullable().optional()}); export const catalogActionsBatchCheckResponse = z.object({results: z.array(catalogActionsBatchCheckResult)}); 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 }; /** * Batch Check Catalog Actions * * POST /management/v1/action/batch-check */ export const createApiManagementV1ActionBatchCheck = async (args: CreateApiManagementV1ActionBatchCheckArgs, options?: CreateApiManagementV1ActionBatchCheckOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/management/v1/action/batch-check${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(catalogActionsBatchCheckResponse, await res.json()) };