import {z} from 'zod' export type DriverSchedulingConfig = {memoryMb?: number | undefined, vcores?: number | undefined}; export type LoggingConfig = {driverLogLevels?: ({[key: string]: 'LEVEL_UNSPECIFIED' | 'ALL' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL' | 'OFF'}) | undefined}; export type FlinkJob = {args?: Array | undefined, jarFileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, mainClass?: string | undefined, mainJarFileUri?: string | undefined, properties?: {[key: string]: string} | undefined, savepointUri?: string | undefined}; export type HadoopJob = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, jarFileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, mainClass?: string | undefined, mainJarFileUri?: string | undefined, properties?: {[key: string]: string} | undefined}; export type QueryList = {queries?: Array | undefined}; export type HiveJob = {continueOnFailure?: boolean | undefined, jarFileUris?: Array | undefined, properties?: {[key: string]: string} | undefined, queryFileUri?: string | undefined, queryList?: QueryList | undefined, scriptVariables?: {[key: string]: string} | undefined}; export type PigJob = {continueOnFailure?: boolean | undefined, jarFileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, properties?: {[key: string]: string} | undefined, queryFileUri?: string | undefined, queryList?: QueryList | undefined, scriptVariables?: {[key: string]: string} | undefined}; export type JobPlacement = {clusterLabels?: {[key: string]: string} | undefined, clusterName?: string | undefined, clusterUuid?: string | undefined}; export type PrestoJob = {clientTags?: Array | undefined, continueOnFailure?: boolean | undefined, loggingConfig?: LoggingConfig | undefined, outputFormat?: string | undefined, properties?: {[key: string]: string} | undefined, queryFileUri?: string | undefined, queryList?: QueryList | undefined}; export type PySparkJob = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, jarFileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, mainPythonFileUri?: string | undefined, properties?: {[key: string]: string} | undefined, pythonFileUris?: Array | undefined}; export type JobReference = {jobId?: string | undefined, projectId?: string | undefined}; export type JobScheduling = {maxFailuresPerHour?: number | undefined, maxFailuresTotal?: number | undefined}; export type SparkJob = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, jarFileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, mainClass?: string | undefined, mainJarFileUri?: string | undefined, properties?: {[key: string]: string} | undefined}; export type SparkRJob = {archiveUris?: Array | undefined, args?: Array | undefined, fileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, mainRFileUri?: string | undefined, properties?: {[key: string]: string} | undefined}; export type SparkSqlJob = {jarFileUris?: Array | undefined, loggingConfig?: LoggingConfig | undefined, properties?: {[key: string]: string} | undefined, queryFileUri?: string | undefined, queryList?: QueryList | undefined, scriptVariables?: {[key: string]: string} | undefined}; export type JobStatus = {details?: string | undefined, state?: ('STATE_UNSPECIFIED' | 'PENDING' | 'SETUP_DONE' | 'RUNNING' | 'CANCEL_PENDING' | 'CANCEL_STARTED' | 'CANCELLED' | 'DONE' | 'ERROR' | 'ATTEMPT_FAILURE') | undefined, stateStartTime?: unknown | undefined, substate?: ('UNSPECIFIED' | 'SUBMITTED' | 'QUEUED' | 'STALE_STATUS') | undefined}; export type TrinoJob = {clientTags?: Array | undefined, continueOnFailure?: boolean | undefined, loggingConfig?: LoggingConfig | undefined, outputFormat?: string | undefined, properties?: {[key: string]: string} | undefined, queryFileUri?: string | undefined, queryList?: QueryList | undefined}; export type YarnApplication = {memoryMbSeconds?: unknown | undefined, name?: string | undefined, progress?: number | undefined, state?: ('STATE_UNSPECIFIED' | 'NEW' | 'NEW_SAVING' | 'SUBMITTED' | 'ACCEPTED' | 'RUNNING' | 'FINISHED' | 'FAILED' | 'KILLED') | undefined, trackingUrl?: string | undefined, vcoreSeconds?: unknown | undefined}; export type Job = {done?: boolean | undefined, driverControlFilesUri?: string | undefined, driverOutputResourceUri?: string | undefined, driverSchedulingConfig?: DriverSchedulingConfig | undefined, flinkJob?: FlinkJob | undefined, hadoopJob?: HadoopJob | undefined, hiveJob?: HiveJob | undefined, jobUuid?: string | undefined, labels?: {[key: string]: string} | undefined, pigJob?: PigJob | undefined, placement?: JobPlacement | undefined, prestoJob?: PrestoJob | undefined, pysparkJob?: PySparkJob | undefined, reference?: JobReference | undefined, scheduling?: JobScheduling | undefined, sparkJob?: SparkJob | undefined, sparkRJob?: SparkRJob | undefined, sparkSqlJob?: SparkSqlJob | undefined, status?: JobStatus | undefined, statusHistory?: Array | undefined, trinoJob?: TrinoJob | undefined, yarnApplications?: Array | undefined}; export type SubmitJobRequest = {job?: Job | undefined, requestId?: string | undefined}; export type CreateApiV1ProjectsProjectIdRegionsRegionJobsSubmitAsOperationArgs = {projectId: string, region: string, body: SubmitJobRequest}; export type CreateApiV1ProjectsProjectIdRegionsRegionJobsSubmitAsOperationOptions = {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 }; /** * Submits job to a cluster. * * POST /v1/projects/{projectId}/regions/{region}/jobs:submitAsOperation * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectIdRegionsRegionJobsSubmitAsOperation = async (args: CreateApiV1ProjectsProjectIdRegionsRegionJobsSubmitAsOperationArgs, options?: CreateApiV1ProjectsProjectIdRegionsRegionJobsSubmitAsOperationOptions) => { 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 (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/regions/${encodeURIComponent(String(args.region))}/jobs:submitAsOperation${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()) };