import { BaseSearch , ProcessedSearchEntry , SearcherFactory } from "./BaseSearch" ; import { EntryURLType , getEntryURLs } from "../tools/entry" ; import { fieldsToProperties } from "../facades/entry" ; import StorageInterface from "../storage/StorageInterface" ; import { EntryFacade , VaultFacade } from "../types" ; async function extractEntries ( facade , memory ) { const scoresRaw = await memory . getValue ( `bcup_search_${ facade . id }` ) ; let vaultScore = { } ; if ( scoresRaw ) { try { const scores = JSON . parse ( scoresRaw ) ; vaultScore = scores ; } catch ( err ) { } } return facade . entries . reduce ( ( entries , nextEntry ) => { const properties = fieldsToProperties ( nextEntry . fields ) ; const urls = getEntryURLs ( properties , EntryURLType . General ) ; entries . push ( { id : nextEntry . id , properties , entryType : nextEntry . type , urls , groupID : nextEntry . parentID , vaultID : facade . id , domainScores : vaultScore [ nextEntry . id ] || { } } ) ; return entries ; } , [ ] ) ; } export class VaultFacadeEntrySearch extends BaseSearch { constructor ( facades , memory ? , searcherFactory ? ) { super ( facades , extractEntries , memory , searcherFactory ) ; } }