import { z } from 'zod'; import { KVClient } from '../kv'; /** * Document type that combines a schema type with an _id field */ export type Document = T & { _id: string; }; /** * DBClient provides methods to interact with Spark's document database. */ export declare class DBClient { private kv; constructor(kvClient?: KVClient); /** * Generate a unique document ID using ULID * @returns A unique document ID */ generateDocId(): string; /** * Get all documents in a collection using the DB API * @param collectionName The name of the collection * @returns Array of all documents in the collection with id field */ getAll(collectionName: string): Promise[]>; /** * Insert a document into a collection with schema validation * @param collectionName The name of the collection * @param schema The Zod schema for validation * @param data The document data to insert * @returns The inserted document with generated id */ insert(collectionName: string, schema: T, data: z.infer): Promise>>; /** * Get a document by ID from a collection * @param collectionName The name of the collection * @param id The document ID * @returns The document with id field or null if not found */ get(collectionName: string, id: string): Promise | null>; /** * Update a document with partial data and schema validation * @param collectionName The name of the collection * @param id The document ID * @param schema The Zod schema for validation * @param data Partial data to update * @returns The updated document or null if not found */ update(collectionName: string, id: string, schema: T, data: Partial>): Promise> | null>; /** * Delete a document from a collection * @param collectionName The name of the collection * @param id The document ID to delete * @returns true if document was deleted, false if not found */ delete(collectionName: string, id: string): Promise; /** * Query documents with filtering * @param collectionName The name of the collection * @param filterFn Function to filter documents * @returns Array of filtered documents */ query(collectionName: string, filterFn: (doc: Document) => boolean): Promise[]>; }