import {z} from 'zod' export type GetApiApiAtlasV2GroupsGroupIdPipelinesPipelineNameRunsArgs = {envelope?: boolean | undefined, groupId: string, includeCount?: boolean | undefined, itemsPerPage?: number | undefined, pageNum?: number | undefined, pretty?: boolean | undefined, createdBefore?: string | undefined, pipelineName: string}; export type GetApiApiAtlasV2GroupsGroupIdPipelinesPipelineNameRunsOptions = {baseUrl?: string | undefined, ServiceAccounts?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({href: z.string().optional(), rel: z.string().optional()}); export const datasetRetentionPolicy = z.object({lastModifiedDate: z.string().optional(), units: z.enum(["DAYS", "WEEKS", "MONTHS"]), value: z.number().int().gte(1)}); export const pipelineRunStats = z.object({bytesExported: z.number().int().optional(), numDocs: z.number().int().optional()}); export const ingestionPipelineRun = z.object({_id: z.string().optional(), backupFrequencyType: z.enum(["HOURLY", "DAILY", "WEEKLY", "MONTHLY", "YEARLY", "ON_DEMAND"]).optional(), createdDate: z.string().optional(), datasetName: z.string().optional(), datasetRetentionPolicy: datasetRetentionPolicy.optional(), groupId: z.string().optional(), lastUpdatedDate: z.string().optional(), phase: z.enum(["SNAPSHOT", "EXPORT", "INGESTION"]).optional(), pipelineId: z.string().optional(), scheduledDeletionDate: z.string().optional(), snapshotId: z.string().optional(), state: z.enum(["PENDING", "IN_PROGRESS", "DONE", "FAILED", "DATASET_DELETED"]).optional(), stats: pipelineRunStats.optional()}); export const paginatedPipelineRunView = z.object({links: z.array(link).optional(), results: z.array(ingestionPipelineRun), totalCount: z.number().int().gte(0).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 }; /** * Return All Data Lake Pipeline Runs in One Project * * GET /api/atlas/v2/groups/{groupId}/pipelines/{pipelineName}/runs * * Also accepts auth: DigestAuth */ export const getApiApiAtlasV2GroupsGroupIdPipelinesPipelineNameRuns = async (args: GetApiApiAtlasV2GroupsGroupIdPipelinesPipelineNameRunsArgs, options?: GetApiApiAtlasV2GroupsGroupIdPipelinesPipelineNameRunsOptions) => { const {baseUrl = "https://cloud.mongodb.com", fetch: fetchFn = fetch, ServiceAccounts} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.atlas.2023-01-01+json") if (args.envelope != null) query.append("envelope", String(args.envelope)) if (args.includeCount != null) query.append("includeCount", String(args.includeCount)) if (args.itemsPerPage != null) query.append("itemsPerPage", String(args.itemsPerPage)) if (args.pageNum != null) query.append("pageNum", String(args.pageNum)) if (args.pretty != null) query.append("pretty", String(args.pretty)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (ServiceAccounts !== undefined) headers.set('authorization', `Bearer ${ServiceAccounts}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/atlas/v2/groups/${encodeURIComponent(String(args.groupId))}/pipelines/${encodeURIComponent(String(args.pipelineName))}/runs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedPipelineRunView, await res.json()) };