import {z} from 'zod' export type UpdateDatasetInfoRequest = {name?: (string | null) | undefined, folder?: (string | null) | undefined}; export type PatchApiV1DatasetsDatasetIdArgs = {dataset_id: string, body: UpdateDatasetInfoRequest}; export type PatchApiV1DatasetsDatasetIdOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const datasetStatus = z.enum(["READY", "PENDING", "FAILED", "TEMPORARY", "DRAFT"]); export const schemaPrimitiveType = z.enum(["string", "integer", "boolean", "float", "double", "json", "null"]); export const schemaPrimitive = z.object({name: schemaPrimitiveType}); export const schemaOptionType = z.literal("option"); export const schemaOptionOutput: z.ZodType = z.object({name: schemaOptionType, item: z.union([schemaPrimitive, z.lazy(() => schemaOptionOutput)])}); export const columnSchemaOutput = z.object({name: z.string(), type: z.union([schemaPrimitive, schemaOptionOutput])}); export const datasetOriginType = z.enum(["upload", "s3", "demo"]); export const datasetOriginResponse = z.object({type: datasetOriginType}); export const datasetResponse = z.object({id: z.string(), name: z.string(), status: datasetStatus, schema: z.array(columnSchemaOutput), metadata: z.record(z.string(), z.union([z.string(), z.array(z.string())])), current_version_origin: datasetOriginResponse.nullable().optional(), folder: z.string(), current_version: z.string().nullable(), type: z.string().optional(), created_at: z.number().int(), error: z.string().nullable(), ai_project_id: z.string().nullable().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 dataset info * * PATCH /v1/datasets/{dataset_id} */ export const patchApiV1DatasetsDatasetId = async (args: PatchApiV1DatasetsDatasetIdArgs, options?: PatchApiV1DatasetsDatasetIdOptions) => { const {baseUrl = "https://api.tokenfactory.nebius.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/datasets/${encodeURIComponent(String(args.dataset_id))}${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(datasetResponse, await res.json()) };