import {z} from 'zod' export type AuthenticationConfig = {userWorkloadAuthenticationType?: ('AUTHENTICATION_TYPE_UNSPECIFIED' | 'SERVICE_ACCOUNT' | 'END_USER_CREDENTIALS') | undefined}; export type ExecutionConfig = {authenticationConfig?: AuthenticationConfig | undefined, idleTtl?: unknown | undefined, kmsKey?: string | undefined, networkTags?: Array | undefined, networkUri?: string | undefined, resourceManagerTags?: {[key: string]: string} | undefined, serviceAccount?: string | undefined, stagingBucket?: string | undefined, subnetworkUri?: string | undefined, ttl?: unknown | undefined}; export type SparkHistoryServerConfig = {dataprocCluster?: string | undefined}; export type PeripheralsConfig = {metastoreService?: string | undefined, sparkHistoryServerConfig?: SparkHistoryServerConfig | undefined}; export type EnvironmentConfig = {executionConfig?: ExecutionConfig | undefined, peripheralsConfig?: PeripheralsConfig | undefined}; export type PySparkBatch = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, jarFileUris?: Array | undefined, mainPythonFileUri?: string | undefined, pythonFileUris?: Array | undefined}; export type PySparkNotebookBatch = {archiveUris?: Array | undefined, fileUris?: Array | undefined, jarFileUris?: Array | undefined, notebookFileUri?: string | undefined, params?: {[key: string]: string} | undefined, pythonFileUris?: Array | undefined}; export type AutotuningConfig = {scenarios?: (Array<'SCENARIO_UNSPECIFIED' | 'SCALING' | 'BROADCAST_HASH_JOIN' | 'MEMORY' | 'NONE' | 'AUTO'>) | undefined}; export type PyPiRepositoryConfig = {pypiRepository?: string | undefined}; export type RepositoryConfig = {pypiRepositoryConfig?: PyPiRepositoryConfig | undefined}; export type RuntimeConfig = {autotuningConfig?: AutotuningConfig | undefined, cohort?: string | undefined, containerImage?: string | undefined, properties?: {[key: string]: string} | undefined, repositoryConfig?: RepositoryConfig | undefined, version?: string | undefined}; export type UsageMetrics = {acceleratorType?: string | undefined, milliAcceleratorSeconds?: unknown | undefined, milliAcceleratorSecondsA10040?: unknown | undefined, milliAcceleratorSecondsA10080?: unknown | undefined, milliAcceleratorSecondsL4?: unknown | undefined, milliDcuSeconds?: unknown | undefined, shuffleStorageGbSeconds?: unknown | undefined, updateTime?: unknown | undefined}; export type CohortInfo = {cohort?: string | undefined, cohortSource?: ('COHORT_SOURCE_UNSPECIFIED' | 'USER_PROVIDED' | 'AIRFLOW') | undefined}; export type UsageSnapshot = {acceleratorType?: string | undefined, milliAccelerator?: unknown | undefined, milliAcceleratorA10040?: unknown | undefined, milliAcceleratorA10080?: unknown | undefined, milliAcceleratorL4?: unknown | undefined, milliDcu?: unknown | undefined, milliDcuPremium?: unknown | undefined, shuffleStorageGb?: unknown | undefined, shuffleStorageGbPremium?: unknown | undefined, snapshotTime?: unknown | undefined}; export type ValueInfo = {annotation?: string | undefined, overriddenValue?: string | undefined, value?: string | undefined}; export type PropertiesInfo = {autotuningProperties?: {[key: string]: ValueInfo} | undefined}; export type RuntimeInfo = {approximateUsage?: UsageMetrics | undefined, cohortInfo?: CohortInfo | undefined, currentUsage?: UsageSnapshot | undefined, diagnosticOutputUri?: string | undefined, endpoints?: {[key: string]: string} | undefined, outputUri?: string | undefined, propertiesInfo?: PropertiesInfo | undefined}; export type SparkBatch = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, jarFileUris?: Array | undefined, mainClass?: string | undefined, mainJarFileUri?: string | undefined}; export type SparkRBatch = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, mainRFileUri?: string | undefined}; export type SparkSqlBatch = {jarFileUris?: Array | undefined, queryFileUri?: string | undefined, queryVariables?: {[key: string]: string} | undefined}; export type StateHistory = {state?: ('STATE_UNSPECIFIED' | 'PENDING' | 'RUNNING' | 'CANCELLING' | 'CANCELLED' | 'SUCCEEDED' | 'FAILED') | undefined, stateMessage?: string | undefined, stateStartTime?: unknown | undefined}; export type Batch = {createTime?: unknown | undefined, creator?: string | undefined, environmentConfig?: EnvironmentConfig | undefined, labels?: {[key: string]: string} | undefined, name?: string | undefined, operation?: string | undefined, pysparkBatch?: PySparkBatch | undefined, pysparkNotebookBatch?: PySparkNotebookBatch | undefined, runtimeConfig?: RuntimeConfig | undefined, runtimeInfo?: RuntimeInfo | undefined, sparkBatch?: SparkBatch | undefined, sparkRBatch?: SparkRBatch | undefined, sparkSqlBatch?: SparkSqlBatch | undefined, state?: ('STATE_UNSPECIFIED' | 'PENDING' | 'RUNNING' | 'CANCELLING' | 'CANCELLED' | 'SUCCEEDED' | 'FAILED') | undefined, stateHistory?: Array | undefined, stateMessage?: string | undefined, stateTime?: unknown | undefined, uuid?: string | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdBatchesArgs = {projectsId: string, locationsId: string, batchId?: string | undefined, requestId?: string | undefined, body: Batch}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdBatchesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const status = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const operation = z.object({done: z.boolean().optional(), error: status.optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string().optional(), response: z.record(z.string(), z.unknown()).optional()}); 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 }; /** * Creates a batch workload that executes asynchronously. * * POST /v1/projects/{projectsId}/locations/{locationsId}/batches * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdBatches = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdBatchesArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdBatchesOptions) => { const {baseUrl = "https://dataproc.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.batchId != null) query.append("batchId", String(args.batchId)) if (args.requestId != null) query.append("requestId", String(args.requestId)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/batches${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(operation, await res.json()) };