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 SparkConnectConfig = Record; export type SessionTemplate = {createTime?: unknown | undefined, creator?: string | undefined, description?: string | undefined, displayName?: string | undefined, environmentConfig?: EnvironmentConfig | undefined, jupyterSession?: JupyterConfig | undefined, labels?: {[key: string]: string} | undefined, name?: string | undefined, runtimeConfig?: RuntimeConfig | undefined, sparkConnectSession?: SparkConnectConfig | undefined, updateTime?: unknown | undefined, uuid?: string | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionTemplatesArgs = {projectsId: string, locationsId: string, body: SessionTemplate}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionTemplatesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const authenticationConfig = z.object({userWorkloadAuthenticationType: z.enum(["AUTHENTICATION_TYPE_UNSPECIFIED", "SERVICE_ACCOUNT", "END_USER_CREDENTIALS"]).optional()}); export const executionConfig = z.object({authenticationConfig: authenticationConfig.optional(), idleTtl: z.string().optional(), kmsKey: z.string().optional(), networkTags: z.array(z.string()).optional(), networkUri: z.string().optional(), resourceManagerTags: z.record(z.string(), z.string()).optional(), serviceAccount: z.string().optional(), stagingBucket: z.string().optional(), subnetworkUri: z.string().optional(), ttl: z.string().optional()}); export const sparkHistoryServerConfig = z.object({dataprocCluster: z.string().optional()}); export const peripheralsConfig = z.object({metastoreService: z.string().optional(), sparkHistoryServerConfig: sparkHistoryServerConfig.optional()}); export const environmentConfig = z.object({executionConfig: executionConfig.optional(), peripheralsConfig: peripheralsConfig.optional()}); export const jupyterConfig = z.object({displayName: z.string().optional(), kernel: z.enum(["KERNEL_UNSPECIFIED", "PYTHON", "SCALA"]).optional()}); export const autotuningConfig = z.object({scenarios: z.array(z.enum(["SCENARIO_UNSPECIFIED", "SCALING", "BROADCAST_HASH_JOIN", "MEMORY", "NONE", "AUTO"])).optional()}); export const pyPiRepositoryConfig = z.object({pypiRepository: z.string().optional()}); export const repositoryConfig = z.object({pypiRepositoryConfig: pyPiRepositoryConfig.optional()}); export const runtimeConfig = z.object({autotuningConfig: autotuningConfig.optional(), cohort: z.string().optional(), containerImage: z.string().optional(), properties: z.record(z.string(), z.string()).optional(), repositoryConfig: repositoryConfig.optional(), version: z.string().optional()}); export const sparkConnectConfig = z.object({}); export const sessionTemplate = z.object({createTime: z.string().optional(), creator: z.string().optional(), description: z.string().optional(), displayName: z.string().optional(), environmentConfig: environmentConfig.optional(), jupyterSession: jupyterConfig.optional(), labels: z.record(z.string(), z.string()).optional(), name: z.string().optional(), runtimeConfig: runtimeConfig.optional(), sparkConnectSession: sparkConnectConfig.optional(), updateTime: z.string().optional(), uuid: z.string().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 a session template synchronously. * * POST /v1/projects/{projectsId}/locations/{locationsId}/sessionTemplates * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdSessionTemplates = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionTemplatesArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdSessionTemplatesOptions) => { 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.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/sessionTemplates${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(sessionTemplate, await res.json()) };