import {z} from 'zod' export type SpiderJobArg = {name: string, value: string}; export type SpiderJobEnvVar = {evid?: (number | null) | undefined, name: string, value: string, masked?: boolean | undefined}; export type SpiderJobTag = {name: string}; export type SpiderCronJob = {cjid?: number | undefined, spider?: string | undefined, created?: string | undefined, name?: string | undefined, cargs?: Array | undefined, cenv_vars?: Array | undefined, ctags?: Array | undefined, schedule?: string | undefined, status?: ('ACTIVE' | 'DISABLED') | undefined, unique_collection?: boolean | undefined, data_status?: ('PERSISTENT' | 'PENDING') | undefined, data_expiry_days?: (number | null) | undefined, resource_tier?: ('TINY' | 'XSMALL' | 'SMALL' | 'MEDIUM' | 'LARGE' | 'XLARGE' | 'HUGE' | 'XHUGE') | undefined}; export type PatchApiApiProjectsPidSpidersSidCronjobsCjidArgs = {body: SpiderCronJob}; export type PatchApiApiProjectsPidSpidersSidCronjobsCjidOptions = {baseUrl?: string | undefined, Basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const spiderJobArg = z.object({name: z.string().min(1).max(1000), value: z.string().min(1).max(1000)}); export const spiderJobEnvVar = z.object({evid: z.number().int().nullable().optional(), name: z.string().min(1).max(1000), value: z.string().min(1).max(12000), masked: z.boolean().optional()}); export const spiderJobTag = z.object({name: z.string().min(1).max(50)}); export const spiderCronJob = z.object({cjid: z.number().int().optional(), spider: z.string().optional(), created: z.string().optional(), name: z.string().min(1).optional(), cargs: z.array(spiderJobArg).optional(), cenv_vars: z.array(spiderJobEnvVar).optional(), ctags: z.array(spiderJobTag).optional(), schedule: z.string().max(20).optional(), status: z.enum(["ACTIVE", "DISABLED"]).optional(), unique_collection: z.boolean().optional(), data_status: z.enum(["PERSISTENT", "PENDING"]).optional(), data_expiry_days: z.number().int().gte(0).lte(65535).nullable().optional(), resource_tier: z.enum(["TINY", "XSMALL", "SMALL", "MEDIUM", "LARGE", "XLARGE", "HUGE", "XHUGE"]).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 }; /** * PATCH /api/projects/{pid}/spiders/{sid}/cronjobs/{cjid} */ export const patchApiApiProjectsPidSpidersSidCronjobsCjid = async (args: PatchApiApiProjectsPidSpidersSidCronjobsCjidArgs, options?: PatchApiApiProjectsPidSpidersSidCronjobsCjidOptions) => { const {baseUrl = "http://127.0.0.1:8000", fetch: fetchFn = fetch, Basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Basic !== undefined) headers.set('authorization', `Basic ${btoa(`${Basic.username}:${Basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.pid))}/spiders/${encodeURIComponent(String(args.sid))}/cronjobs/${encodeURIComponent(String(args.cjid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(spiderCronJob, await res.json()) };