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 JupyterConfig = {displayName?: string | undefined, kernel?: ('KERNEL_UNSPECIFIED' | 'PYTHON' | 'SCALA') | 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 SparkConnectConfig = Record; export type SessionStateHistory = {state?: ('STATE_UNSPECIFIED' | 'CREATING' | 'ACTIVE' | 'TERMINATING' | 'TERMINATED' | 'FAILED') | undefined, stateMessage?: string | undefined, stateStartTime?: unknown | undefined}; export type Session = {createTime?: unknown | undefined, creator?: string | undefined, environmentConfig?: EnvironmentConfig | undefined, jupyterSession?: JupyterConfig | undefined, labels?: {[key: string]: string} | undefined, name?: string | undefined, runtimeConfig?: RuntimeConfig | undefined, runtimeInfo?: RuntimeInfo | undefined, sessionTemplate?: string | undefined, sparkConnectSession?: SparkConnectConfig | undefined, state?: ('STATE_UNSPECIFIED' | 'CREATING' | 'ACTIVE' | 'TERMINATING' | 'TERMINATED' | 'FAILED') | undefined, stateHistory?: Array | undefined, stateMessage?: string | undefined, stateTime?: unknown | undefined, user?: string | undefined, uuid?: string | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionsArgs = {projectsId: string, locationsId: string, requestId?: string | undefined, sessionId?: string | undefined, body: Session}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionsOptions = {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 }; /** * Create an interactive session asynchronously. * * POST /v1/projects/{projectsId}/locations/{locationsId}/sessions * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdSessions = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionsArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionsOptions) => { 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.requestId != null) query.append("requestId", String(args.requestId)) if (args.sessionId != null) query.append("sessionId", String(args.sessionId)) 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))}/sessions${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()) };