import {z} from 'zod' export type AWSIAMRole = {aws_iam_role_arn: string}; export type UpdateAWSAccessKeys = {access_id?: string | undefined, secret_key?: string | undefined}; export type UpdateS3DatalakeOptions = {prefix?: string | undefined, auth_method?: ('aws_iam_role' | 'aws_access_keys') | undefined, aws_iam_role?: AWSIAMRole | undefined, aws_access_keys?: UpdateAWSAccessKeys | undefined}; export type UpdateS3CompatibleDatalakeOptions = {prefix?: string | undefined, bucket_host?: string | undefined, bucket_port?: number | undefined, aws_access_keys?: UpdateAWSAccessKeys | undefined}; export type UpdateGCPDatalakeServiceAccountRole = {gcp_service_account_email?: string | undefined}; export type UpdateGCPDatalakeServiceAccountKey = {service_account_email?: string | undefined, service_account_key: unknown}; export type UpdateGCSDatalakeOptions = {prefix?: string | undefined, auth_method?: ('gcp_service_account_role' | 'gcp_service_account_key' | 'federated_gcp_service_account_role') | undefined, gcp_service_account_role?: UpdateGCPDatalakeServiceAccountRole | undefined, gcp_service_account_key?: UpdateGCPDatalakeServiceAccountKey | undefined, federated_gcp_service_account_role?: UpdateGCPDatalakeServiceAccountRole | undefined}; export type UpdateAzureStorageAccountAccessKey = {storage_account_access_key?: string | undefined}; export type UpdateABSDatalakeOptions = {prefix?: string | undefined, container_name?: string | undefined, storage_account_name?: string | undefined, auth_method?: 'azure_storage_account_access_key' | undefined, azure_storage_account_access_key?: UpdateAzureStorageAccountAccessKey | undefined}; export type DatalakeUpdateOptions = {name?: string | undefined, retention_window_days?: number | undefined, s3?: UpdateS3DatalakeOptions | undefined, s3_compatible?: UpdateS3CompatibleDatalakeOptions | undefined, gcs?: UpdateGCSDatalakeOptions | undefined, abs?: UpdateABSDatalakeOptions | undefined}; export type UpdateDatalakeRequest = {datalake: DatalakeUpdateOptions}; export type PatchApiImportDatalakesIdArgs = {id: string, body: UpdateDatalakeRequest}; export type PatchApiImportDatalakesIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const aWSIAMRoleResource = z.object({aws_iam_role: z.string()}); export const s3DatalakeResourceAWSIAMRole = z.object({prefix: z.string(), bucket_name: z.string(), bucket_region: z.string(), auth_method: z.literal("aws_iam_role"), aws_iam_role: aWSIAMRoleResource}); export const aWSAccessKeysResource = z.object({access_key_id: z.string()}); export const s3DatalakeResourceAWSAccessKeys = z.object({prefix: z.string(), bucket_name: z.string(), bucket_region: z.string(), auth_method: z.literal("aws_access_keys"), aws_access_keys: aWSAccessKeysResource}); export const s3DatalakeResource = z.discriminatedUnion("auth_method", [s3DatalakeResourceAWSIAMRole, s3DatalakeResourceAWSAccessKeys]); export const s3CompatibleDatalakeResource = z.object({prefix: z.string(), bucket_name: z.string(), bucket_region: z.string(), bucket_host: z.string(), bucket_port: z.number().int(), aws_access_keys: aWSAccessKeysResource}); export const gCPDatalakeServiceAccountRoleResource = z.object({gcp_service_account_email: z.string()}); export const gCSDatalakeResourceGCPServiceAccountRole = z.object({prefix: z.string(), bucket_name: z.string(), bucket_region: z.string(), auth_method: z.literal("gcp_service_account_role"), gcp_service_account_role: gCPDatalakeServiceAccountRoleResource}); export const gCPDatalakeServiceAccountKeyResource = z.object({service_account_email: z.string()}); export const gCSDatalakeResourceGCPServiceAccountKey = z.object({prefix: z.string(), bucket_name: z.string(), bucket_region: z.string(), auth_method: z.literal("gcp_service_account_key"), gcp_service_account_key: gCPDatalakeServiceAccountKeyResource}); export const federatedGCPDatalakeServiceAccountRoleResource = z.object({gcp_service_account_email: z.string()}); export const gCSDatalakeResourceFederatedGCPServiceAccountRole = z.object({prefix: z.string(), bucket_name: z.string(), bucket_region: z.string(), auth_method: z.literal("federated_gcp_service_account_role"), federated_gcp_service_account_role: federatedGCPDatalakeServiceAccountRoleResource}); export const gCSDatalakeResource = z.discriminatedUnion("auth_method", [gCSDatalakeResourceGCPServiceAccountRole, gCSDatalakeResourceGCPServiceAccountKey, gCSDatalakeResourceFederatedGCPServiceAccountRole]); export const azureStorageAccountAccessKeyResource = z.object({}); export const aBSDatalakeResource = z.object({prefix: z.string(), container_name: z.string(), storage_account_name: z.string(), auth_method: z.string(), azure_storage_account_access_key: azureStorageAccountAccessKeyResource.optional()}); export const datalakeResource = z.union([z.object({storage: z.literal("s3"), s3: s3DatalakeResource, id: z.string(), name: z.string(), retention_window_days: z.number().int().optional(), created_at: z.string(), updated_at: z.string()}), z.object({storage: z.literal("s3_compatible"), s3_compatible: s3CompatibleDatalakeResource, id: z.string(), name: z.string(), retention_window_days: z.number().int().optional(), created_at: z.string(), updated_at: z.string()}), z.object({storage: z.literal("gcs"), gcs: gCSDatalakeResource, id: z.string(), name: z.string(), retention_window_days: z.number().int().optional(), created_at: z.string(), updated_at: z.string()}), z.object({storage: z.literal("abs"), abs: aBSDatalakeResource, id: z.string(), name: z.string(), retention_window_days: z.number().int().optional(), created_at: z.string(), updated_at: z.string()})]); export const getDatalakeResponse = z.object({datalake: datalakeResource}); export const patchApiImportDatalakesIdResponse = z.object({status: z.literal("success"), data: getDatalakeResponse, message: 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 }; /** * Update datalake * * PATCH /import/datalakes/{id} */ export const patchApiImportDatalakesId = async (args: PatchApiImportDatalakesIdArgs, options?: PatchApiImportDatalakesIdOptions) => { const {baseUrl = "https://api.prequel.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/import/datalakes/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiImportDatalakesIdResponse, await res.json()) };