import {z} from 'zod' export type DataSource = {name?: string | undefined, description?: string | undefined, data_credentials_id?: number | undefined, stream_config?: Record | undefined, source_type?: string | undefined, code_container_id?: number | undefined, code_container?: ({code?: (string | Record | Array) | undefined, name?: string | undefined, description?: string | undefined, resource_type?: ('source' | 'source_custom') | undefined, code_type?: ('jolt_standard' | 'jolt_custom' | 'python' | 'python3' | 'javascript' | 'flink_sql' | 'spark_sql') | undefined, code_encoding?: ('none' | 'base64') | undefined, code_config?: Record | undefined, custom_config?: Record | undefined, repo_type?: ('embedded' | 'github') | undefined, repo_config?: Record | undefined}) | undefined}; export type UpdateApiDataSourcesSourceIdArgs = {source_id: number, body: DataSource}; export type UpdateApiDataSourcesSourceIdOptions = {baseUrl?: string | undefined, NexlaSessionToken?: string | undefined, fetch?: typeof fetch | undefined}; export const owner = z.object({id: z.number().int().optional(), full_name: z.string().optional(), email: z.string().optional()}); export const org = z.object({id: z.number().int().optional(), name: z.string().optional(), email_domain: z.string().optional(), email: z.unknown(), client_identifier: z.unknown()}); export const accessRoles = z.array(z.enum(["owner", "collaborator", "operator", "admin"])); export const updateApiDataSourcesSourceIdResponse = z.object({id: z.number().int().optional(), owner: owner.optional(), org: org.optional(), access_roles: accessRoles.optional(), name: z.string().optional(), description: z.unknown(), status: z.string().optional(), data_sets: z.array(z.object({version: z.number().int().optional(), id: z.number().int().optional(), owner_id: z.number().int().optional(), org_id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), updated_at: z.string().optional(), created_at: z.string().optional()})).optional(), ingest_method: z.string().optional(), source_format: z.string().optional(), source_config: z.record(z.string(), z.string()).optional(), poll_schedule: z.unknown(), managed: z.boolean().optional(), code_container_id: z.unknown(), source_type: z.string().optional(), connector_type: z.string().optional(), connector: z.object({id: z.number().int().optional(), type: z.string().optional(), connection_type: z.string().optional(), name: z.string().optional(), description: z.string().optional(), nexset_api_compatible: z.boolean().optional()}).optional(), api_keys: z.array(z.unknown()).optional(), auto_generated: z.boolean().optional(), data_credentials: z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), owner: owner.optional(), org: org.optional(), access_roles: accessRoles.optional(), credentials_version: z.string().optional(), managed: z.boolean().optional(), credentials_type: z.string().optional(), connector: z.object({id: z.number().int().optional(), type: z.string().optional(), connection_type: z.string().optional(), name: z.string().optional(), description: z.string().optional(), nexset_api_compatible: z.boolean().optional()}).optional(), api_keys: z.array(z.unknown()).optional(), credentials_non_secure_data: z.record(z.string(), z.union([z.string(), z.object({}), z.number().int()])).optional(), verified_status: z.string().optional(), verified_at: z.string().optional(), copied_from_id: z.unknown(), updated_at: z.string().optional(), created_at: z.string().optional(), tags: z.array(z.unknown()).optional()}).optional(), run_ids: z.array(z.object({id: z.number().int().optional(), created_at: z.string().optional()})).optional(), copied_from_id: z.unknown(), updated_at: z.string().optional(), created_at: z.string().optional(), tags: z.array(z.unknown()).optional(), flow_type: z.string().optional(), ingestion_mode: 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 Source * * PUT /data_sources/{source_id} */ export const updateApiDataSourcesSourceId = async (args: UpdateApiDataSourcesSourceIdArgs, options?: UpdateApiDataSourcesSourceIdOptions) => { 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 (NexlaSessionToken !== undefined) headers.set('authorization', `Bearer ${NexlaSessionToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/data_sources/${encodeURIComponent(String(args.source_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(updateApiDataSourcesSourceIdResponse, await res.json()) };