You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement a high-performance client-side invoice filter engine that compiles filter criteria into a reusable query object, supports nested AND/OR logic, and caches per-field indexes to avoid re-scanning large invoice arrays on repeated queries.
compileFilter validates criteria (throws if both and and or present at same level) and returns a CompiledFilter with a pre-built predicate function
FilterIndex class in same file: buildIndex(invoices: Invoice[]): FilterIndex builds Map-based indexes for status, creator, token; queryIndex(filter: CompiledFilter): Invoice[] uses indexes for equality checks then applies remaining predicates
Index is invalidated when the underlying invoice array reference changes
All exported from src/index.ts
Tests in test/invoiceFilter.test.ts: nested AND/OR logic, index reuse across multiple queries, invalid criteria throws, empty array returns empty, bigint funded range filtering
Context
Invoice and InvoiceStatus types are in src/types.ts
bigint comparison requires care — use explicit > / < not Math functions
Index must handle invoices with multiple recipients (recipient filter matches if ANY recipient matches)
Description
Implement a high-performance client-side invoice filter engine that compiles filter criteria into a reusable query object, supports nested AND/OR logic, and caches per-field indexes to avoid re-scanning large invoice arrays on repeated queries.
Acceptance Criteria
src/invoiceFilter.tsexportingcompileFilter(criteria: FilterCriteria): CompiledFilterandapplyFilter(invoices: Invoice[], filter: CompiledFilter): Invoice[]FilterCriteriasupports:{ and?: FilterCriteria[], or?: FilterCriteria[], status?: InvoiceStatus, creator?: string, recipient?: string, token?: string, minFunded?: bigint, maxFunded?: bigint, deadlineBefore?: number, deadlineAfter?: number }compileFiltervalidates criteria (throws if bothandandorpresent at same level) and returns aCompiledFilterwith a pre-built predicate functionFilterIndexclass in same file:buildIndex(invoices: Invoice[]): FilterIndexbuilds Map-based indexes forstatus,creator,token;queryIndex(filter: CompiledFilter): Invoice[]uses indexes for equality checks then applies remaining predicatessrc/index.tstest/invoiceFilter.test.ts: nested AND/OR logic, index reuse across multiple queries, invalid criteria throws, empty array returns empty, bigint funded range filteringContext
InvoiceandInvoiceStatustypes are insrc/types.tsbigintcomparison requires care — use explicit>/<notMathfunctions