import {z} from 'zod' export type BoundedTrieNode = {children?: {[key: string]: BoundedTrieNode} | undefined, truncated?: boolean | undefined}; export type BoundedTrie = {bound?: number | undefined, root?: BoundedTrieNode | undefined, singleton?: Array | undefined}; export type SplitInt64 = {highBits?: number | undefined, lowBits?: number | undefined}; export type Histogram = {bucketCounts?: Array | undefined, firstBucketOffset?: number | undefined}; export type DistributionUpdate = {count?: SplitInt64 | undefined, histogram?: Histogram | undefined, max?: SplitInt64 | undefined, min?: SplitInt64 | undefined, sum?: SplitInt64 | undefined, sumOfSquares?: number | undefined}; export type FloatingPointList = {elements?: Array | undefined}; export type FloatingPointMean = {count?: SplitInt64 | undefined, sum?: number | undefined}; export type IntegerGauge = {timestamp?: unknown | undefined, value?: SplitInt64 | undefined}; export type IntegerList = {elements?: Array | undefined}; export type IntegerMean = {count?: SplitInt64 | undefined, sum?: SplitInt64 | undefined}; export type NameAndKind = {kind?: ('INVALID' | 'SUM' | 'MAX' | 'MIN' | 'MEAN' | 'OR' | 'AND' | 'SET' | 'DISTRIBUTION' | 'LATEST_VALUE') | undefined, name?: string | undefined}; export type StringList = {elements?: Array | undefined}; export type CounterMetadata = {description?: string | undefined, kind?: ('INVALID' | 'SUM' | 'MAX' | 'MIN' | 'MEAN' | 'OR' | 'AND' | 'SET' | 'DISTRIBUTION' | 'LATEST_VALUE') | undefined, otherUnits?: string | undefined, standardUnits?: ('BYTES' | 'BYTES_PER_SEC' | 'MILLISECONDS' | 'MICROSECONDS' | 'NANOSECONDS' | 'TIMESTAMP_MSEC' | 'TIMESTAMP_USEC' | 'TIMESTAMP_NSEC') | undefined}; export type CounterStructuredName = {componentStepName?: string | undefined, executionStepName?: string | undefined, inputIndex?: number | undefined, name?: string | undefined, origin?: ('SYSTEM' | 'USER') | undefined, originNamespace?: string | undefined, originalRequestingStepName?: string | undefined, originalStepName?: string | undefined, portion?: ('ALL' | 'KEY' | 'VALUE') | undefined, workerId?: string | undefined}; export type CounterStructuredNameAndMetadata = {metadata?: CounterMetadata | undefined, name?: CounterStructuredName | undefined}; export type CounterUpdate = {boolean?: boolean | undefined, boundedTrie?: BoundedTrie | undefined, cumulative?: boolean | undefined, distribution?: DistributionUpdate | undefined, floatingPoint?: number | undefined, floatingPointList?: FloatingPointList | undefined, floatingPointMean?: FloatingPointMean | undefined, integer?: SplitInt64 | undefined, integerGauge?: IntegerGauge | undefined, integerList?: IntegerList | undefined, integerMean?: IntegerMean | undefined, internal: unknown, nameAndKind?: NameAndKind | undefined, shortId?: unknown | undefined, stringList?: StringList | undefined, structuredNameAndMetadata?: CounterStructuredNameAndMetadata | undefined}; export type SourceMetadata = {estimatedSizeBytes?: unknown | undefined, infinite?: boolean | undefined, producesSortedKeys?: boolean | undefined}; export type Source = {baseSpecs?: Array<{[key: string]: unknown}> | undefined, codec?: {[key: string]: unknown} | undefined, doesNotNeedSplitting?: boolean | undefined, metadata?: SourceMetadata | undefined, spec?: {[key: string]: unknown} | undefined}; export type DerivedSource = {derivationMode?: ('SOURCE_DERIVATION_MODE_UNKNOWN' | 'SOURCE_DERIVATION_MODE_INDEPENDENT' | 'SOURCE_DERIVATION_MODE_CHILD_OF_CURRENT' | 'SOURCE_DERIVATION_MODE_SIBLING_OF_CURRENT') | undefined, source?: Source | undefined}; export type DynamicSourceSplit = {primary?: DerivedSource | undefined, residual?: DerivedSource | undefined}; export type Status = {code?: number | undefined, details?: Array<{[key: string]: unknown}> | undefined, message?: string | undefined}; export type MetricStructuredName = {context?: {[key: string]: string} | undefined, name?: string | undefined, origin?: string | undefined}; export type MetricUpdate = {boundedTrie: unknown, cumulative?: boolean | undefined, distribution: unknown, gauge: unknown, internal: unknown, kind?: string | undefined, meanCount: unknown, meanSum: unknown, name?: MetricStructuredName | undefined, scalar: unknown, set: unknown, trie: unknown, updateTime?: unknown | undefined}; export type ConcatPosition = {index?: number | undefined, position?: Position | undefined}; export type Position = {byteOffset?: unknown | undefined, concatPosition?: ConcatPosition | undefined, end?: boolean | undefined, key?: string | undefined, recordIndex?: unknown | undefined, shufflePosition?: string | undefined}; export type ApproximateProgress = {percentComplete?: number | undefined, position?: Position | undefined, remainingTime?: unknown | undefined}; export type ReportedParallelism = {isInfinite?: boolean | undefined, value?: number | undefined}; export type ApproximateReportedProgress = {consumedParallelism?: ReportedParallelism | undefined, fractionConsumed?: number | undefined, position?: Position | undefined, remainingParallelism?: ReportedParallelism | undefined}; export type SourceSplitShard = {derivationMode?: ('SOURCE_DERIVATION_MODE_UNKNOWN' | 'SOURCE_DERIVATION_MODE_INDEPENDENT' | 'SOURCE_DERIVATION_MODE_CHILD_OF_CURRENT' | 'SOURCE_DERIVATION_MODE_SIBLING_OF_CURRENT') | undefined, source?: Source | undefined}; export type SourceFork = {primary?: SourceSplitShard | undefined, primarySource?: DerivedSource | undefined, residual?: SourceSplitShard | undefined, residualSource?: DerivedSource | undefined}; export type SourceGetMetadataResponse = {metadata?: SourceMetadata | undefined}; export type SourceSplitResponse = {bundles?: Array | undefined, outcome?: ('SOURCE_SPLIT_OUTCOME_UNKNOWN' | 'SOURCE_SPLIT_OUTCOME_USE_CURRENT' | 'SOURCE_SPLIT_OUTCOME_SPLITTING_HAPPENED') | undefined, shards?: Array | undefined}; export type SourceOperationResponse = {getMetadata?: SourceGetMetadataResponse | undefined, split?: SourceSplitResponse | undefined}; export type WorkItemStatus = {completed?: boolean | undefined, counterUpdates?: Array | undefined, dynamicSourceSplit?: DynamicSourceSplit | undefined, errors?: Array | undefined, metricUpdates?: Array | undefined, progress?: ApproximateProgress | undefined, reportIndex?: unknown | undefined, reportedProgress?: ApproximateReportedProgress | undefined, requestedLeaseDuration?: unknown | undefined, sourceFork?: SourceFork | undefined, sourceOperationResponse?: SourceOperationResponse | undefined, stopPosition?: Position | undefined, totalThrottlerWaitTimeSeconds?: number | undefined, workItemId?: string | undefined}; export type ReportWorkItemStatusRequest = {currentWorkerTime?: unknown | undefined, location?: string | undefined, projectNumber?: unknown | undefined, unifiedWorkerRequest?: {[key: string]: unknown} | undefined, workItemStatuses?: Array | undefined, workerId?: string | undefined}; export type CreateApiV1b3ProjectsProjectIdJobsJobIdWorkItemsReportStatusArgs = {projectId: string, jobId: string, body: ReportWorkItemStatusRequest}; export type CreateApiV1b3ProjectsProjectIdJobsJobIdWorkItemsReportStatusOptions = {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 hotKeyDetection = z.object({hotKeyAge: z.string().optional(), systemName: z.string().optional(), userStepName: z.string().optional()}); export const metricShortId = z.object({metricIndex: z.number().int().optional(), shortId: z.string().optional()}); export const concatPosition = z.object({index: z.number().int().optional(), position: z.lazy(() => position.optional())}); export const position: z.ZodType = z.object({byteOffset: z.string().optional(), concatPosition: concatPosition.optional(), end: z.boolean().optional(), key: z.string().optional(), recordIndex: z.string().optional(), shufflePosition: z.string().optional()}); export const approximateSplitRequest = z.object({fractionConsumed: z.number().optional(), fractionOfRemainder: z.number().optional(), position: position.optional()}); export const approximateProgress = z.object({percentComplete: z.number().optional(), position: position.optional(), remainingTime: z.string().optional()}); export const workItemServiceState = z.object({completeWorkStatus: status.optional(), harnessData: z.record(z.string(), z.unknown()).optional(), hotKeyDetection: hotKeyDetection.optional(), leaseExpireTime: z.string().optional(), metricShortId: z.array(metricShortId).optional(), nextReportIndex: z.string().optional(), reportStatusInterval: z.string().optional(), splitRequest: approximateSplitRequest.optional(), suggestedStopPoint: approximateProgress.optional(), suggestedStopPosition: position.optional()}); export const reportWorkItemStatusResponse = z.object({unifiedWorkerResponse: z.record(z.string(), z.unknown()).optional(), workItemServiceStates: z.array(workItemServiceState).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 }; /** * Reports the status of dataflow WorkItems leased by a worker. * * POST /v1b3/projects/{projectId}/jobs/{jobId}/workItems:reportStatus * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1b3ProjectsProjectIdJobsJobIdWorkItemsReportStatus = async (args: CreateApiV1b3ProjectsProjectIdJobsJobIdWorkItemsReportStatusArgs, options?: CreateApiV1b3ProjectsProjectIdJobsJobIdWorkItemsReportStatusOptions) => { const {baseUrl = "https://dataflow.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(/\/+$/, '')}/v1b3/projects/${encodeURIComponent(String(args.projectId))}/jobs/${encodeURIComponent(String(args.jobId))}/workItems:reportStatus${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(reportWorkItemStatusResponse, await res.json()) };