import {z} from 'zod' export type Int32Parameter = {eq?: (number | null) | undefined, ne?: (number | null) | undefined, gt?: (number | null) | undefined, ge?: (number | null) | undefined, lt?: (number | null) | undefined, le?: (number | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type TimestampParameter = {eq?: (string | null) | undefined, ne?: (string | null) | undefined, gt?: (string | null) | undefined, ge?: (string | null) | undefined, lt?: (string | null) | undefined, le?: (string | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type GetApiV1OperationsVdfRevelationsCountArgs = {level?: (Int32Parameter | null) | undefined, timestamp?: (TimestampParameter | null) | undefined}; export type GetApiV1OperationsVdfRevelationsCountOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1OperationsVdfRevelationsCountResponse = z.number().int(); 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 vdf revelations count * * GET /v1/operations/vdf_revelations/count */ export const getApiV1OperationsVdfRevelationsCount = async (args: GetApiV1OperationsVdfRevelationsCountArgs, options?: GetApiV1OperationsVdfRevelationsCountOptions) => { const {baseUrl = "https://api.tzkt.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.level != null) query.append("level", JSON.stringify(args.level)) if (args.timestamp != null) query.append("timestamp", JSON.stringify(args.timestamp)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/operations/vdf_revelations/count${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(getApiV1OperationsVdfRevelationsCountResponse, await res.json()) };