UNPKG

@accounter/server

Version:
50 lines (49 loc) 2.09 kB
/** * Queue Match Evaluator Provider * * Lazily evaluates match suggestions for a batch of unmatched charges, powering * the charge matching review screen queue. Purely read-only and analytical — * no DB mutations happen here. */ import DataLoader from 'dataloader'; import type { ChargeMatchProto } from '../types.js'; import { ChargesMatcherProvider } from './charges-matcher.provider.js'; /** * A base charge paired with its match suggestions, ordered by confidence score * (highest first) */ export interface ChargeWithSuggestionsProto<TCharge = { id: string; }> { id: string; baseCharge: TCharge; suggestions: ChargeMatchProto[]; } export declare class QueueMatchEvaluatorProvider { private chargesMatcherProvider; constructor(chargesMatcherProvider: ChargesMatcherProvider); /** * Calculate match suggestions for a batch of unmatched charges on the fly. * * Delegates to `ChargesMatcherProvider.findMatchesForCharges`, which builds the * candidate pool once for the whole batch (instead of once per charge). A charge * whose evaluation fails (e.g. it turns out to be already matched) is returned * with empty suggestions rather than failing the whole batch. * * @param baseCharges - Unmatched charges to evaluate, in queue order * @returns One entry per input charge, preserving input order */ evaluateMatchesForCharges<TCharge extends { id: string; }>(baseCharges: TCharge[]): Promise<ChargeWithSuggestionsProto<TCharge>[]>; /** * DataLoader for lazily resolving a single charge's match suggestions. * * Backs the `ChargeWithSuggestions.suggestions` field resolver so the queue can * return base charges immediately and stream suggestions in via `@defer`. All * suggestions requested within the operation are coalesced into a single * `findMatchesForCharges` call, so the shared candidate pool is still built once. */ suggestionsByChargeIdLoader: DataLoader<string, ChargeMatchProto[], string>; private batchLoadSuggestions; }