Prometheus Entity Management API
    Preparing search index...

    view/incremental.ts — G3 parity: incremental view maintenance.

    The baseline applyView re-filters + re-sorts the entire id list on every change — O(n) per update. For large lists this is the gap vs TanStack DB's differential-dataflow live queries.

    This maintains a derived, sorted result and updates it for a SINGLE entity change in O(log n): binary-search the entity's current position, decide membership via the filter, and insert / remove / reposition. No full re-derivation. Result is byte-identical to applyView for the same inputs (correctness parity is asserted in tests).

    Design choice: a hand-rolled dirty-tracking index rather than adopting d2ts (0.1.x, pre-production) — same acceptance bar (sub-linear single-row update), far lower dependency risk. The differential engine can replace the internals later behind this same class without an API change.

    interface IncrementalViewOptions {
        filter?: FilterSpec | null;
        getEntity: (id: string) => Record<string, unknown> | null;
        search?: { fields: string[]; query: string } | null;
        sort?: SortSpec | null;
    }
    Index
    filter?: FilterSpec | null
    getEntity: (id: string) => Record<string, unknown> | null

    Resolve an entity by id from the graph (or null if absent).

    search?: { fields: string[]; query: string } | null
    sort?: SortSpec | null