import {z} from 'zod' export type GetApiTransformsTransformIdCheckpointsArgs = {transform_id: string, include_operator_breakdown?: boolean | undefined}; export type GetApiTransformsTransformIdCheckpointsOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const transformCheckpointHistory = z.object({id: z.number().int(), status: z.string(), is_savepoint: z.boolean(), trigger_timestamp: z.number().int(), latest_ack_timestamp: z.number().int(), state_size: z.number().int(), end_to_end_duration: z.number().int(), alignment_buffered: z.number().int(), num_subtasks: z.number().int(), num_acknowledged_subtasks: z.number().int()}).and(z.record(z.string(), z.unknown())); export const transformOperatorState = z.object({operator_id: z.string(), operator_name: z.string(), state_size: z.number().int(), checkpointed_size: z.number().int(), end_to_end_duration: z.number().int(), parallelism: z.number().int()}).and(z.record(z.string(), z.unknown())); export const transformCheckpointsInfo = z.object({job_id: z.string(), counts: z.record(z.string(), z.unknown()), summary: z.record(z.string(), z.unknown()), latest: transformCheckpointHistory.nullable().optional(), history: z.array(transformCheckpointHistory).optional(), operator_breakdown: z.array(transformOperatorState).optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Get Transform Checkpoints * * GET /transforms/{transform_id}/checkpoints */ export const getApiTransformsTransformIdCheckpoints = async (args: GetApiTransformsTransformIdCheckpointsArgs, options?: GetApiTransformsTransformIdCheckpointsOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_operator_breakdown != null) query.append("include_operator_breakdown", String(args.include_operator_breakdown)) if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/transforms/${encodeURIComponent(String(args.transform_id))}/checkpoints${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(transformCheckpointsInfo, await res.json()) };