/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { blobLikeSchema } from "../../types/blobs.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type FileT = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type IndexFileRequest = { /** * The name of the index to which the document will be added */ indexName: string; /** * Text-based files and PDF files are supported. */ file: FileT | Blob; /** * The ID of the document. If not provided, a unique document ID will be automatically generated by the server */ docId?: string | undefined; /** * Title of the document to be indexed */ title?: string | undefined; /** * URL associated with the document to be indexed */ url?: string | undefined; /** * Metadata associated with the document as JSON string. Accepts key value pairs where the value can be a string, number, boolean, or list of strings. */ metadata?: string | undefined; }; /** @internal */ export const FileT$inboundSchema: z.ZodType = z .object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); /** @internal */ export type FileT$Outbound = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ export const FileT$outboundSchema: z.ZodType< FileT$Outbound, z.ZodTypeDef, FileT > = z.object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace FileT$ { /** @deprecated use `FileT$inboundSchema` instead. */ export const inboundSchema = FileT$inboundSchema; /** @deprecated use `FileT$outboundSchema` instead. */ export const outboundSchema = FileT$outboundSchema; /** @deprecated use `FileT$Outbound` instead. */ export type Outbound = FileT$Outbound; } export function fileToJSON(fileT: FileT): string { return JSON.stringify(FileT$outboundSchema.parse(fileT)); } export function fileFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => FileT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FileT' from JSON`, ); } /** @internal */ export const IndexFileRequest$inboundSchema: z.ZodType< IndexFileRequest, z.ZodTypeDef, unknown > = z.object({ index_name: z.string(), file: z.lazy(() => FileT$inboundSchema), doc_id: z.string().optional(), title: z.string().optional(), url: z.string().optional(), metadata: z.string().optional(), }).transform((v) => { return remap$(v, { "index_name": "indexName", "doc_id": "docId", }); }); /** @internal */ export type IndexFileRequest$Outbound = { index_name: string; file: FileT$Outbound | Blob; doc_id?: string | undefined; title?: string | undefined; url?: string | undefined; metadata?: string | undefined; }; /** @internal */ export const IndexFileRequest$outboundSchema: z.ZodType< IndexFileRequest$Outbound, z.ZodTypeDef, IndexFileRequest > = z.object({ indexName: z.string(), file: z.lazy(() => FileT$outboundSchema).or(blobLikeSchema), docId: z.string().optional(), title: z.string().optional(), url: z.string().optional(), metadata: z.string().optional(), }).transform((v) => { return remap$(v, { indexName: "index_name", docId: "doc_id", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace IndexFileRequest$ { /** @deprecated use `IndexFileRequest$inboundSchema` instead. */ export const inboundSchema = IndexFileRequest$inboundSchema; /** @deprecated use `IndexFileRequest$outboundSchema` instead. */ export const outboundSchema = IndexFileRequest$outboundSchema; /** @deprecated use `IndexFileRequest$Outbound` instead. */ export type Outbound = IndexFileRequest$Outbound; } export function indexFileRequestToJSON( indexFileRequest: IndexFileRequest, ): string { return JSON.stringify( IndexFileRequest$outboundSchema.parse(indexFileRequest), ); } export function indexFileRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => IndexFileRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'IndexFileRequest' from JSON`, ); }