import {z} from 'zod' export type GetApiV1DatasetsUploadsUploadIdArgs = {upload_id: string, ai_project_id?: (string | null) | undefined}; export type GetApiV1DatasetsUploadsUploadIdOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const uploadStatus = z.enum(["PENDING", "COMPLETING", "COMPLETED", "FAILED", "CANCELLED"]); 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 uploadDatasetInfoResponse = z.object({id: z.string().nullable().optional(), name: z.string(), schema: z.array(columnSchemaOutput), folder: z.string()}); export const uploadInfoResponse = z.object({status: uploadStatus, dataset: uploadDatasetInfoResponse, error: z.string().nullable().optional(), created_at: z.number().int(), completed_at: z.number().int().nullable().optional(), ai_project_id: z.string().nullable().optional()}); export const uploadResponse = z.object({id: z.string(), upload_info: uploadInfoResponse}); 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 information about a multipart upload * * GET /v1/datasets/uploads/{upload_id} */ export const getApiV1DatasetsUploadsUploadId = async (args: GetApiV1DatasetsUploadsUploadIdArgs, options?: GetApiV1DatasetsUploadsUploadIdOptions) => { const {baseUrl = "https://api.tokenfactory.nebius.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ai_project_id != null) query.append("ai_project_id", String(args.ai_project_id)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/datasets/uploads/${encodeURIComponent(String(args.upload_id))}${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(uploadResponse, await res.json()) };