import {z} from 'zod' export type GetApiV1b3ProjectsProjectIdLocationsLocationSnapshotsArgs = {projectId: string, location: string, jobId?: string | undefined}; export type GetApiV1b3ProjectsProjectIdLocationsLocationSnapshotsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const pubsubSnapshotMetadata = z.object({expireTime: z.string().optional(), snapshotName: z.string().optional(), topicName: z.string().optional()}); export const snapshot = z.object({creationTime: z.string().optional(), description: z.string().optional(), diskSizeBytes: z.string().optional(), id: z.string().optional(), projectId: z.string().optional(), pubsubMetadata: z.array(pubsubSnapshotMetadata).optional(), region: z.string().optional(), sourceJobId: z.string().optional(), state: z.enum(["UNKNOWN_SNAPSHOT_STATE", "PENDING", "RUNNING", "READY", "FAILED", "DELETED"]).optional(), ttl: z.string().optional()}); export const listSnapshotsResponse = z.object({snapshots: z.array(snapshot).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 }; /** * Lists snapshots. * * GET /v1b3/projects/{projectId}/locations/{location}/snapshots * * Also accepts auth: Oauth2 + Oauth2c */ export const getApiV1b3ProjectsProjectIdLocationsLocationSnapshots = async (args: GetApiV1b3ProjectsProjectIdLocationsLocationSnapshotsArgs, options?: GetApiV1b3ProjectsProjectIdLocationsLocationSnapshotsOptions) => { const {baseUrl = "https://dataflow.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jobId != null) query.append("jobId", String(args.jobId)) 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))}/locations/${encodeURIComponent(String(args.location))}/snapshots${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(listSnapshotsResponse, await res.json()) };