import {z} from 'zod' export type GetApiWorkspaceWorkspaceIdScheduleScheduleIdArgs = {'fields[schedule]'?: (Array<'createdBy' | 'createdDate' | 'cron' | 'description' | 'enabled' | 'tcl' | 'templateReference' | 'updatedBy' | 'updatedDate' | 'workspace'>) | undefined, include?: Array<'workspace'> | undefined}; export type GetApiWorkspaceWorkspaceIdScheduleScheduleIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const schedule = z.object({type: z.string().optional(), id: z.string().optional(), attributes: z.object({createdBy: z.string().optional(), createdDate: z.string().optional(), cron: z.string().optional(), description: z.string().optional(), enabled: z.boolean().optional(), tcl: z.string().optional(), templateReference: z.string().optional(), updatedBy: z.string().optional(), updatedDate: z.string().optional()}).optional(), relationships: z.object({workspace: z.object({id: z.string().optional(), type: z.literal("workspace").optional()}).optional()}).optional()}); export const getApiWorkspaceWorkspaceIdScheduleScheduleIdResponse = z.object({data: schedule.optional(), included: z.array(z.object({attributes: z.object({}).optional(), id: z.string().optional(), relationships: z.object({}).optional(), type: z.string().optional()})).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 }; /** * Returns an instance of type schedule * * GET /workspace/{workspaceId}/schedule/{scheduleId} */ export const getApiWorkspaceWorkspaceIdScheduleScheduleId = async (args: GetApiWorkspaceWorkspaceIdScheduleScheduleIdArgs, options: GetApiWorkspaceWorkspaceIdScheduleScheduleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") for (const item of args['fields[schedule]'] ?? []) query.append("fields[schedule]", String(item)) for (const item of args.include ?? []) query.append("include", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/workspace/${encodeURIComponent(String(args.workspaceId))}/schedule/${encodeURIComponent(String(args.scheduleId))}${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(getApiWorkspaceWorkspaceIdScheduleScheduleIdResponse, await res.json()) };