import {z} from 'zod' export type AcceleratorConfig = {acceleratorCount?: number | undefined, acceleratorTypeUri?: string | undefined}; export type AttachedDiskConfig = {diskSizeGb?: number | undefined, diskType?: ('DISK_TYPE_UNSPECIFIED' | 'HYPERDISK_BALANCED' | 'HYPERDISK_EXTREME' | 'HYPERDISK_ML' | 'HYPERDISK_THROUGHPUT') | undefined, provisionedIops?: unknown | undefined, provisionedThroughput?: unknown | undefined, type?: string | undefined}; export type DiskConfig = {attachedDiskConfigs?: Array | undefined, bootDiskProvisionedIops?: unknown | undefined, bootDiskProvisionedThroughput?: unknown | undefined, bootDiskSizeGb?: number | undefined, bootDiskType?: string | undefined, localSsdInterface?: string | undefined, numLocalSsds?: number | undefined}; export type InstanceSelection = {diskConfig?: DiskConfig | undefined, machineTypes?: Array | undefined, rank?: number | undefined}; export type InstanceSelectionResult = {machineType?: string | undefined, vmCount?: number | undefined}; export type ProvisioningModelMix = {standardCapacityBase?: number | undefined, standardCapacityPercentAboveBase?: number | undefined}; export type InstanceFlexibilityPolicy = {instanceMachineTypes?: {[key: string]: string} | undefined, instanceSelectionList?: Array | undefined, instanceSelectionResults?: Array | undefined, provisioningModelMix?: ProvisioningModelMix | undefined}; export type InstanceReference = {instanceId?: string | undefined, instanceName?: string | undefined, publicEciesKey?: string | undefined, publicKey?: string | undefined}; export type ManagedGroupConfig = {instanceGroupManagerName?: string | undefined, instanceGroupManagerUri?: string | undefined, instanceTemplateName?: string | undefined}; export type StartupConfig = {requiredRegistrationFraction?: number | undefined}; export type InstanceGroupConfig = {accelerators?: Array | undefined, diskConfig?: DiskConfig | undefined, imageUri?: string | undefined, instanceFlexibilityPolicy?: InstanceFlexibilityPolicy | undefined, instanceNames?: Array | undefined, instanceReferences?: Array | undefined, isPreemptible?: boolean | undefined, machineTypeUri?: string | undefined, managedGroupConfig?: ManagedGroupConfig | undefined, minCpuPlatform?: string | undefined, minNumInstances?: number | undefined, numInstances?: number | undefined, preemptibility?: ('PREEMPTIBILITY_UNSPECIFIED' | 'NON_PREEMPTIBLE' | 'PREEMPTIBLE' | 'SPOT') | undefined, startupConfig?: StartupConfig | undefined}; export type NodeGroup = {labels?: {[key: string]: string} | undefined, name?: string | undefined, nodeGroupConfig?: InstanceGroupConfig | undefined, roles?: (Array<'ROLE_UNSPECIFIED' | 'DRIVER'>) | undefined}; export type CreateApiV1ProjectsProjectsIdRegionsRegionsIdClustersClustersIdNodeGroupsArgs = {projectsId: string, regionsId: string, clustersId: string, nodeGroupId?: string | undefined, parentOperationId?: string | undefined, requestId?: string | undefined, body: NodeGroup}; export type CreateApiV1ProjectsProjectsIdRegionsRegionsIdClustersClustersIdNodeGroupsOptions = {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 node group in a cluster. The returned Operation.metadata is NodeGroupOperationMetadata (https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#nodegroupoperationmetadata). * * POST /v1/projects/{projectsId}/regions/{regionsId}/clusters/{clustersId}/nodeGroups * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdRegionsRegionsIdClustersClustersIdNodeGroups = async (args: CreateApiV1ProjectsProjectsIdRegionsRegionsIdClustersClustersIdNodeGroupsArgs, options?: CreateApiV1ProjectsProjectsIdRegionsRegionsIdClustersClustersIdNodeGroupsOptions) => { 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.nodeGroupId != null) query.append("nodeGroupId", String(args.nodeGroupId)) if (args.parentOperationId != null) query.append("parentOperationId", String(args.parentOperationId)) 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))}/regions/${encodeURIComponent(String(args.regionsId))}/clusters/${encodeURIComponent(String(args.clustersId))}/nodeGroups${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()) };