import {z} from 'zod' export type CreateApiApiV1QueuesQueueParamConcurrencyOverrideArgs = {queueParam: string, body: {type?: ('id' | 'task' | 'custom') | undefined, concurrencyLimit: number}}; export type CreateApiApiV1QueuesQueueParamConcurrencyOverrideOptions = {baseUrl?: string | undefined, secretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const queueObject = z.object({id: z.string(), name: z.string(), type: z.enum(["task", "custom"]), version: z.enum(["V1", "V2"]), running: z.number().int(), queued: z.number().int(), paused: z.boolean(), concurrencyLimit: z.number().int().nullable().optional(), concurrency: z.object({current: z.number().int().nullable().optional(), base: z.number().int().nullable().optional(), override: z.number().int().nullable().optional(), overriddenAt: z.string().nullable().optional(), overriddenBy: z.string().nullable().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 }; /** * Override queue concurrency limit * * POST /api/v1/queues/{queueParam}/concurrency/override */ export const createApiApiV1QueuesQueueParamConcurrencyOverride = async (args: CreateApiApiV1QueuesQueueParamConcurrencyOverrideArgs, options?: CreateApiApiV1QueuesQueueParamConcurrencyOverrideOptions) => { const {baseUrl = "https://api.trigger.dev", fetch: fetchFn = fetch, secretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (secretKey !== undefined) headers.set('authorization', `Bearer ${secretKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/queues/${encodeURIComponent(String(args.queueParam))}/concurrency/override${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(queueObject, await res.json()) };