/** * Comprehensive TypeScript types for CyborgDB SDK * * This file provides strongly-typed alternatives to generic `any` and `object` types * throughout the SDK, improving type safety and developer experience. */ import type { QueryResponse as GeneratedQueryResponse, GetResultItemModel, QueryResultItem } from "./models"; /** * Represents any valid JSON primitive value */ export type JsonPrimitive = string | number | boolean | null; /** * Represents any valid JSON value (recursive definition) * This is used for metadata and other JSON-serializable data */ export type JsonValue = JsonPrimitive | JsonObject | JsonArray; /** * Represents a JSON object with string keys and JsonValue values */ export interface JsonObject { [key: string]: JsonValue; } /** * Represents a JSON array */ export type JsonArray = JsonValue[]; /** * Metadata type for vector items * Metadata must be a valid JSON object */ export type VectorMetadata = JsonObject; /** * Filter expressions for querying vectors * Supports MongoDB-style query operators * * Examples: * - Simple equality: { category: "tech" } * - Comparison: { age: { $gt: 18, $lt: 65 } } * - Array operations: { tags: { $in: ["javascript", "typescript"] } } * - Logical operators: { $and: [{ price: { $gte: 10 } }, { stock: { $gt: 0 } }] } */ export type FilterExpression = { [key: string]: FilterValue | FilterOperator; }; /** * Possible filter values */ export type FilterValue = JsonPrimitive | JsonArray; /** * MongoDB-style filter operators */ export interface FilterOperator { $eq?: FilterValue; $ne?: FilterValue; $gt?: number; $gte?: number; $lt?: number; $lte?: number; $in?: JsonArray; $nin?: JsonArray; $and?: FilterExpression[]; $or?: FilterExpression[]; $nor?: FilterExpression[]; $not?: FilterExpression; $exists?: boolean; /** * ECMAScript regex, matched with search semantics (unanchored). * * On `query()` this resolves from the field's regex dictionary when the * index declared it `pattern: true`, and otherwise falls back to a * post-filter — same rows either way. On `queryMetadata()` there is no * fallback, so a non-pattern field is rejected. */ $regex?: string; /** Substring match. Same index-resolution rules as `$regex`. */ $contains?: string; } /** * Response from upsert operations */ export interface UpsertResponse { /** * Status of the operation */ status: string; /** * Additional message or details */ message?: string; } /** * Response from delete operations */ export interface DeleteResponse { /** * Status of the operation */ status: string; /** * Additional message or details */ message?: string; } /** * Response from train operations */ export interface TrainResponse { /** * Status of the training operation */ status: string; /** * Additional message or details */ message?: string; } /** * Response from health check */ export interface HealthResponse { /** * Status of the service */ status: string; /** * Optional additional health information */ [key: string]: string; } /** * Get operation result item with proper typing * Extends GetResultItemModel from models with enhanced type safety for metadata and contents */ export interface GetResultItem extends Omit { /** * The stored content, returned verbatim as a string (if included). Text * contents round-trip as the original UTF-8 string. Binary contents that * were upserted as a Buffer round-trip as a base64 string — decode them with * `Buffer.from(contents, "base64")`. */ contents?: string; /** * Metadata associated with the vector (if included) */ metadata?: VectorMetadata; } /** * Result of `query()` and `rerank()`: one list of matches for a single query, * or one list per query vector for a batch. * * Replaces the generated `QueryResponse`, whose `results` the generator emits * as `{}` because the schema is an `anyOf` of the two array shapes. */ export interface QueryResponse extends Omit { results: QueryResultItem[] | QueryResultItem[][]; } /** * Type guard to check if a value is a valid JSON value * Handles circular references by tracking visited objects */ export declare function isJsonValue(value: unknown, visited?: WeakSet): value is JsonValue; /** * Type guard to check if an error is an Error instance */ export declare function isError(error: unknown): error is Error; /** * Helper to safely extract error message from unknown error */ export declare function getErrorMessage(error: unknown): string;