/** * @beignet/core/search * * Provider-neutral search primitives for Beignet applications. */ /** * Primitive values accepted in indexed documents and provider-neutral filters. */ export type SearchPrimitive = null | boolean | number | string; /** * JSON-like values accepted in indexed documents. */ export type SearchValue = SearchPrimitive | readonly SearchValue[] | { readonly [key: string]: SearchValue; }; /** * Minimal document shape accepted by search indexes. */ export type SearchDocumentBase = { id: string; }; /** * General search document shape. */ export type SearchDocument = SearchDocumentBase & { readonly [field: string]: SearchValue | undefined; }; type SearchField = Extract; /** * Provider-neutral index definition. */ export type SearchIndexDef = { kind: "search-index"; name: string; primaryKey: SearchField; searchableAttributes?: readonly SearchField[]; filterableAttributes?: readonly SearchField[]; sortableAttributes?: readonly SearchField[]; displayedAttributes?: readonly SearchField[]; metadata?: Record; }; /** * Options accepted when defining a search index. */ export type DefineSearchIndexOptions = Omit, "kind" | "name" | "primaryKey"> & { primaryKey?: SearchField; }; /** * Provider-neutral filter values. */ export type SearchFilterValue = SearchPrimitive | readonly Exclude[]; /** * Provider-neutral exact-match filters. */ export type SearchFilters = Record; /** * Provider-neutral sort expression. Use `field:asc` or `field:desc`. */ export type SearchSort = `${string}:asc` | `${string}:desc` | (string & {}); /** * Query accepted by search providers. */ export type SearchQuery = { query?: string; filters?: SearchFilters; sort?: readonly SearchSort[]; facets?: readonly string[]; limit?: number; offset?: number; }; /** * Page metadata returned from search providers. */ export type SearchResultPage = { kind: "offset"; limit: number; offset: number; total?: number; hasMore: boolean; }; /** * Search result payload. */ export type SearchResults = { hits: TDocument[]; query: string; page: SearchResultPage; processingTimeMs?: number; facets?: Record>; }; /** * Result returned after indexing documents. */ export type SearchIndexResult = { indexed: number; taskId?: string | number; }; /** * Result returned after deleting indexed documents. */ export type SearchDeleteResult = { deleted: number; taskId?: string | number; }; /** * App-facing search port. */ export type SearchPort = { configureIndex(index: SearchIndexDef): Promise; indexDocuments(index: SearchIndexDef, documents: TDocument | readonly TDocument[]): Promise; deleteDocuments(index: SearchIndexDef, ids: string | readonly string[]): Promise; clearIndex(index: SearchIndexDef): Promise; search(index: SearchIndexDef, query: SearchQuery): Promise>; }; /** * Captured memory index state exposed for tests. */ export type MemorySearchIndexState = { definition?: SearchIndexDef; documents: Map; }; /** * In-memory search port exposed for assertions in tests. */ export type MemorySearchPort = SearchPort & { indexes: Map; reset(index?: SearchIndexDef): void; }; /** * Options for the in-memory search adapter. */ export type CreateMemorySearchOptions = { now?: () => Date; }; /** * Options for the in-memory search provider. */ export type MemorySearchProviderOptions = CreateMemorySearchOptions & { name?: string; }; /** * Ports contributed by the memory search provider. */ export interface MemorySearchProviderPorts { search: SearchPort; } /** * Error thrown when search inputs are invalid. */ export declare class SearchOptionsError extends Error { constructor(message: string); } /** * Define a typed search index. */ export declare function defineSearchIndex(name: string, options?: DefineSearchIndexOptions): SearchIndexDef; /** * Index documents through any `SearchPort`. */ export declare function indexSearchDocuments(search: SearchPort, index: SearchIndexDef, documents: TDocument | readonly TDocument[]): Promise; /** * Query documents through any `SearchPort`. */ export declare function searchDocuments(search: SearchPort, index: SearchIndexDef, query: SearchQuery): Promise>; /** * Create an in-memory search port for tests and single-process development. */ export declare function createMemorySearch(_options?: CreateMemorySearchOptions): MemorySearchPort; /** * Create a provider that contributes an in-memory search port. */ export declare function createMemorySearchProvider(options?: MemorySearchProviderOptions): import("../providers/provider.js").ServiceProvider, { search: SearchPort; }, unknown, void>; export {}; //# sourceMappingURL=index.d.ts.map