import {z} from 'zod' export type CodeContainersResourceType = 'transform' | 'ai_function' | 'source' | 'sink' | 'error' | 'validator'; export type CodeContainersOutputType = 'record' | 'attribute' | 'custom'; export type CodeContainersCodeType = 'jolt_standard' | 'jolt_custom' | 'python' | 'python3' | 'javascript'; export type CodeContainerMutable = {name: string, description?: string | undefined, data_credentials_id?: number | undefined, resource_type?: CodeContainersResourceType | undefined, ai_function_type?: ('chunker' | 'context_enricher' | 'query_rewriter' | 'reranker') | undefined, output_type: CodeContainersOutputType, code_type: CodeContainersCodeType, code_encoding: 'none' | 'base64', code: string | Array<{operation?: string | undefined, spec?: ({language?: string | undefined, encoding?: string | undefined, script?: string | undefined}) | undefined}>, reusable: boolean, tags?: Array | undefined, custom_config?: Record | undefined}; export type UpdateApiCodeContainersCodeContainerIdArgs = {code_container_id: number, Accept?: ('application/vnd.nexla.api.v1+json' | 'application/json') | undefined, body: CodeContainerMutable}; export type UpdateApiCodeContainersCodeContainerIdOptions = {baseUrl?: string | undefined, NexlaSessionToken?: string | undefined, fetch?: typeof fetch | undefined}; export const codeContainersResourceType = z.enum(["transform", "ai_function", "source", "sink", "error", "validator"]); export const userSimplified = z.object({id: z.number().int().optional(), full_name: z.string().optional(), email: z.string().optional(), email_verified_at: z.string().optional()}); export const orgSimplified = z.object({id: z.number().int().optional(), name: z.string().optional(), email_domain: z.string().optional(), email: z.string().optional(), client_identifier: z.string().optional(), org_webhook_host: z.string().optional()}); export const accessRoles = z.array(z.enum(["owner", "collaborator", "operator", "admin"])); export const codeContainersCodeType = z.enum(["jolt_standard", "jolt_custom", "python", "python3", "javascript"]); export const codeContainersOutputType = z.enum(["record", "attribute", "custom"]); export const codeContainer = z.object({id: z.number().int().optional(), name: z.string().optional(), resource_type: codeContainersResourceType.optional(), ai_function_type: z.enum(["chunker", "context_enricher", "query_rewriter", "reranker"]).optional(), reusable: z.boolean().optional(), public: z.boolean().optional(), owner: userSimplified.optional(), org: orgSimplified.optional(), access_roles: accessRoles.optional(), data_credentials: z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), updated_at: z.string().optional(), created_at: z.string().optional()}).optional(), runtime_data_credentials: z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), updated_at: z.string().optional(), created_at: z.string().optional()}).optional(), description: z.string().optional(), code_type: codeContainersCodeType.optional(), output_type: codeContainersOutputType.optional(), code_config: z.object({}).optional(), custom_config: z.object({}).optional(), code_encoding: z.string().optional(), code: z.array(z.object({operation: z.string().optional(), spec: z.object({language: z.string().optional(), encoding: z.string().optional(), script: z.string().optional()}).optional()})).optional(), managed: z.boolean().optional(), data_sets: z.array(z.number().int()).optional(), copied_from_id: z.number().int().optional(), updated_at: z.string().optional(), created_at: z.string().optional(), tags: z.array(z.string()).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 }; /** * Update a Code Container * * PUT /code_containers/{code_container_id} */ export const updateApiCodeContainersCodeContainerId = async (args: UpdateApiCodeContainersCodeContainerIdArgs, options?: UpdateApiCodeContainersCodeContainerIdOptions) => { const {baseUrl = "https://dataops.nexla.io/nexla-api", fetch: fetchFn = fetch, NexlaSessionToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (NexlaSessionToken !== undefined) headers.set('authorization', `Bearer ${NexlaSessionToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/code_containers/${encodeURIComponent(String(args.code_container_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(codeContainer, await res.json()) };