import {z} from 'zod' export type GetApiFabricFabricApiSearchViewViewNamePropertiesArgs = {fabric: unknown, 'view-name': unknown}; export type GetApiFabricFabricApiSearchViewViewNamePropertiesOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const postApiViewSemanticFieldDef = z.object({"[field-name]": z.object({size: z.number().int(), distanceType: z.enum(["L2", "IP", "COSINE"]), indexConfig: z.object({type: z.enum(["hnsw", "ivf", "flat"]), maxSize: z.number().int().optional(), nLinks: z.number().int().optional(), efConstruction: z.number().int().optional(), efSearch: z.number().int().optional(), nProbe: z.number().int().optional(), sample: z.number().optional()}), quantizationConfig: z.object({type: z.enum(["none", "pq", "sq"]), bits: z.number().int().optional()}).optional()})}); export const postApiViewSemanticFields = z.object({fields: postApiViewSemanticFieldDef.optional()}); export const postApiViewLinkSemanticProps = z.object({"[collection-name]": postApiViewSemanticFields.optional()}); export const searchGetSemanticViewPropertiesRc200Example = z.object({code: z.number().int().optional(), error: z.boolean().optional(), result: z.object({globallyUniqueId: z.string().optional(), id: z.string().optional(), name: z.string().optional(), links: postApiViewLinkSemanticProps.optional(), type: z.string().optional()}).optional()}); export const postApiViewFields = z.object({"[field-name]": z.object({}).optional()}); export const postApiViewLinkProps = z.object({analyzers: z.array(z.string()).optional(), fields: postApiViewFields.optional(), includeAllFields: z.boolean().optional(), storeValues: z.string().optional(), trackListPositions: z.boolean().optional()}); export const postApiViewLinks = z.object({"[collection-name]": postApiViewLinkProps.optional()}); export const searchGetViewPropertiesRc200Example = z.object({code: z.number().int().optional(), error: z.boolean().optional(), result: z.object({globallyUniqueId: z.string().optional(), id: z.string().optional(), name: z.string().optional(), primarySort: z.array(z.object({field: z.string().optional(), direction: z.string().optional()})).optional(), links: postApiViewLinks.optional(), type: z.string().optional()}).optional()}); export const getApiFabricFabricApiSearchViewViewNamePropertiesResponse = z.union([searchGetSemanticViewPropertiesRc200Example, searchGetViewPropertiesRc200Example]); 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 }; /** * Read properties of search view * * GET /_fabric/{fabric}/_api/search/view/{view-name}/properties * * Also accepts auth: BearerAuth */ export const getApiFabricFabricApiSearchViewViewNameProperties = async (args: GetApiFabricFabricApiSearchViewViewNamePropertiesArgs, options: GetApiFabricFabricApiSearchViewViewNamePropertiesOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/_fabric/${encodeURIComponent(String(args.fabric))}/_api/search/view/${encodeURIComponent(String(args['view-name']))}/properties${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(getApiFabricFabricApiSearchViewViewNamePropertiesResponse, await res.json()) };