import {z} from 'zod' export type GetApiApiOrgIdFunctionsNameArgs = {org_id: string, name: string}; export type GetApiApiOrgIdFunctionsNameOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const streamType = z.enum(["logs", "metrics", "traces", "profiles", "service_graph", "enrichment_tables", "file_list", "metadata", "index"]); export const streamOrder = z.object({applyBeforeFlattening: z.boolean().optional(), isRemoved: z.boolean().optional(), order: z.number().int().gte(0).optional(), stream: z.string().optional(), streamType: streamType.optional()}); export const transform = z.object({function: z.string(), name: z.string().optional(), numArgs: z.number().int().gte(0).optional(), params: z.string().optional(), streams: z.array(streamOrder).nullable().optional(), transType: z.number().int().gte(0).nullable().optional()}); export const getApiApiOrgIdFunctionsNameResponse = z.object({list: z.array(transform)}); 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 function pipeline dependencies * * GET /api/{org_id}/functions/{name} */ export const getApiApiOrgIdFunctionsName = async (args: GetApiApiOrgIdFunctionsNameArgs, options: GetApiApiOrgIdFunctionsNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/functions/${encodeURIComponent(String(args.name))}${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(getApiApiOrgIdFunctionsNameResponse, await res.json()) };