import {z} from 'zod' export type UsersSelectColumn = {id?: Record | undefined, name?: Record | undefined, rocket?: Record | undefined, timestamp?: Record | undefined, twitter?: Record | undefined}; export type UsersOrderBy = {id?: Record | undefined, name?: Record | undefined, rocket?: Record | undefined, timestamp?: Record | undefined, twitter?: Record | undefined}; export type UsersBoolExp = {_and?: Array> | undefined, _not?: Record | undefined, _or?: Array> | undefined, id?: Record | undefined, name?: Record | undefined, rocket?: Record | undefined, timestamp?: Record | undefined, twitter?: Record | undefined}; export type GetApiRestUsersAggregateArgs = {distinctOn?: Array | undefined, limit?: number | undefined, offset?: number | undefined, order_by?: Array | undefined, where?: UsersBoolExp | undefined, usersAggregateAggregateAggregateCountColumns?: Array | undefined, usersAggregateAggregateAggregateCountDistinct?: boolean | undefined}; export type GetApiRestUsersAggregateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const usersMaxFields = z.object({name: z.string().optional(), rocket: z.string().optional(), timestamp: z.object({}).optional(), twitter: z.string().optional()}); export const usersMinFields = z.object({name: z.string().optional(), rocket: z.string().optional(), timestamp: z.object({}).optional(), twitter: z.string().optional()}); export const usersAggregateFields = z.object({count: z.number().int().optional(), max: usersMaxFields.optional(), min: usersMinFields.optional()}); export const users = z.object({id: z.object({}), name: z.string().optional(), rocket: z.string().optional(), timestamp: z.object({}), twitter: z.string().optional()}); export const usersAggregate = z.object({aggregate: usersAggregateFields.optional(), nodes: z.array(users)}); 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 /rest/users-aggregate */ export const getApiRestUsersAggregate = async (args: GetApiRestUsersAggregateArgs, options: GetApiRestUsersAggregateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.distinctOn ?? []) query.append("distinctOn", String(item)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) for (const item of args.order_by ?? []) query.append("order_by", String(item)) if (args.where != null) query.append("where", JSON.stringify(args.where)) for (const item of args.usersAggregateAggregateAggregateCountColumns ?? []) query.append("usersAggregateAggregateAggregateCountColumns", String(item)) if (args.usersAggregateAggregateAggregateCountDistinct != null) query.append("usersAggregateAggregateAggregateCountDistinct", String(args.usersAggregateAggregateAggregateCountDistinct)) const url = `${baseUrl.replace(/\/+$/, '')}/rest/users-aggregate${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(usersAggregate, await res.json()) };