UNPKG

cozy-dataproxy-lib

Version:

Library meant to be by Cozy Cloud's DataProxy apps for data manipulation

62 lines (61 loc) 3.08 kB
import FlexSearch from 'flexsearch'; import CozyClient from 'cozy-client'; import type { PerformanceAPI } from 'cozy-client/types/performances/types'; import CozyRealtime from 'cozy-realtime'; import { SearchedDoctype } from './consts'; import { CozyDoc, RawSearchResult, SearchIndex, SearchIndexes, SearchResult, SearchOptions, StorageInterface, EnrichedSearchResult } from './types'; interface FlexSearchResultWithDoctype extends FlexSearch.SimpleDocumentSearchResultSetUnit { doctype: SearchedDoctype; } interface EngineOptions { shouldInit?: boolean; } export declare class SearchEngine { client: CozyClient; searchIndexes: SearchIndexes; debouncedReplication: () => void; isLocalSearch: boolean; storage: StorageInterface; performanceApi: PerformanceAPI; engineOptions: EngineOptions; sharedDrivesRealtimes: Record<string, CozyRealtime>; constructor(client: CozyClient, storage: StorageInterface, performanceApi?: PerformanceAPI, engineOptions?: EngineOptions); afterLogin(): void; indexDocumentsAtInit(): Promise<void>; handleReplicationEvents(): void; init(): Promise<void>; addSharedDrive(driveId: string): void; private indexSharedDriveDocs; removeSharedDrive(driveId: string): void; private addSharedDriveRealtime; stopSharedDrivesRealtimes(): void; subscribeDoctype(client: CozyClient, doctype: string, realtime?: CozyRealtime, sharedDriveId?: string): void; handleUpdatedOrCreatedDoc(doc: CozyDoc, sharedDriveId?: string): void; handleDeletedDoc(doc: CozyDoc, sharedDriveId?: string): void; /** * Initialize indexes by: * - importing persisted indexes * - Requesting remote changes if the indexes are stale * - Query the local database to load the redux store */ initSearchWithIndexImport(): Promise<void>; buildSearchIndex(doctype: string, docs: CozyDoc[]): FlexSearch.Document<CozyDoc, false>; getLocalLastSeq(doctype: string): Promise<number>; initialIndexation(doctype: string): Promise<SearchIndex | null>; incrementalIndexation(doctype: string, searchIndex: SearchIndex): Promise<SearchIndex>; indexDocsForSearch(doctype: string): Promise<SearchIndex | null>; search(query: string, options: SearchOptions | undefined): Promise<SearchResult[] | null>; searchOnIndexes(query: string, searchOnDoctypes: string[]): FlexSearchResultWithDoctype[]; deduplicateAndFlatten(searchResults: FlexSearchResultWithDoctype[]): RawSearchResult[]; compareStrings(str1: string, str2: string): number; sortSearchResults(searchResults: EnrichedSearchResult[], doctypesOrder: string[] | undefined): EnrichedSearchResult[]; sortFiles(aRes: EnrichedSearchResult, bRes: EnrichedSearchResult): number; limitSearchResults(searchResults: EnrichedSearchResult[]): EnrichedSearchResult[]; getSharedDrivesDoctypes(): string[]; /** * Clean up search indexes for doctypes that no longer exist * @param currentDoctypes - List of currently valid doctypes */ private cleanIndexes; } export {};